diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2021-03-09 11:53:33 +1000 |
---|---|---|
committer | Shane Lontis <shane.lontis@oracle.com> | 2021-03-18 17:52:37 +1000 |
commit | 8a6e9125200223fa2294d3634d3dfec24857264b (patch) | |
tree | 456f123f76f8d213acc195450d4a8502cd2fda23 | |
parent | 7bbadfc15a446134d15d8fd0aa5362628b8c96be (diff) |
Add ossl_ symbols for sm3 and sm4
Partial fix for #12964
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14473)
-rw-r--r-- | crypto/evp/e_sm4.c | 16 | ||||
-rw-r--r-- | crypto/sm3/legacy_sm3.c | 2 | ||||
-rw-r--r-- | crypto/sm3/sm3.c | 5 | ||||
-rw-r--r-- | crypto/sm3/sm3_local.h | 12 | ||||
-rw-r--r-- | crypto/sm4/sm4.c | 6 | ||||
-rw-r--r-- | include/crypto/sm4.h | 6 | ||||
-rw-r--r-- | include/internal/sm3.h | 6 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_sm4_hw.c | 6 | ||||
-rw-r--r-- | providers/implementations/digests/sm3_prov.c | 2 | ||||
-rw-r--r-- | test/sm4_internal_test.c | 8 |
10 files changed, 34 insertions, 35 deletions
diff --git a/crypto/evp/e_sm4.c b/crypto/evp/e_sm4.c index 5a164eff75..4e6c1cdceb 100644 --- a/crypto/evp/e_sm4.c +++ b/crypto/evp/e_sm4.c @@ -24,7 +24,7 @@ typedef struct { static int sm4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { - SM4_set_key(key, EVP_CIPHER_CTX_get_cipher_data(ctx)); + ossl_sm4_set_key(key, EVP_CIPHER_CTX_get_cipher_data(ctx)); return 1; } @@ -34,10 +34,10 @@ static void sm4_cbc_encrypt(const unsigned char *in, unsigned char *out, { if (enc) CRYPTO_cbc128_encrypt(in, out, len, key, ivec, - (block128_f)SM4_encrypt); + (block128_f)ossl_sm4_encrypt); else CRYPTO_cbc128_decrypt(in, out, len, key, ivec, - (block128_f)SM4_decrypt); + (block128_f)ossl_sm4_decrypt); } static void sm4_cfb128_encrypt(const unsigned char *in, unsigned char *out, @@ -45,16 +45,16 @@ static void sm4_cfb128_encrypt(const unsigned char *in, unsigned char *out, unsigned char *ivec, int *num, const int enc) { CRYPTO_cfb128_encrypt(in, out, length, key, ivec, num, enc, - (block128_f)SM4_encrypt); + (block128_f)ossl_sm4_encrypt); } static void sm4_ecb_encrypt(const unsigned char *in, unsigned char *out, const SM4_KEY *key, const int enc) { if (enc) - SM4_encrypt(in, out, key); + ossl_sm4_encrypt(in, out, key); else - SM4_decrypt(in, out, key); + ossl_sm4_decrypt(in, out, key); } static void sm4_ofb128_encrypt(const unsigned char *in, unsigned char *out, @@ -62,7 +62,7 @@ static void sm4_ofb128_encrypt(const unsigned char *in, unsigned char *out, unsigned char *ivec, int *num) { CRYPTO_ofb128_encrypt(in, out, length, key, ivec, num, - (block128_f)SM4_encrypt); + (block128_f)ossl_sm4_encrypt); } IMPLEMENT_BLOCK_CIPHER(sm4, ks, sm4, EVP_SM4_KEY, NID_sm4, @@ -77,7 +77,7 @@ static int sm4_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, CRYPTO_ctr128_encrypt(in, out, len, &dat->ks, ctx->iv, EVP_CIPHER_CTX_buf_noconst(ctx), &num, - (block128_f)SM4_encrypt); + (block128_f)ossl_sm4_encrypt); EVP_CIPHER_CTX_set_num(ctx, num); return 1; } diff --git a/crypto/sm3/legacy_sm3.c b/crypto/sm3/legacy_sm3.c index da07aed12a..e91e59d504 100644 --- a/crypto/sm3/legacy_sm3.c +++ b/crypto/sm3/legacy_sm3.c @@ -13,7 +13,7 @@ #include "../evp/legacy_meth.h" #include "internal/sm3.h" -IMPLEMENT_LEGACY_EVP_MD_METH_LC(sm3_int, sm3) +IMPLEMENT_LEGACY_EVP_MD_METH_LC(sm3_int, ossl_sm3) static const EVP_MD sm3_md = { NID_sm3, diff --git a/crypto/sm3/sm3.c b/crypto/sm3/sm3.c index ef03150cab..37a494b69b 100644 --- a/crypto/sm3/sm3.c +++ b/crypto/sm3/sm3.c @@ -12,7 +12,7 @@ #include <openssl/e_os2.h> #include "sm3_local.h" -int sm3_init(SM3_CTX *c) +int ossl_sm3_init(SM3_CTX *c) { memset(c, 0, sizeof(*c)); c->A = SM3_A; @@ -26,7 +26,7 @@ int sm3_init(SM3_CTX *c) return 1; } -void sm3_block_data_order(SM3_CTX *ctx, const void *p, size_t num) +void ossl_sm3_block_data_order(SM3_CTX *ctx, const void *p, size_t num) { const unsigned char *data = p; register unsigned MD32_REG_T A, B, C, D, E, F, G, H; @@ -193,4 +193,3 @@ void sm3_block_data_order(SM3_CTX *ctx, const void *p, size_t num) ctx->H ^= H; } } - diff --git a/crypto/sm3/sm3_local.h b/crypto/sm3/sm3_local.h index 07def19cf1..3325eac745 100644 --- a/crypto/sm3/sm3_local.h +++ b/crypto/sm3/sm3_local.h @@ -17,9 +17,9 @@ #define HASH_LONG SM3_WORD #define HASH_CTX SM3_CTX #define HASH_CBLOCK SM3_CBLOCK -#define HASH_UPDATE sm3_update -#define HASH_TRANSFORM sm3_transform -#define HASH_FINAL sm3_final +#define HASH_UPDATE ossl_sm3_update +#define HASH_TRANSFORM ossl_sm3_transform +#define HASH_FINAL ossl_sm3_final #define HASH_MAKE_STRING(c, s) \ do { \ unsigned long ll; \ @@ -32,10 +32,10 @@ ll=(c)->G; (void)HOST_l2c(ll, (s)); \ ll=(c)->H; (void)HOST_l2c(ll, (s)); \ } while (0) -#define HASH_BLOCK_DATA_ORDER sm3_block_data_order +#define HASH_BLOCK_DATA_ORDER ossl_sm3_block_data_order -void sm3_block_data_order(SM3_CTX *c, const void *p, size_t num); -void sm3_transform(SM3_CTX *c, const unsigned char *data); +void ossl_sm3_block_data_order(SM3_CTX *c, const void *p, size_t num); +void ossl_sm3_transform(SM3_CTX *c, const unsigned char *data); #include "crypto/md32_common.h" diff --git a/crypto/sm4/sm4.c b/crypto/sm4/sm4.c index a62993c272..5e525d96e5 100644 --- a/crypto/sm4/sm4.c +++ b/crypto/sm4/sm4.c @@ -129,7 +129,7 @@ static ossl_inline uint32_t SM4_T(uint32_t X) rotl(SM4_SBOX_T[(uint8_t)X], 8); } -int SM4_set_key(const uint8_t *key, SM4_KEY *ks) +int ossl_sm4_set_key(const uint8_t *key, SM4_KEY *ks) { /* * Family Key @@ -184,7 +184,7 @@ int SM4_set_key(const uint8_t *key, SM4_KEY *ks) B3 ^= F(B0 ^ B1 ^ B2 ^ ks->rk[k3]); \ } while(0) -void SM4_encrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks) +void ossl_sm4_encrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks) { uint32_t B0 = load_u32_be(in, 0); uint32_t B1 = load_u32_be(in, 1); @@ -210,7 +210,7 @@ void SM4_encrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks) store_u32_be(B0, out + 12); } -void SM4_decrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks) +void ossl_sm4_decrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks) { uint32_t B0 = load_u32_be(in, 0); uint32_t B1 = load_u32_be(in, 1); diff --git a/include/crypto/sm4.h b/include/crypto/sm4.h index 8195ab165c..e21ec81ca6 100644 --- a/include/crypto/sm4.h +++ b/include/crypto/sm4.h @@ -29,10 +29,10 @@ typedef struct SM4_KEY_st { uint32_t rk[SM4_KEY_SCHEDULE]; } SM4_KEY; -int SM4_set_key(const uint8_t *key, SM4_KEY *ks); +int ossl_sm4_set_key(const uint8_t *key, SM4_KEY *ks); -void SM4_encrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks); +void ossl_sm4_encrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks); -void SM4_decrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks); +void ossl_sm4_decrypt(const uint8_t *in, uint8_t *out, const SM4_KEY *ks); #endif diff --git a/include/internal/sm3.h b/include/internal/sm3.h index fe84f1905e..db1d61f052 100644 --- a/include/internal/sm3.h +++ b/include/internal/sm3.h @@ -32,8 +32,8 @@ typedef struct SM3state_st { unsigned int num; } SM3_CTX; -int sm3_init(SM3_CTX *c); -int sm3_update(SM3_CTX *c, const void *data, size_t len); -int sm3_final(unsigned char *md, SM3_CTX *c); +int ossl_sm3_init(SM3_CTX *c); +int ossl_sm3_update(SM3_CTX *c, const void *data, size_t len); +int ossl_sm3_final(unsigned char *md, SM3_CTX *c); #endif /* OSSL_INTERNAL_SM3_H */ diff --git a/providers/implementations/ciphers/cipher_sm4_hw.c b/providers/implementations/ciphers/cipher_sm4_hw.c index 5cfa81d46f..e370574384 100644 --- a/providers/implementations/ciphers/cipher_sm4_hw.c +++ b/providers/implementations/ciphers/cipher_sm4_hw.c @@ -15,14 +15,14 @@ static int cipher_hw_sm4_initkey(PROV_CIPHER_CTX *ctx, PROV_SM4_CTX *sctx = (PROV_SM4_CTX *)ctx; SM4_KEY *ks = &sctx->ks.ks; - SM4_set_key(key, ks); + ossl_sm4_set_key(key, ks); ctx->ks = ks; if (ctx->enc || (ctx->mode != EVP_CIPH_ECB_MODE && ctx->mode != EVP_CIPH_CBC_MODE)) - ctx->block = (block128_f)SM4_encrypt; + ctx->block = (block128_f)ossl_sm4_encrypt; else - ctx->block = (block128_f)SM4_decrypt; + ctx->block = (block128_f)ossl_sm4_decrypt; return 1; } diff --git a/providers/implementations/digests/sm3_prov.c b/providers/implementations/digests/sm3_prov.c index fec3dcbef3..0de38f2e15 100644 --- a/providers/implementations/digests/sm3_prov.c +++ b/providers/implementations/digests/sm3_prov.c @@ -15,4 +15,4 @@ /* ossl_sm3_functions */ IMPLEMENT_digest_functions(sm3, SM3_CTX, SM3_CBLOCK, SM3_DIGEST_LENGTH, 0, - sm3_init, sm3_update, sm3_final) + ossl_sm3_init, ossl_sm3_update, ossl_sm3_final) diff --git a/test/sm4_internal_test.c b/test/sm4_internal_test.c index 0a5ea738e5..6e18b19090 100644 --- a/test/sm4_internal_test.c +++ b/test/sm4_internal_test.c @@ -54,21 +54,21 @@ static int test_sm4_ecb(void) SM4_KEY key; uint8_t block[SM4_BLOCK_SIZE]; - SM4_set_key(k, &key); + ossl_sm4_set_key(k, &key); memcpy(block, input, SM4_BLOCK_SIZE); - SM4_encrypt(block, block, &key); + ossl_sm4_encrypt(block, block, &key); if (!TEST_mem_eq(block, SM4_BLOCK_SIZE, expected, SM4_BLOCK_SIZE)) return 0; for (i = 0; i != 999999; ++i) - SM4_encrypt(block, block, &key); + ossl_sm4_encrypt(block, block, &key); if (!TEST_mem_eq(block, SM4_BLOCK_SIZE, expected_iter, SM4_BLOCK_SIZE)) return 0; for (i = 0; i != 1000000; ++i) - SM4_decrypt(block, block, &key); + ossl_sm4_decrypt(block, block, &key); if (!TEST_mem_eq(block, SM4_BLOCK_SIZE, input, SM4_BLOCK_SIZE)) return 0; |