Skip to content

Commit 8521d4a

Browse files
committed
Fix a port issue
1 parent 01a3904 commit 8521d4a

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

src/crypto/crypto_openssl.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,42 +1219,42 @@ int omac1_aes_vector(const u8 *key, size_t key_len, size_t num_elem,
12191219
const u8 *addr[], const size_t *len, u8 *mac)
12201220
{
12211221
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
1222-
+ EVP_MAC_CTX *ctx = NULL;
1223-
+ EVP_MAC *emac;
1224-
+ int ret = -1;
1225-
+ size_t outlen, i;
1226-
+ OSSL_PARAM params[2];
1227-
+ char *cipher = NULL;
1228-
+ if (TEST_FAIL())
1229-
+ return -1;
1230-
+ emac = EVP_MAC_fetch(NULL, "CMAC", NULL);
1231-
+
1232-
+ if (key_len == 32)
1233-
+ cipher = "aes-256-cbc";
1234-
+ else if (key_len == 24)
1235-
+ cipher = "aes-192-cbc";
1236-
+ else if (key_len == 16)
1237-
+ cipher = "aes-128-cbc";
1238-
+
1239-
+ params[0] = OSSL_PARAM_construct_utf8_string("cipher", cipher, 0);
1240-
+ params[1] = OSSL_PARAM_construct_end();
1241-
+
1242-
+ if (!emac || !cipher ||
1243-
+ !(ctx = EVP_MAC_CTX_new(emac)) ||
1244-
+ EVP_MAC_init(ctx, key, key_len, params) != 1)
1245-
+ goto fail;
1246-
+
1247-
+ for (i = 0; i < num_elem; i++) {
1248-
+ if (!EVP_MAC_update(ctx, addr[i], len[i]))
1249-
+ goto fail;
1250-
+ }
1251-
+ if (EVP_MAC_final(ctx, mac, &outlen, 16) != 1 || outlen != 16)
1252-
+ goto fail;
1253-
+ ret = 0;
1254-
+fail:
1255-
+ EVP_MAC_CTX_free(ctx);
1256-
+ return ret;
1257-
+#else /* OpenSSL version >= 3.0 */
1222+
EVP_MAC_CTX *ctx = NULL;
1223+
EVP_MAC *emac;
1224+
int ret = -1;
1225+
size_t outlen, i;
1226+
OSSL_PARAM params[2];
1227+
char *cipher = NULL;
1228+
if (TEST_FAIL())
1229+
return -1;
1230+
emac = EVP_MAC_fetch(NULL, "CMAC", NULL);
1231+
1232+
if (key_len == 32)
1233+
cipher = "aes-256-cbc";
1234+
else if (key_len == 24)
1235+
cipher = "aes-192-cbc";
1236+
else if (key_len == 16)
1237+
cipher = "aes-128-cbc";
1238+
1239+
params[0] = OSSL_PARAM_construct_utf8_string("cipher", cipher, 0);
1240+
params[1] = OSSL_PARAM_construct_end();
1241+
1242+
if (!emac || !cipher ||
1243+
!(ctx = EVP_MAC_CTX_new(emac)) ||
1244+
EVP_MAC_init(ctx, key, key_len, params) != 1)
1245+
goto fail;
1246+
1247+
for (i = 0; i < num_elem; i++) {
1248+
if (!EVP_MAC_update(ctx, addr[i], len[i]))
1249+
goto fail;
1250+
}
1251+
if (EVP_MAC_final(ctx, mac, &outlen, 16) != 1 || outlen != 16)
1252+
goto fail;
1253+
ret = 0;
1254+
fail:
1255+
EVP_MAC_CTX_free(ctx);
1256+
return ret;
1257+
#else /* OpenSSL version >= 3.0 */
12581258
CMAC_CTX *ctx;
12591259
int ret = -1;
12601260
size_t outlen, i;

0 commit comments

Comments
 (0)