diff --git a/include/gmssl/gcm.h b/include/gmssl/gcm.h deleted file mode 100644 index c2aae9f0..00000000 --- a/include/gmssl/gcm.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014-2024 The GmSSL Project. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * - * http://www.apache.org/licenses/LICENSE-2.0 - */ - -#ifndef GMSSL_GCM_H -#define GMSSL_GCM_H - - -#include -#include -#include -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif - -#define GCM_IV_MIN_SIZE 1 -#define GCM_IV_MAX_SIZE ((uint64_t)(1 << (64-3))) -#define GCM_IV_DEFAULT_BITS 96 -#define GCM_IV_DEFAULT_SIZE 12 - -#define GCM_MIN_AAD_SIZE 0 -#define GCM_MAX_AAD_SIZE ((uint64_t)(1 << (64-3))) - -#define GCM_MIN_PLAINTEXT_SIZE 0 -#define GCM_MAX_PLAINTEXT_SIZE ((((uint64_t)1 << 39) - 256) >> 3) - - -#define GCM_IS_LITTLE_ENDIAN 1 - - -int gcm_encrypt(const BLOCK_CIPHER_KEY *key, const uint8_t *iv, size_t ivlen, - const uint8_t *aad, size_t aadlen, const uint8_t *in, size_t inlen, - uint8_t *out, size_t taglen, uint8_t *tag); - -int gcm_decrypt(const BLOCK_CIPHER_KEY *key, const uint8_t *iv, size_t ivlen, - const uint8_t *aad, size_t aadlen, const uint8_t *in, size_t inlen, - const uint8_t *tag, size_t taglen, uint8_t *out); - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/aes_modes.c b/src/aes_modes.c index 89e5a6e9..7a521837 100644 --- a/src/aes_modes.c +++ b/src/aes_modes.c @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. + * Copyright 2014-2024 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. @@ -13,9 +13,9 @@ #include #include #include -#include -#include #include +#include +#include void aes_cbc_encrypt(const AES_KEY *key, const uint8_t iv[16], @@ -149,16 +149,8 @@ int aes_gcm_encrypt(const AES_KEY *key, const uint8_t *iv, size_t ivlen, aes_encrypt(key, Y, T); - while (left) { - uint8_t block[16]; - size_t len = left < 16 ? left : 16; - ctr_incr(Y); - aes_encrypt(key, Y, block); - gmssl_memxor(pout, pin, block, len); - pin += len; - pout += len; - left -= len; - } + ctr_incr(Y); + aes_ctr_encrypt(key, Y, in, inlen, out); ghash(H, aad, aadlen, out, inlen, H); gmssl_memxor(tag, T, H, taglen); @@ -194,15 +186,8 @@ int aes_gcm_decrypt(const AES_KEY *key, const uint8_t *iv, size_t ivlen, return -1; } - while (left) { - uint8_t block[16]; - size_t len = left < 16 ? left : 16; - ctr_incr(Y); - aes_encrypt(key, Y, block); - gmssl_memxor(pout, pin, block, len); - pin += len; - pout += len; - left -= len; - } + ctr_incr(Y); + aes_ctr_encrypt(key, Y, in, inlen, out); + return 1; } diff --git a/src/sm4_gcm.c b/src/sm4_gcm.c index a86d3e29..880d2dc4 100644 --- a/src/sm4_gcm.c +++ b/src/sm4_gcm.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include