• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #include "hitls_build.h"
17 #if defined(HITLS_CRYPTO_AES) && defined(HITLS_CRYPTO_ECB)
18 
19 #include "bsl_err_internal.h"
20 #include "crypt_aes.h"
21 #include "crypt_errno.h"
22 #include "crypt_modes_ecb.h"
23 #include "modes_local.h"
24 
AES_ECB_EncryptBlock(MODES_CipherCommonCtx * ctx,const uint8_t * in,uint8_t * out,uint32_t len)25 int32_t AES_ECB_EncryptBlock(MODES_CipherCommonCtx *ctx, const uint8_t *in, uint8_t *out, uint32_t len)
26 {
27     if (ctx->ciphCtx == NULL) {
28         BSL_ERR_PUSH_ERROR(CRYPT_NULL_INPUT);
29         return CRYPT_NULL_INPUT;
30     }
31     if ((len & 0x0f) != 0) {
32         BSL_ERR_PUSH_ERROR(CRYPT_MODE_ERR_INPUT_LEN);
33         return CRYPT_MODE_ERR_INPUT_LEN;
34     }
35     (void)CRYPT_AES_ECB_Encrypt(ctx->ciphCtx, in, out, len);
36     return CRYPT_SUCCESS;
37 }
38 
AES_ECB_DecryptBlock(MODES_CipherCommonCtx * ctx,const uint8_t * in,uint8_t * out,uint32_t len)39 int32_t AES_ECB_DecryptBlock(MODES_CipherCommonCtx *ctx, const uint8_t *in, uint8_t *out, uint32_t len)
40 {
41     if (ctx->ciphCtx == NULL) {
42         BSL_ERR_PUSH_ERROR(CRYPT_NULL_INPUT);
43         return CRYPT_NULL_INPUT;
44     }
45     if ((len & 0x0f) != 0) {
46         BSL_ERR_PUSH_ERROR(CRYPT_MODE_ERR_INPUT_LEN);
47         return CRYPT_MODE_ERR_INPUT_LEN;
48     }
49     (void)CRYPT_AES_ECB_Decrypt(ctx->ciphCtx, in, out, len);
50     return CRYPT_SUCCESS;
51 }
52 
AES_ECB_Update(MODES_CipherCtx * modeCtx,const uint8_t * in,uint32_t inLen,uint8_t * out,uint32_t * outLen)53 int32_t AES_ECB_Update(MODES_CipherCtx *modeCtx, const uint8_t *in, uint32_t inLen, uint8_t *out, uint32_t *outLen)
54 {
55     return MODES_CipherUpdate(modeCtx, modeCtx->enc ? AES_ECB_EncryptBlock : AES_ECB_DecryptBlock,
56         in, inLen, out, outLen);
57 }
58 
AES_ECB_Final(MODES_CipherCtx * modeCtx,uint8_t * out,uint32_t * outLen)59 int32_t AES_ECB_Final(MODES_CipherCtx *modeCtx, uint8_t *out, uint32_t *outLen)
60 {
61     return MODES_CipherFinal(modeCtx, modeCtx->enc ? AES_ECB_EncryptBlock : AES_ECB_DecryptBlock, out, outLen);
62 }
63 
64 #endif