hwcrypto: Match API completely to mbedTLS naming conventions

This commit is contained in:
Angus Gratton
2016-09-06 10:38:12 +10:00
committed by Wu Jian Gang
parent 2580c07ae6
commit 0a970e3a25
5 changed files with 135 additions and 134 deletions

View File

@@ -1,8 +1,6 @@
/**
* \file esp_aes.h
*
* \brief AES block cipher, ESP32 hardware accelerated version
* Based on mbedTLS version.
* Based on mbedTLS FIPS-197 compliant version.
*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* Additions Copyright (C) 2016, Espressif Systems (Shanghai) PTE Ltd
@@ -34,11 +32,11 @@ extern "C" {
#endif
/* padlock.c and aesni.c rely on these values! */
#define AES_ENCRYPT 1
#define AES_DECRYPT 0
#define ESP_AES_ENCRYPT 1
#define ESP_AES_DECRYPT 0
#define ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
#define ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
#define ERR_ESP_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
#define ERR_ESP_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
typedef struct {
enum AES_BITS aesbits;
@@ -58,7 +56,7 @@ typedef struct {
uint32_t *rk; /*!< AES round keys */
KEY_CTX enc;
KEY_CTX dec;
} aes_context, AES_CTX;
} esp_aes_context;
/**
* \brief Lock access to AES hardware unit
@@ -86,14 +84,14 @@ void esp_aes_release_hardware( void );
*
* \param ctx AES context to be initialized
*/
void esp_aes_init( AES_CTX *ctx );
void esp_aes_init( esp_aes_context *ctx );
/**
* \brief Clear AES context
*
* \param ctx AES context to be cleared
*/
void esp_aes_free( AES_CTX *ctx );
void esp_aes_free( esp_aes_context *ctx );
/**
* \brief AES key schedule (encryption)
@@ -104,7 +102,7 @@ void esp_aes_free( AES_CTX *ctx );
*
* \return 0 if successful, or ERR_AES_INVALID_KEY_LENGTH
*/
int esp_aes_setkey_enc( AES_CTX *ctx, const unsigned char *key, unsigned int keybits );
int esp_aes_setkey_enc( esp_aes_context *ctx, const unsigned char *key, unsigned int keybits );
/**
* \brief AES key schedule (decryption)
@@ -115,7 +113,7 @@ int esp_aes_setkey_enc( AES_CTX *ctx, const unsigned char *key, unsigned int key
*
* \return 0 if successful, or ERR_AES_INVALID_KEY_LENGTH
*/
int esp_aes_setkey_dec( AES_CTX *ctx, const unsigned char *key, unsigned int keybits );
int esp_aes_setkey_dec( esp_aes_context *ctx, const unsigned char *key, unsigned int keybits );
/**
* \brief AES-ECB block encryption/decryption
@@ -127,7 +125,7 @@ int esp_aes_setkey_dec( AES_CTX *ctx, const unsigned char *key, unsigned int key
*
* \return 0 if successful
*/
int esp_aes_crypt_ecb( AES_CTX *ctx, int mode, const unsigned char input[16], unsigned char output[16] );
int esp_aes_crypt_ecb( esp_aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16] );
/**
* \brief AES-CBC buffer encryption/decryption
@@ -151,7 +149,7 @@ int esp_aes_crypt_ecb( AES_CTX *ctx, int mode, const unsigned char input[16], un
*
* \return 0 if successful, or ERR_AES_INVALID_INPUT_LENGTH
*/
int esp_aes_crypt_cbc( AES_CTX *ctx,
int esp_aes_crypt_cbc( esp_aes_context *ctx,
int mode,
size_t length,
unsigned char iv[16],
@@ -184,7 +182,7 @@ int esp_aes_crypt_cbc( AES_CTX *ctx,
*
* \return 0 if successful
*/
int esp_aes_crypt_cfb128( AES_CTX *ctx,
int esp_aes_crypt_cfb128( esp_aes_context *ctx,
int mode,
size_t length,
size_t *iv_off,
@@ -216,7 +214,7 @@ int esp_aes_crypt_cfb128( AES_CTX *ctx,
*
* \return 0 if successful
*/
int esp_aes_crypt_cfb8( AES_CTX *ctx,
int esp_aes_crypt_cfb8( esp_aes_context *ctx,
int mode,
size_t length,
unsigned char iv[16],
@@ -245,7 +243,7 @@ int esp_aes_crypt_cfb8( AES_CTX *ctx,
*
* \return 0 if successful
*/
int esp_aes_crypt_ctr( AES_CTX *ctx,
int esp_aes_crypt_ctr( esp_aes_context *ctx,
size_t length,
size_t *nc_off,
unsigned char nonce_counter[16],
@@ -263,7 +261,7 @@ int esp_aes_crypt_ctr( AES_CTX *ctx,
* \param input Plaintext block
* \param output Output (ciphertext) block
*/
void esp_aes_encrypt( AES_CTX *ctx, const unsigned char input[16], unsigned char output[16] );
void esp_aes_encrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] );
/**
* \brief Internal AES block decryption function
@@ -274,7 +272,7 @@ void esp_aes_encrypt( AES_CTX *ctx, const unsigned char input[16], unsigned char
* \param input Ciphertext block
* \param output Output (plaintext) block
*/
void esp_aes_decrypt( AES_CTX *ctx, const unsigned char input[16], unsigned char output[16] );
void esp_aes_decrypt( esp_aes_context *ctx, const unsigned char input[16], unsigned char output[16] );
#ifdef __cplusplus
}

View File

@@ -1,16 +1,24 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// 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.
/*
* ESP32 hardware accelerated SHA1/256/512 implementation
* based on mbedTLS FIPS-197 compliant version.
*
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
* Additions Copyright (C) 2016, Espressif Systems (Shanghai) PTE Ltd
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); 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_
#define _ESP_SHA_H_
@@ -27,11 +35,10 @@ extern "C" {
* \brief SHA-1 context structure
*/
typedef struct {
/* both types defined in rom/sha.h */
SHA_CTX context;
enum SHA_TYPE context_type; /* defined in rom/sha.h */
} sha_context;
typedef sha_context SHA1_CTX;
enum SHA_TYPE context_type;
} esp_sha_context;
/**
* \brief Lock access to SHA hardware unit
@@ -59,14 +66,14 @@ void esp_sha_release_hardware( void );
*
* \param ctx SHA-1 context to be initialized
*/
void esp_sha1_init( SHA1_CTX *ctx );
void esp_sha1_init( esp_sha_context *ctx );
/**
* \brief Clear SHA-1 context
*
* \param ctx SHA-1 context to be cleared
*/
void esp_sha1_free( SHA1_CTX *ctx );
void esp_sha1_free( esp_sha_context *ctx );
/**
* \brief Clone (the state of) a SHA-1 context
@@ -74,14 +81,14 @@ void esp_sha1_free( SHA1_CTX *ctx );
* \param dst The destination context
* \param src The context to be cloned
*/
void esp_sha1_clone( SHA1_CTX *dst, const SHA1_CTX *src );
void esp_sha1_clone( esp_sha_context *dst, const esp_sha_context *src );
/**
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*/
void esp_sha1_start( SHA1_CTX *ctx );
void esp_sha1_start( esp_sha_context *ctx );
/**
* \brief SHA-1 process buffer
@@ -90,7 +97,7 @@ void esp_sha1_start( SHA1_CTX *ctx );
* \param input buffer holding the data
* \param ilen length of the input data
*/
void esp_sha1_update( SHA1_CTX *ctx, const unsigned char *input, size_t ilen );
void esp_sha1_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief SHA-1 final digest
@@ -98,36 +105,34 @@ void esp_sha1_update( SHA1_CTX *ctx, const unsigned char *input, size_t ilen );
* \param ctx SHA-1 context
* \param output SHA-1 checksum result
*/
void esp_sha1_finish( SHA1_CTX *ctx, unsigned char output[20] );
void esp_sha1_finish( esp_sha_context *ctx, unsigned char output[20] );
/**
* \brief Output = SHA-1( input buffer )
* \brief Calculate SHA-1 of input buffer
*
* \param input buffer holding the data
* \param input buffer holding the data
* \param ilen length of the input data
* \param output SHA-1 checksum result
*/
void esp_sha1_output( const unsigned char *input, size_t ilen, unsigned char output[20] );
void esp_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] );
/**
* \brief SHA-256 context structure
*/
typedef sha_context SHA256_CTX;
/**
* \brief Initialize SHA-256 context
*
* \param ctx SHA-256 context to be initialized
*/
void esp_sha256_init( SHA256_CTX *ctx );
void esp_sha256_init( esp_sha_context *ctx );
/**
* \brief Clear SHA-256 context
*
* \param ctx SHA-256 context to be cleared
*/
void esp_sha256_free( SHA256_CTX *ctx );
void esp_sha256_free( esp_sha_context *ctx );
/**
* \brief Clone (the state of) a SHA-256 context
@@ -135,7 +140,7 @@ void esp_sha256_free( SHA256_CTX *ctx );
* \param dst The destination context
* \param src The context to be cloned
*/
void esp_sha256_clone( SHA256_CTX *dst, const SHA256_CTX *src );
void esp_sha256_clone( esp_sha_context *dst, const esp_sha_context *src );
/**
* \brief SHA-256 context setup
@@ -143,7 +148,7 @@ void esp_sha256_clone( SHA256_CTX *dst, const SHA256_CTX *src );
* \param ctx context to be initialized
* \param is224 0 = use SHA256, 1 = use SHA224
*/
void esp_sha256_start( SHA256_CTX *ctx, int is224 );
void esp_sha256_start( esp_sha_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@@ -152,7 +157,7 @@ void esp_sha256_start( SHA256_CTX *ctx, int is224 );
* \param input buffer holding the data
* \param ilen length of the input data
*/
void esp_sha256_update( SHA256_CTX *ctx, const unsigned char *input, size_t ilen );
void esp_sha256_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief SHA-256 final digest
@@ -160,17 +165,17 @@ void esp_sha256_update( SHA256_CTX *ctx, const unsigned char *input, size_t ilen
* \param ctx SHA-256 context
* \param output SHA-224/256 checksum result
*/
void esp_sha256_finish( SHA256_CTX *ctx, unsigned char output[32] );
void esp_sha256_finish( esp_sha_context *ctx, unsigned char output[32] );
/**
* \brief Output = SHA-256( input buffer )
* \brief Calculate SHA-256 of input buffer
*
* \param input buffer holding the data
* \param input buffer holding the data
* \param ilen length of the input data
* \param output SHA-224/256 checksum result
* \param is224 0 = use SHA256, 1 = use SHA224
*/
void esp_sha256_output( const unsigned char *input, size_t ilen, unsigned char output[32], int is224 );
void esp_sha256( const unsigned char *input, size_t ilen, unsigned char output[32], int is224 );
//
@@ -178,21 +183,19 @@ void esp_sha256_output( const unsigned char *input, size_t ilen, unsigned char o
* \brief SHA-512 context structure
*/
typedef sha_context SHA512_CTX;
/**
* \brief Initialize SHA-512 context
*
* \param ctx SHA-512 context to be initialized
*/
void esp_sha512_init( SHA512_CTX *ctx );
void esp_sha512_init( esp_sha_context *ctx );
/**
* \brief Clear SHA-512 context
*
* \param ctx SHA-512 context to be cleared
*/
void esp_sha512_free( SHA512_CTX *ctx );
void esp_sha512_free( esp_sha_context *ctx );
/**
* \brief Clone (the state of) a SHA-512 context
@@ -200,7 +203,7 @@ void esp_sha512_free( SHA512_CTX *ctx );
* \param dst The destination context
* \param src The context to be cloned
*/
void esp_sha512_clone( SHA512_CTX *dst, const SHA512_CTX *src );
void esp_sha512_clone( esp_sha_context *dst, const esp_sha_context *src );
/**
* \brief SHA-512 context setup
@@ -208,7 +211,7 @@ void esp_sha512_clone( SHA512_CTX *dst, const SHA512_CTX *src );
* \param ctx context to be initialized
* \param is384 0 = use SHA512, 1 = use SHA384
*/
void esp_sha512_start( SHA512_CTX *ctx, int is384 );
void esp_sha512_start( esp_sha_context *ctx, int is384 );
/**
* \brief SHA-512 process buffer
@@ -217,7 +220,7 @@ void esp_sha512_start( SHA512_CTX *ctx, int is384 );
* \param input buffer holding the data
* \param ilen length of the input data
*/
void esp_sha512_update( SHA512_CTX *ctx, const unsigned char *input, size_t ilen );
void esp_sha512_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief SHA-512 final digest
@@ -225,17 +228,17 @@ void esp_sha512_update( SHA512_CTX *ctx, const unsigned char *input, size_t ilen
* \param ctx SHA-512 context
* \param output SHA-384/512 checksum result
*/
void esp_sha512_finish( SHA512_CTX *ctx, unsigned char output[64] );
void esp_sha512_finish( esp_sha_context *ctx, unsigned char output[64] );
/**
* \brief Output = SHA-512( input buffer )
* \brief Calculate SHA-512 of input buffer.
*
* \param input buffer holding the data
* \param input buffer holding the data
* \param ilen length of the input data
* \param output SHA-384/512 checksum result
* \param is384 0 = use SHA512, 1 = use SHA384
*/
void esp_sha512_output( const unsigned char *input, size_t ilen, unsigned char output[64], int is384 );
void esp_sha512( const unsigned char *input, size_t ilen, unsigned char output[64], int is384 );
//