components/mbedtls: modify hardware encryption feature

rename "flag" and "keybites" in aes file,
rename "xxx_starts" and add license in sha file.
This commit is contained in:
liuhan 2016-08-31 11:43:48 +08:00 committed by Wu Jian Gang
parent 2d80fada70
commit 1900c50d3b
7 changed files with 36 additions and 27 deletions

View File

@ -77,9 +77,9 @@ int esp_aes_setkey_enc( AES_CTX *ctx, const unsigned char *key,
break; break;
default : return( ERR_AES_INVALID_KEY_LENGTH ); default : return( ERR_AES_INVALID_KEY_LENGTH );
} }
if (ctx->enc.flag == false){ if (ctx->enc.keyflag == false){
ctx->enc.flag = true; ctx->enc.keyflag = true;
ctx->enc.keybites = keybits; ctx->enc.keybits = keybits;
memset(ctx->enc.key, 0, sizeof(ctx->enc.key)); memset(ctx->enc.key, 0, sizeof(ctx->enc.key));
memcpy(ctx->enc.key, key, keybyte); memcpy(ctx->enc.key, key, keybyte);
} else { } else {
@ -108,9 +108,9 @@ int esp_aes_setkey_dec( AES_CTX *ctx, const unsigned char *key,
break; break;
default : return( ERR_AES_INVALID_KEY_LENGTH ); default : return( ERR_AES_INVALID_KEY_LENGTH );
} }
if (ctx->dec.flag == false){ if (ctx->dec.keyflag == false){
ctx->dec.flag = true; ctx->dec.keyflag = true;
ctx->dec.keybites = keybits; ctx->dec.keybits = keybits;
memset(ctx->dec.key, 0, sizeof(ctx->dec.key)); memset(ctx->dec.key, 0, sizeof(ctx->dec.key));
memcpy(ctx->dec.key, key, keybyte); memcpy(ctx->dec.key, key, keybyte);
} else { } else {
@ -123,9 +123,9 @@ int esp_aes_setkey_dec( AES_CTX *ctx, const unsigned char *key,
static void esp_aes_process_enable(AES_CTX *ctx, int mode) static void esp_aes_process_enable(AES_CTX *ctx, int mode)
{ {
if( mode == AES_ENCRYPT ){ if( mode == AES_ENCRYPT ){
esp_aes_setkey_enc(ctx, ctx->enc.key, ctx->enc.keybites); esp_aes_setkey_enc(ctx, ctx->enc.key, ctx->enc.keybits);
}else{ }else{
esp_aes_setkey_dec(ctx, ctx->dec.key, ctx->dec.keybites); esp_aes_setkey_dec(ctx, ctx->dec.key, ctx->dec.keybits);
} }
return; return;
} }

View File

@ -40,8 +40,8 @@ extern "C" {
#define ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */ #define ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
typedef struct{ typedef struct{
bool flag; bool keyflag;
uint16_t keybites; uint16_t keybits;
uint8_t key[32]; uint8_t key[32];
}key_context, KEY_CTX; }key_context, KEY_CTX;

View File

@ -1,8 +1,17 @@
/* // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
* copyright (c) 2010 - 2012 Espressif System //
* // Licensed under the Apache License, Version 2.0 (the "License");
* esf Link List Descriptor // you may not use this file except in compliance with the License.
*/ // You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _ESP_SHA_H_ #ifndef _ESP_SHA_H_
#define _ESP_SHA_H_ #define _ESP_SHA_H_
@ -53,7 +62,7 @@ void esp_sha1_process(SHA1_CTX *ctx, const unsigned char data[64]);
* *
* \param ctx context to be initialized * \param ctx context to be initialized
*/ */
void esp_sha1_starts( SHA1_CTX *ctx ); void esp_sha1_start( SHA1_CTX *ctx );
/** /**
* \brief SHA-1 process buffer * \brief SHA-1 process buffer
@ -120,7 +129,7 @@ void esp_sha256_clone( SHA256_CTX *dst, const SHA256_CTX *src );
* \param ctx context to be initialized * \param ctx context to be initialized
* \param is224 0 = use SHA256, 1 = use SHA224 * \param is224 0 = use SHA256, 1 = use SHA224
*/ */
void esp_sha256_starts( SHA256_CTX *ctx, int is224 ); void esp_sha256_start( SHA256_CTX *ctx, int is224 );
/** /**
* \brief SHA-256 process buffer * \brief SHA-256 process buffer
@ -187,7 +196,7 @@ void esp_sha512_clone( SHA512_CTX *dst, const SHA512_CTX *src );
* \param ctx context to be initialized * \param ctx context to be initialized
* \param is384 0 = use SHA512, 1 = use SHA384 * \param is384 0 = use SHA512, 1 = use SHA384
*/ */
void esp_sha512_starts( SHA512_CTX *ctx, int is384 ); void esp_sha512_start( SHA512_CTX *ctx, int is384 );
/** /**
* \brief SHA-512 process buffer * \brief SHA-512 process buffer

View File

@ -69,7 +69,7 @@ void esp_sha1_process(SHA1_CTX *ctx, const unsigned char data[64])
/* /*
* SHA-1 context setup * SHA-1 context setup
*/ */
void esp_sha1_starts( SHA1_CTX *ctx ) void esp_sha1_start( SHA1_CTX *ctx )
{ {
SHA_LOCK(); SHA_LOCK();
ets_sha_init(&ctx->context); ets_sha_init(&ctx->context);
@ -102,7 +102,7 @@ void esp_sha1_output( const unsigned char *input, size_t ilen, unsigned char out
SHA1_CTX ctx; SHA1_CTX ctx;
esp_sha1_init( &ctx ); esp_sha1_init( &ctx );
esp_sha1_starts( &ctx ); esp_sha1_start( &ctx );
esp_sha1_update( &ctx, input, ilen ); esp_sha1_update( &ctx, input, ilen );
esp_sha1_finish( &ctx, output ); esp_sha1_finish( &ctx, output );
esp_sha1_free( &ctx ); esp_sha1_free( &ctx );
@ -147,7 +147,7 @@ void esp_sha256_clone( SHA256_CTX *dst, const SHA256_CTX *src )
/* /*
* SHA-256 context setup * SHA-256 context setup
*/ */
void esp_sha256_starts( SHA256_CTX *ctx, int is224 ) void esp_sha256_start( SHA256_CTX *ctx, int is224 )
{ {
SHA_LOCK(); SHA_LOCK();
ets_sha_init(&ctx->context); ets_sha_init(&ctx->context);
@ -187,7 +187,7 @@ void esp_sha256_output( const unsigned char *input, size_t ilen, unsigned char o
SHA256_CTX ctx; SHA256_CTX ctx;
esp_sha256_init( &ctx ); esp_sha256_init( &ctx );
esp_sha256_starts( &ctx, is224 ); esp_sha256_start( &ctx, is224 );
esp_sha256_update( &ctx, input, ilen ); esp_sha256_update( &ctx, input, ilen );
esp_sha256_finish( &ctx, output ); esp_sha256_finish( &ctx, output );
esp_sha256_free( &ctx ); esp_sha256_free( &ctx );
@ -232,7 +232,7 @@ void esp_sha512_clone( SHA512_CTX *dst, const SHA512_CTX *src )
/* /*
* SHA-512 context setup * SHA-512 context setup
*/ */
void esp_sha512_starts( SHA512_CTX *ctx, int is384 ) void esp_sha512_start( SHA512_CTX *ctx, int is384 )
{ {
SHA_LOCK(); SHA_LOCK();
ets_sha_init(&ctx->context); ets_sha_init(&ctx->context);
@ -274,7 +274,7 @@ void esp_sha512_output( const unsigned char *input, size_t ilen,unsigned char ou
SHA512_CTX ctx; SHA512_CTX ctx;
esp_sha512_init( &ctx ); esp_sha512_init( &ctx );
esp_sha512_starts( &ctx, is384 ); esp_sha512_start( &ctx, is384 );
esp_sha512_update( &ctx, input, ilen ); esp_sha512_update( &ctx, input, ilen );
esp_sha512_finish( &ctx, output ); esp_sha512_finish( &ctx, output );
esp_sha512_free( &ctx ); esp_sha512_free( &ctx );

View File

@ -17,7 +17,7 @@ extern "C" {
typedef SHA1_CTX mbedtls_sha1_context; typedef SHA1_CTX mbedtls_sha1_context;
#define mbedtls_sha1_init esp_sha1_init #define mbedtls_sha1_init esp_sha1_init
#define mbedtls_sha1_starts esp_sha1_starts #define mbedtls_sha1_starts esp_sha1_start
#define mbedtls_sha1_clone esp_sha1_clone #define mbedtls_sha1_clone esp_sha1_clone
#define mbedtls_sha1_update esp_sha1_update #define mbedtls_sha1_update esp_sha1_update
#define mbedtls_sha1_finish esp_sha1_finish #define mbedtls_sha1_finish esp_sha1_finish

View File

@ -19,7 +19,7 @@ typedef SHA256_CTX mbedtls_sha256_context;
#define mbedtls_sha256_init esp_sha256_init #define mbedtls_sha256_init esp_sha256_init
#define mbedtls_sha256_clone esp_sha256_clone #define mbedtls_sha256_clone esp_sha256_clone
#define mbedtls_sha256_starts esp_sha256_starts #define mbedtls_sha256_starts esp_sha256_start
#define mbedtls_sha256_update esp_sha256_update #define mbedtls_sha256_update esp_sha256_update
#define mbedtls_sha256_finish esp_sha256_finish #define mbedtls_sha256_finish esp_sha256_finish
#define mbedtls_sha256_free esp_sha256_free #define mbedtls_sha256_free esp_sha256_free

View File

@ -19,7 +19,7 @@ typedef SHA512_CTX mbedtls_sha512_context;
#define mbedtls_sha512_init esp_sha512_init #define mbedtls_sha512_init esp_sha512_init
#define mbedtls_sha512_process esp_sha512_process #define mbedtls_sha512_process esp_sha512_process
#define mbedtls_sha512_clone esp_sha512_clone #define mbedtls_sha512_clone esp_sha512_clone
#define mbedtls_sha512_starts esp_sha512_starts #define mbedtls_sha512_starts esp_sha512_start
#define mbedtls_sha512_update esp_sha512_update #define mbedtls_sha512_update esp_sha512_update
#define mbedtls_sha512_finish esp_sha512_finish #define mbedtls_sha512_finish esp_sha512_finish
#define mbedtls_sha512_free esp_sha512_free #define mbedtls_sha512_free esp_sha512_free