Codebase list openssl / fc196a5
Make OBJ_NAME case insensitive. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/7089) Pauli 5 years ago
5 changed file(s) with 109 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
0 /*
1 * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the OpenSSL license (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 #ifndef INTERNAL_LHASH_H
10 # define INTERNAL_LHASH_H
11
12 unsigned long openssl_lh_strcasehash(const char *);
13
14 #endif
1212 #include <openssl/crypto.h>
1313 #include <openssl/lhash.h>
1414 #include <openssl/err.h>
15 #include "internal/ctype.h"
16 #include "internal/lhash.h"
1517 #include "lhash_lcl.h"
1618
1719 /*
348350 return (ret >> 16) ^ ret;
349351 }
350352
353 unsigned long openssl_lh_strcasehash(const char *c)
354 {
355 unsigned long ret = 0;
356 long n;
357 unsigned long v;
358 int r;
359
360 if (c == NULL || *c == '\0')
361 return ret;
362
363 for (n = 0x100; *c != '\0'; n += 0x100) {
364 v = n | ossl_tolower(*c);
365 r = (int)((v >> 2) ^ v) & 0x0f;
366 ret = (ret << r) | (ret >> (32 - r));
367 ret &= 0xFFFFFFFFL;
368 ret ^= v * v;
369 c++;
370 }
371 return (ret >> 16) ^ ret;
372 }
373
351374 unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh)
352375 {
353376 return lh ? lh->num_items : 0;
1616 #include <openssl/safestack.h>
1717 #include <openssl/e_os2.h>
1818 #include "internal/thread_once.h"
19 #include "internal/lhash.h"
1920 #include "obj_lcl.h"
21 #include "e_os.h"
2022
2123 /*
2224 * We define this wrapper for two reasons. Firstly, later versions of
2325 * DEC C add linkage information to certain functions, which makes it
2426 * tricky to use them as values to regular function pointers.
25 * Secondly, in the EDK2 build environment, the strcmp function is
26 * actually an external function (AsciiStrCmp) with the Microsoft ABI,
27 * so we can't transparently assign function pointers to it.
28 * Arguably the latter is a stupidity of the UEFI environment, but
29 * since the wrapper solves the DEC C issue too, let's just use the
30 * same solution.
27 * Secondly, in the EDK2 build environment, the strcasecmp function is
28 * actually an external function with the Microsoft ABI, so we can't
29 * transparently assign function pointers to it.
3130 */
3231 #if defined(OPENSSL_SYS_VMS_DECC) || defined(OPENSSL_SYS_UEFI)
33 static int obj_strcmp(const char *a, const char *b)
34 {
35 return strcmp(a, b);
32 static int obj_strcasecmp(const char *a, const char *b)
33 {
34 return strcasecmp(a, b);
3635 }
3736 #else
38 #define obj_strcmp strcmp
37 #define obj_strcasecmp strcasecmp
3938 #endif
4039
4140 /*
110109 ret = 0;
111110 goto out;
112111 }
113 name_funcs->hash_func = OPENSSL_LH_strhash;
114 name_funcs->cmp_func = obj_strcmp;
112 name_funcs->hash_func = openssl_lh_strcasehash;
113 name_funcs->cmp_func = obj_strcasecmp;
115114 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
116115
117116 push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
148147 ret = sk_NAME_FUNCS_value(name_funcs_stack,
149148 a->type)->cmp_func(a->name, b->name);
150149 } else
151 ret = strcmp(a->name, b->name);
150 ret = strcasecmp(a->name, b->name);
152151 }
153152 return ret;
154153 }
163162 sk_NAME_FUNCS_value(name_funcs_stack,
164163 a->type)->hash_func(a->name);
165164 } else {
166 ret = OPENSSL_LH_strhash(a->name);
165 ret = openssl_lh_strcasehash(a->name);
167166 }
168167 ret ^= a->type;
169168 return ret;
213212 if (!OBJ_NAME_init())
214213 return 0;
215214
216 CRYPTO_THREAD_write_lock(obj_lock);
217
218215 alias = type & OBJ_NAME_ALIAS;
219216 type &= ~OBJ_NAME_ALIAS;
220217
228225 onp->alias = alias;
229226 onp->type = type;
230227 onp->data = data;
228
229 CRYPTO_THREAD_write_lock(obj_lock);
231230
232231 ret = lh_OBJ_NAME_insert(names_lh, onp);
233232 if (ret != NULL) {
1414 setup("test_evp");
1515
1616 my @files = ( "evpciph.txt", "evpdigest.txt", "evpencod.txt", "evpkdf.txt",
17 "evpmac.txt", "evppbe.txt", "evppkey.txt", "evppkey_ecc.txt" );
17 "evpmac.txt", "evppbe.txt", "evppkey.txt", "evppkey_ecc.txt",
18 "evpcase.txt" );
1819
1920 plan tests => scalar(@files);
2021
0 #
1 # Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
2 #
3 # Licensed under the OpenSSL license (the "License"). You may not use
4 # this file except in compliance with the License. You can obtain a copy
5 # in the file LICENSE in the source distribution or at
6 # https://www.openssl.org/source/license.html
7
8 # Tests start with one of these keywords
9 # Cipher Decrypt Derive Digest Encoding KDF MAC PBE
10 # PrivPubKeyPair Sign Verify VerifyRecover
11 # and continue until a blank line. Lines starting with a pound sign,
12 # like this prolog, are ignored.
13
14 # These tests exercise the case insensitive handling of object names.
15 # They are contrived
16
17 Title = Case insensitive AES tests
18
19 Cipher = Aes-128-eCb
20 Key = 2B7E151628AED2A6ABF7158809CF4F3C
21 Plaintext = 6BC1BEE22E409F96E93D7E117393172A
22 Ciphertext = 3AD77BB40D7A3660A89ECAF32466EF97
23
24 Cipher = AeS-128-cbC
25 Key = 2B7E151628AED2A6ABF7158809CF4F3C
26 IV = 73BED6B8E3C1743B7116E69E22229516
27 Plaintext = F69F2445DF4F9B17AD2B417BE66C3710
28 Ciphertext = 3FF1CAA1681FAC09120ECA307586E1A7
29
30 Cipher = aES-128-CTR
31 Key = AE6852F8121067CC4BF7A5765577F39E
32 IV = 00000030000000000000000000000001
33 Operation = ENCRYPT
34 Plaintext = 53696E676C6520626C6F636B206D7367
35 Ciphertext = E4095D4FB7A7B3792D6175A3261311B8
36
37 Cipher = AES-128-GcM
38 Key = 00000000000000000000000000000000
39 IV = 000000000000000000000000
40 AAD =
41 Tag = ab6e47d42cec13bdf53a67b21257bddf
42 Plaintext = 00000000000000000000000000000000
43 Ciphertext = 0388dace60b6a392f328c2b971b2fe78
44
45 Title = Case insensitive digest tests
46
47 Digest = Sha3-256
48 Input = ""
49 Output = A7FFC6F8BF1ED76651C14756A061D662F580FF4DE43B49FA82D80A4B80F8434A
50
51 Digest = shA512
52 Input = "abc"
53 Output = ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f