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,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 );
//