You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-28 16:07:14 +00:00
mbedtls: Update to upstream version 2.28.3
Rediff patch from PR 1453, lstrlenW is no longer used upstream so
that part of the patch was dropped.
(cherry picked from commit 1fde2092d0)
This commit is contained in:
361
thirdparty/mbedtls/library/md4.c
vendored
361
thirdparty/mbedtls/library/md4.c
vendored
@@ -37,21 +37,22 @@
|
||||
|
||||
#if !defined(MBEDTLS_MD4_ALT)
|
||||
|
||||
void mbedtls_md4_init( mbedtls_md4_context *ctx )
|
||||
void mbedtls_md4_init(mbedtls_md4_context *ctx)
|
||||
{
|
||||
memset( ctx, 0, sizeof( mbedtls_md4_context ) );
|
||||
memset(ctx, 0, sizeof(mbedtls_md4_context));
|
||||
}
|
||||
|
||||
void mbedtls_md4_free( mbedtls_md4_context *ctx )
|
||||
void mbedtls_md4_free(mbedtls_md4_context *ctx)
|
||||
{
|
||||
if( ctx == NULL )
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mbedtls_platform_zeroize( ctx, sizeof( mbedtls_md4_context ) );
|
||||
mbedtls_platform_zeroize(ctx, sizeof(mbedtls_md4_context));
|
||||
}
|
||||
|
||||
void mbedtls_md4_clone( mbedtls_md4_context *dst,
|
||||
const mbedtls_md4_context *src )
|
||||
void mbedtls_md4_clone(mbedtls_md4_context *dst,
|
||||
const mbedtls_md4_context *src)
|
||||
{
|
||||
*dst = *src;
|
||||
}
|
||||
@@ -59,7 +60,7 @@ void mbedtls_md4_clone( mbedtls_md4_context *dst,
|
||||
/*
|
||||
* MD4 context setup
|
||||
*/
|
||||
int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx )
|
||||
int mbedtls_md4_starts_ret(mbedtls_md4_context *ctx)
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
@@ -69,43 +70,42 @@ int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx )
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4_starts( mbedtls_md4_context *ctx )
|
||||
void mbedtls_md4_starts(mbedtls_md4_context *ctx)
|
||||
{
|
||||
mbedtls_md4_starts_ret( ctx );
|
||||
mbedtls_md4_starts_ret(ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_MD4_PROCESS_ALT)
|
||||
int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
int mbedtls_internal_md4_process(mbedtls_md4_context *ctx,
|
||||
const unsigned char data[64])
|
||||
{
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
uint32_t X[16], A, B, C, D;
|
||||
} local;
|
||||
|
||||
local.X[ 0] = MBEDTLS_GET_UINT32_LE( data, 0 );
|
||||
local.X[ 1] = MBEDTLS_GET_UINT32_LE( data, 4 );
|
||||
local.X[ 2] = MBEDTLS_GET_UINT32_LE( data, 8 );
|
||||
local.X[ 3] = MBEDTLS_GET_UINT32_LE( data, 12 );
|
||||
local.X[ 4] = MBEDTLS_GET_UINT32_LE( data, 16 );
|
||||
local.X[ 5] = MBEDTLS_GET_UINT32_LE( data, 20 );
|
||||
local.X[ 6] = MBEDTLS_GET_UINT32_LE( data, 24 );
|
||||
local.X[ 7] = MBEDTLS_GET_UINT32_LE( data, 28 );
|
||||
local.X[ 8] = MBEDTLS_GET_UINT32_LE( data, 32 );
|
||||
local.X[ 9] = MBEDTLS_GET_UINT32_LE( data, 36 );
|
||||
local.X[10] = MBEDTLS_GET_UINT32_LE( data, 40 );
|
||||
local.X[11] = MBEDTLS_GET_UINT32_LE( data, 44 );
|
||||
local.X[12] = MBEDTLS_GET_UINT32_LE( data, 48 );
|
||||
local.X[13] = MBEDTLS_GET_UINT32_LE( data, 52 );
|
||||
local.X[14] = MBEDTLS_GET_UINT32_LE( data, 56 );
|
||||
local.X[15] = MBEDTLS_GET_UINT32_LE( data, 60 );
|
||||
local.X[0] = MBEDTLS_GET_UINT32_LE(data, 0);
|
||||
local.X[1] = MBEDTLS_GET_UINT32_LE(data, 4);
|
||||
local.X[2] = MBEDTLS_GET_UINT32_LE(data, 8);
|
||||
local.X[3] = MBEDTLS_GET_UINT32_LE(data, 12);
|
||||
local.X[4] = MBEDTLS_GET_UINT32_LE(data, 16);
|
||||
local.X[5] = MBEDTLS_GET_UINT32_LE(data, 20);
|
||||
local.X[6] = MBEDTLS_GET_UINT32_LE(data, 24);
|
||||
local.X[7] = MBEDTLS_GET_UINT32_LE(data, 28);
|
||||
local.X[8] = MBEDTLS_GET_UINT32_LE(data, 32);
|
||||
local.X[9] = MBEDTLS_GET_UINT32_LE(data, 36);
|
||||
local.X[10] = MBEDTLS_GET_UINT32_LE(data, 40);
|
||||
local.X[11] = MBEDTLS_GET_UINT32_LE(data, 44);
|
||||
local.X[12] = MBEDTLS_GET_UINT32_LE(data, 48);
|
||||
local.X[13] = MBEDTLS_GET_UINT32_LE(data, 52);
|
||||
local.X[14] = MBEDTLS_GET_UINT32_LE(data, 56);
|
||||
local.X[15] = MBEDTLS_GET_UINT32_LE(data, 60);
|
||||
|
||||
#define S(x,n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))
|
||||
#define S(x, n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))
|
||||
|
||||
local.A = ctx->state[0];
|
||||
local.B = ctx->state[1];
|
||||
@@ -113,86 +113,86 @@ int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
|
||||
local.D = ctx->state[3];
|
||||
|
||||
#define F(x, y, z) (((x) & (y)) | ((~(x)) & (z)))
|
||||
#define P(a,b,c,d,x,s) \
|
||||
#define P(a, b, c, d, x, s) \
|
||||
do \
|
||||
{ \
|
||||
(a) += F((b),(c),(d)) + (x); \
|
||||
(a) = S((a),(s)); \
|
||||
} while( 0 )
|
||||
(a) += F((b), (c), (d)) + (x); \
|
||||
(a) = S((a), (s)); \
|
||||
} while (0)
|
||||
|
||||
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 0], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 1], 7 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[ 2], 11 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[ 3], 19 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 4], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 5], 7 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[ 6], 11 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[ 7], 19 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 8], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 9], 7 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[10], 11 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[11], 19 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[12], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[13], 7 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[14], 11 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[15], 19 );
|
||||
P(local.A, local.B, local.C, local.D, local.X[0], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[1], 7);
|
||||
P(local.C, local.D, local.A, local.B, local.X[2], 11);
|
||||
P(local.B, local.C, local.D, local.A, local.X[3], 19);
|
||||
P(local.A, local.B, local.C, local.D, local.X[4], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[5], 7);
|
||||
P(local.C, local.D, local.A, local.B, local.X[6], 11);
|
||||
P(local.B, local.C, local.D, local.A, local.X[7], 19);
|
||||
P(local.A, local.B, local.C, local.D, local.X[8], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[9], 7);
|
||||
P(local.C, local.D, local.A, local.B, local.X[10], 11);
|
||||
P(local.B, local.C, local.D, local.A, local.X[11], 19);
|
||||
P(local.A, local.B, local.C, local.D, local.X[12], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[13], 7);
|
||||
P(local.C, local.D, local.A, local.B, local.X[14], 11);
|
||||
P(local.B, local.C, local.D, local.A, local.X[15], 19);
|
||||
|
||||
#undef P
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
#define P(a,b,c,d,x,s) \
|
||||
#define F(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
#define P(a, b, c, d, x, s) \
|
||||
do \
|
||||
{ \
|
||||
(a) += F((b),(c),(d)) + (x) + 0x5A827999; \
|
||||
(a) = S((a),(s)); \
|
||||
} while( 0 )
|
||||
(a) += F((b), (c), (d)) + (x) + 0x5A827999; \
|
||||
(a) = S((a), (s)); \
|
||||
} while (0)
|
||||
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 0], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 4], 5 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[ 8], 9 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[12], 13 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 1], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 5], 5 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[ 9], 9 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[13], 13 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 2], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 6], 5 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[10], 9 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[14], 13 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 3], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 7], 5 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[11], 9 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[15], 13 );
|
||||
P(local.A, local.B, local.C, local.D, local.X[0], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[4], 5);
|
||||
P(local.C, local.D, local.A, local.B, local.X[8], 9);
|
||||
P(local.B, local.C, local.D, local.A, local.X[12], 13);
|
||||
P(local.A, local.B, local.C, local.D, local.X[1], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[5], 5);
|
||||
P(local.C, local.D, local.A, local.B, local.X[9], 9);
|
||||
P(local.B, local.C, local.D, local.A, local.X[13], 13);
|
||||
P(local.A, local.B, local.C, local.D, local.X[2], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[6], 5);
|
||||
P(local.C, local.D, local.A, local.B, local.X[10], 9);
|
||||
P(local.B, local.C, local.D, local.A, local.X[14], 13);
|
||||
P(local.A, local.B, local.C, local.D, local.X[3], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[7], 5);
|
||||
P(local.C, local.D, local.A, local.B, local.X[11], 9);
|
||||
P(local.B, local.C, local.D, local.A, local.X[15], 13);
|
||||
|
||||
#undef P
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) ((x) ^ (y) ^ (z))
|
||||
#define P(a,b,c,d,x,s) \
|
||||
#define F(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define P(a, b, c, d, x, s) \
|
||||
do \
|
||||
{ \
|
||||
(a) += F((b),(c),(d)) + (x) + 0x6ED9EBA1; \
|
||||
(a) = S((a),(s)); \
|
||||
} while( 0 )
|
||||
(a) += F((b), (c), (d)) + (x) + 0x6ED9EBA1; \
|
||||
(a) = S((a), (s)); \
|
||||
} while (0)
|
||||
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 0], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 8], 9 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[ 4], 11 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[12], 15 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 2], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[10], 9 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[ 6], 11 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[14], 15 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 1], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[ 9], 9 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[ 5], 11 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[13], 15 );
|
||||
P( local.A, local.B, local.C, local.D, local.X[ 3], 3 );
|
||||
P( local.D, local.A, local.B, local.C, local.X[11], 9 );
|
||||
P( local.C, local.D, local.A, local.B, local.X[ 7], 11 );
|
||||
P( local.B, local.C, local.D, local.A, local.X[15], 15 );
|
||||
P(local.A, local.B, local.C, local.D, local.X[0], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[8], 9);
|
||||
P(local.C, local.D, local.A, local.B, local.X[4], 11);
|
||||
P(local.B, local.C, local.D, local.A, local.X[12], 15);
|
||||
P(local.A, local.B, local.C, local.D, local.X[2], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[10], 9);
|
||||
P(local.C, local.D, local.A, local.B, local.X[6], 11);
|
||||
P(local.B, local.C, local.D, local.A, local.X[14], 15);
|
||||
P(local.A, local.B, local.C, local.D, local.X[1], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[9], 9);
|
||||
P(local.C, local.D, local.A, local.B, local.X[5], 11);
|
||||
P(local.B, local.C, local.D, local.A, local.X[13], 15);
|
||||
P(local.A, local.B, local.C, local.D, local.X[3], 3);
|
||||
P(local.D, local.A, local.B, local.C, local.X[11], 9);
|
||||
P(local.C, local.D, local.A, local.B, local.X[7], 11);
|
||||
P(local.B, local.C, local.D, local.A, local.X[15], 15);
|
||||
|
||||
#undef F
|
||||
#undef P
|
||||
@@ -203,16 +203,16 @@ int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
|
||||
ctx->state[3] += local.D;
|
||||
|
||||
/* Zeroise variables to clear sensitive data from memory. */
|
||||
mbedtls_platform_zeroize( &local, sizeof( local ) );
|
||||
mbedtls_platform_zeroize(&local, sizeof(local));
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4_process( mbedtls_md4_context *ctx,
|
||||
const unsigned char data[64] )
|
||||
void mbedtls_md4_process(mbedtls_md4_context *ctx,
|
||||
const unsigned char data[64])
|
||||
{
|
||||
mbedtls_internal_md4_process( ctx, data );
|
||||
mbedtls_internal_md4_process(ctx, data);
|
||||
}
|
||||
#endif
|
||||
#endif /* !MBEDTLS_MD4_PROCESS_ALT */
|
||||
@@ -220,16 +220,17 @@ void mbedtls_md4_process( mbedtls_md4_context *ctx,
|
||||
/*
|
||||
* MD4 process buffer
|
||||
*/
|
||||
int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
int mbedtls_md4_update_ret(mbedtls_md4_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t fill;
|
||||
uint32_t left;
|
||||
|
||||
if( ilen == 0 )
|
||||
return( 0 );
|
||||
if (ilen == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
@@ -237,52 +238,52 @@ int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
|
||||
ctx->total[0] += (uint32_t) ilen;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < (uint32_t) ilen )
|
||||
if (ctx->total[0] < (uint32_t) ilen) {
|
||||
ctx->total[1]++;
|
||||
}
|
||||
|
||||
if( left && ilen >= fill )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
(void *) input, fill );
|
||||
if (left && ilen >= fill) {
|
||||
memcpy((void *) (ctx->buffer + left),
|
||||
(void *) input, fill);
|
||||
|
||||
if( ( ret = mbedtls_internal_md4_process( ctx, ctx->buffer ) ) != 0 )
|
||||
return( ret );
|
||||
if ((ret = mbedtls_internal_md4_process(ctx, ctx->buffer)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
input += fill;
|
||||
ilen -= fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( ilen >= 64 )
|
||||
{
|
||||
if( ( ret = mbedtls_internal_md4_process( ctx, input ) ) != 0 )
|
||||
return( ret );
|
||||
while (ilen >= 64) {
|
||||
if ((ret = mbedtls_internal_md4_process(ctx, input)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
input += 64;
|
||||
ilen -= 64;
|
||||
}
|
||||
|
||||
if( ilen > 0 )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
(void *) input, ilen );
|
||||
if (ilen > 0) {
|
||||
memcpy((void *) (ctx->buffer + left),
|
||||
(void *) input, ilen);
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4_update( mbedtls_md4_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen )
|
||||
void mbedtls_md4_update(mbedtls_md4_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen)
|
||||
{
|
||||
mbedtls_md4_update_ret( ctx, input, ilen );
|
||||
mbedtls_md4_update_ret(ctx, input, ilen);
|
||||
}
|
||||
#endif
|
||||
|
||||
static const unsigned char md4_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
@@ -291,45 +292,47 @@ static const unsigned char md4_padding[64] =
|
||||
/*
|
||||
* MD4 final digest
|
||||
*/
|
||||
int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
|
||||
unsigned char output[16] )
|
||||
int mbedtls_md4_finish_ret(mbedtls_md4_context *ctx,
|
||||
unsigned char output[16])
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
uint32_t last, padn;
|
||||
uint32_t high, low;
|
||||
unsigned char msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
high = (ctx->total[0] >> 29)
|
||||
| (ctx->total[1] << 3);
|
||||
low = (ctx->total[0] << 3);
|
||||
|
||||
MBEDTLS_PUT_UINT32_LE( low, msglen, 0 );
|
||||
MBEDTLS_PUT_UINT32_LE( high, msglen, 4 );
|
||||
MBEDTLS_PUT_UINT32_LE(low, msglen, 0);
|
||||
MBEDTLS_PUT_UINT32_LE(high, msglen, 4);
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
padn = (last < 56) ? (56 - last) : (120 - last);
|
||||
|
||||
ret = mbedtls_md4_update_ret( ctx, (unsigned char *)md4_padding, padn );
|
||||
if( ret != 0 )
|
||||
return( ret );
|
||||
ret = mbedtls_md4_update_ret(ctx, (unsigned char *) md4_padding, padn);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_md4_update_ret( ctx, msglen, 8 ) ) != 0 )
|
||||
return( ret );
|
||||
if ((ret = mbedtls_md4_update_ret(ctx, msglen, 8)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
MBEDTLS_PUT_UINT32_LE( ctx->state[0], output, 0 );
|
||||
MBEDTLS_PUT_UINT32_LE( ctx->state[1], output, 4 );
|
||||
MBEDTLS_PUT_UINT32_LE( ctx->state[2], output, 8 );
|
||||
MBEDTLS_PUT_UINT32_LE( ctx->state[3], output, 12 );
|
||||
MBEDTLS_PUT_UINT32_LE(ctx->state[0], output, 0);
|
||||
MBEDTLS_PUT_UINT32_LE(ctx->state[1], output, 4);
|
||||
MBEDTLS_PUT_UINT32_LE(ctx->state[2], output, 8);
|
||||
MBEDTLS_PUT_UINT32_LE(ctx->state[3], output, 12);
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4_finish( mbedtls_md4_context *ctx,
|
||||
unsigned char output[16] )
|
||||
void mbedtls_md4_finish(mbedtls_md4_context *ctx,
|
||||
unsigned char output[16])
|
||||
{
|
||||
mbedtls_md4_finish_ret( ctx, output );
|
||||
mbedtls_md4_finish_ret(ctx, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -338,36 +341,39 @@ void mbedtls_md4_finish( mbedtls_md4_context *ctx,
|
||||
/*
|
||||
* output = MD4( input buffer )
|
||||
*/
|
||||
int mbedtls_md4_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] )
|
||||
int mbedtls_md4_ret(const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16])
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_md4_context ctx;
|
||||
|
||||
mbedtls_md4_init( &ctx );
|
||||
mbedtls_md4_init(&ctx);
|
||||
|
||||
if( ( ret = mbedtls_md4_starts_ret( &ctx ) ) != 0 )
|
||||
if ((ret = mbedtls_md4_starts_ret(&ctx)) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_md4_update_ret( &ctx, input, ilen ) ) != 0 )
|
||||
if ((ret = mbedtls_md4_update_ret(&ctx, input, ilen)) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_md4_finish_ret( &ctx, output ) ) != 0 )
|
||||
if ((ret = mbedtls_md4_finish_ret(&ctx, output)) != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_md4_free( &ctx );
|
||||
mbedtls_md4_free(&ctx);
|
||||
|
||||
return( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_md4( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] )
|
||||
void mbedtls_md4(const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16])
|
||||
{
|
||||
mbedtls_md4_ret( input, ilen, output );
|
||||
mbedtls_md4_ret(input, ilen, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -413,40 +419,43 @@ static const unsigned char md4_test_sum[7][16] =
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
int mbedtls_md4_self_test( int verbose )
|
||||
int mbedtls_md4_self_test(int verbose)
|
||||
{
|
||||
int i, ret = 0;
|
||||
unsigned char md4sum[16];
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD4 test #%d: ", i + 1 );
|
||||
for (i = 0; i < 7; i++) {
|
||||
if (verbose != 0) {
|
||||
mbedtls_printf(" MD4 test #%d: ", i + 1);
|
||||
}
|
||||
|
||||
ret = mbedtls_md4_ret( md4_test_str[i], md4_test_strlen[i], md4sum );
|
||||
if( ret != 0 )
|
||||
ret = mbedtls_md4_ret(md4_test_str[i], md4_test_strlen[i], md4sum);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if( memcmp( md4sum, md4_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if (memcmp(md4sum, md4_test_sum[i], 16) != 0) {
|
||||
ret = 1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
if (verbose != 0) {
|
||||
mbedtls_printf("passed\n");
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "\n" );
|
||||
if (verbose != 0) {
|
||||
mbedtls_printf("\n");
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
if (verbose != 0) {
|
||||
mbedtls_printf("failed\n");
|
||||
}
|
||||
|
||||
return( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
Reference in New Issue
Block a user