Skip to content

Commit 985afb8

Browse files
authored
Merge pull request #8728 from RonEld/cryptocell_sha_alt_fixes
Fix issues in Cryptocell 310 shax_alt discovered by On Target Testing
2 parents c387fec + bcbda3e commit 985afb8

File tree

4 files changed

+10
-210
lines changed

4 files changed

+10
-210
lines changed

features/cryptocell/FEATURE_CRYPTOCELL310/sha1_alt.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#include "mbedtls/sha1.h"
2222
#if defined(MBEDTLS_SHA1_ALT)
2323
#include <string.h>
24+
#include "mbedtls/platform.h"
2425

2526
void mbedtls_sha1_init( mbedtls_sha1_context *ctx )
2627
{
2728
memset( ctx, 0, sizeof( mbedtls_sha1_context ) );
28-
2929
}
3030

3131
void mbedtls_sha1_free( mbedtls_sha1_context *ctx )
@@ -64,10 +64,10 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
6464
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
6565
unsigned char output[20] )
6666
{
67-
CRYSError_t CrysErr = CRYS_OK;
67+
CRYSError_t crys_err = CRYS_OK;
6868
CRYS_HASH_Result_t crys_result = {0};
69-
CrysErr = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result );
70-
if( CrysErr == CRYS_OK )
69+
crys_err = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result );
70+
if( crys_err == CRYS_OK )
7171
{
7272
memcpy( output, crys_result, 20 );
7373
return ( 0 );
@@ -79,8 +79,6 @@ int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
7979
int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
8080
const unsigned char data[64] )
8181
{
82-
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)data, 64 ) != CRYS_OK )
83-
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
84-
return ( 0 );
82+
return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
8583
}
8684
#endif //MBEDTLS_SHA1_ALT

features/cryptocell/FEATURE_CRYPTOCELL310/sha1_alt.h

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#define __SHA1_ALT__
2323
#if defined(MBEDTLS_SHA1_ALT)
2424
#include "crys_hash.h"
25-
#ifdef __cplusplus
26-
extern "C" {
27-
#endif
28-
2925

3026
/**
3127
* \brief SHA-1 context structure
@@ -35,114 +31,6 @@ typedef struct
3531
CRYS_HASHUserContext_t crys_hash_ctx;
3632
} mbedtls_sha1_context;
3733

38-
/**
39-
* \brief This function initializes a SHA-1 context.
40-
*
41-
* \param ctx The SHA-1 context to initialize.
42-
*
43-
* \warning SHA-1 is considered a weak message digest and its use
44-
* constitutes a security risk. We recommend considering
45-
* stronger message digests instead.
46-
*
47-
*/
48-
void mbedtls_sha1_init( mbedtls_sha1_context *ctx );
49-
50-
/**
51-
* \brief This function clears a SHA-1 context.
52-
*
53-
* \param ctx The SHA-1 context to clear.
54-
*
55-
* \warning SHA-1 is considered a weak message digest and its use
56-
* constitutes a security risk. We recommend considering
57-
* stronger message digests instead.
58-
*
59-
*/
60-
void mbedtls_sha1_free( mbedtls_sha1_context *ctx );
61-
62-
/**
63-
* \brief This function clones the state of a SHA-1 context.
64-
*
65-
* \param dst The destination context.
66-
* \param src The context to clone.
67-
*
68-
* \warning SHA-1 is considered a weak message digest and its use
69-
* constitutes a security risk. We recommend considering
70-
* stronger message digests instead.
71-
*
72-
*/
73-
void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
74-
const mbedtls_sha1_context *src );
75-
76-
/**
77-
* \brief This function starts a SHA-1 checksum calculation.
78-
*
79-
* \param ctx The context to initialize.
80-
*
81-
* \return \c 0 if successful
82-
*
83-
* \warning SHA-1 is considered a weak message digest and its use
84-
* constitutes a security risk. We recommend considering
85-
* stronger message digests instead.
86-
*
87-
*/
88-
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
89-
90-
/**
91-
* \brief This function feeds an input buffer into an ongoing SHA-1
92-
* checksum calculation.
93-
*
94-
* \param ctx The SHA-1 context.
95-
* \param input The buffer holding the input data.
96-
* \param ilen The length of the input data.
97-
*
98-
* \return \c 0 if successful
99-
*
100-
* \warning SHA-1 is considered a weak message digest and its use
101-
* constitutes a security risk. We recommend considering
102-
* stronger message digests instead.
103-
*
104-
*/
105-
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
106-
const unsigned char *input,
107-
size_t ilen );
108-
109-
/**
110-
* \brief This function finishes the SHA-1 operation, and writes
111-
* the result to the output buffer.
112-
*
113-
* \param ctx The SHA-1 context.
114-
* \param output The SHA-1 checksum result.
115-
*
116-
* \return \c 0 if successful
117-
*
118-
* \warning SHA-1 is considered a weak message digest and its use
119-
* constitutes a security risk. We recommend considering
120-
* stronger message digests instead.
121-
*
122-
*/
123-
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
124-
unsigned char output[20] );
125-
126-
/**
127-
* \brief SHA-1 process data block (internal use only)
128-
*
129-
* \param ctx SHA-1 context
130-
* \param data The data block being processed.
131-
*
132-
* \return \c 0 if successful
133-
*
134-
* \warning SHA-1 is considered a weak message digest and its use
135-
* constitutes a security risk. We recommend considering
136-
* stronger message digests instead.
137-
*
138-
*/
139-
int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
140-
const unsigned char data[64] );
141-
142-
#ifdef __cplusplus
143-
}
144-
#endif
145-
14634
#endif //MBEDTLS_SHA1_ALT
14735
#endif //__SHA1_ALT__
14836

features/cryptocell/FEATURE_CRYPTOCELL310/sha256_alt.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#include "mbedtls/sha256.h"
2222
#if defined(MBEDTLS_SHA256_ALT)
2323
#include <string.h>
24+
#include "mbedtls/platform.h"
2425

2526
void mbedtls_sha256_init( mbedtls_sha256_context *ctx )
2627
{
2728
memset( ctx, 0, sizeof( mbedtls_sha256_context ) );
28-
2929
}
3030

3131
void mbedtls_sha256_free( mbedtls_sha256_context *ctx )
@@ -54,9 +54,7 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
5454
int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
5555
const unsigned char data[64] )
5656
{
57-
if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)data, 64 ) != CRYS_OK )
58-
return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
59-
return ( 0 );
57+
return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
6058
}
6159

6260
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
@@ -71,10 +69,10 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
7169
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
7270
unsigned char output[32] )
7371
{
74-
CRYSError_t CrysErr = CRYS_OK;
72+
CRYSError_t crys_err = CRYS_OK;
7573
CRYS_HASH_Result_t crys_result = {0};
76-
CrysErr = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result );
77-
if( CrysErr == CRYS_OK )
74+
crys_err = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result );
75+
if( crys_err == CRYS_OK )
7876
{
7977
memcpy( output, crys_result, 32 );
8078
return ( 0 );

features/cryptocell/FEATURE_CRYPTOCELL310/sha256_alt.h

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
#if defined(MBEDTLS_SHA256_ALT)
2525

2626
#include "crys_hash.h"
27-
#ifdef __cplusplus
28-
extern "C" {
29-
#endif
30-
3127

3228
/**
3329
* \brief SHA-256 context structure
@@ -37,85 +33,5 @@ typedef struct
3733
CRYS_HASHUserContext_t crys_hash_ctx;
3834
} mbedtls_sha256_context;
3935

40-
41-
/**
42-
* \brief This function initializes a SHA-256 context.
43-
*
44-
* \param ctx The SHA-256 context to initialize.
45-
*/
46-
void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
47-
48-
/**
49-
* \brief This function clears a SHA-256 context.
50-
*
51-
* \param ctx The SHA-256 context to clear.
52-
*/
53-
void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
54-
55-
/**
56-
* \brief This function clones the state of a SHA-256 context.
57-
*
58-
* \param dst The destination context.
59-
* \param src The context to clone.
60-
*/
61-
void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
62-
const mbedtls_sha256_context *src );
63-
64-
/**
65-
* \brief This function starts a SHA-224 or SHA-256 checksum
66-
* calculation.
67-
*
68-
* \param ctx The context to initialize.
69-
* \param is224 Determines which function to use.
70-
* <ul><li>0: Use SHA-256.</li>
71-
* <li>1: Use SHA-224.</li></ul>
72-
*
73-
* \return \c 0 on success.
74-
*/
75-
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
76-
77-
/**
78-
* \brief This function feeds an input buffer into an ongoing
79-
* SHA-256 checksum calculation.
80-
*
81-
* \param ctx SHA-256 context
82-
* \param input buffer holding the data
83-
* \param ilen length of the input data
84-
*
85-
* \return \c 0 on success.
86-
*/
87-
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
88-
const unsigned char *input,
89-
size_t ilen );
90-
91-
/**
92-
* \brief This function finishes the SHA-256 operation, and writes
93-
* the result to the output buffer.
94-
*
95-
* \param ctx The SHA-256 context.
96-
* \param output The SHA-224 or SHA-256 checksum result.
97-
*
98-
* \return \c 0 on success.
99-
*/
100-
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
101-
unsigned char output[32] );
102-
103-
/**
104-
* \brief This function processes a single data block within
105-
* the ongoing SHA-256 computation. This function is for
106-
* internal use only.
107-
*
108-
* \param ctx The SHA-256 context.
109-
* \param data The buffer holding one block of data.
110-
*
111-
* \return \c 0 on success.
112-
*/
113-
int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
114-
const unsigned char data[64] );
115-
116-
#ifdef __cplusplus
117-
}
118-
#endif
119-
12036
#endif // MBEDTLS_SHA256_ALT__
12137
#endif //__SHA256_ALT__

0 commit comments

Comments
 (0)