52#if !defined(MBEDTLS_CONFIG_FILE)
55#include MBEDTLS_CONFIG_FILE
58#if defined(MBEDTLS_SHA1_C)
65#if defined(MBEDTLS_SELF_TEST)
66#if defined(MBEDTLS_PLATFORM_C)
70#define mbedtls_printf printf
74#define SHA1_VALIDATE_RET(cond) \
75 MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA1_BAD_INPUT_DATA )
77#define SHA1_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond )
79#if !defined(MBEDTLS_SHA1_ALT)
85#define GET_UINT32_BE(n,b,i) \
87 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
88 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
89 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
90 | ( (uint32_t) (b)[(i) + 3] ); \
95#define PUT_UINT32_BE(n,b,i) \
97 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
98 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
99 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
100 (b)[(i) + 3] = (unsigned char) ( (n) ); \
133 SHA1_VALIDATE_RET(
ctx !=
NULL );
138 ctx->state[0] = 0x67452301;
139 ctx->state[1] = 0xEFCDAB89;
140 ctx->state[2] = 0x98BADCFE;
141 ctx->state[3] = 0x10325476;
142 ctx->state[4] = 0xC3D2E1F0;
147#if !defined(MBEDTLS_DEPRECATED_REMOVED)
154#if !defined(MBEDTLS_SHA1_PROCESS_ALT)
156 const unsigned char data[64] )
163 SHA1_VALIDATE_RET(
ctx !=
NULL );
164 SHA1_VALIDATE_RET( (
const unsigned char *)
data !=
NULL );
183#define S(x,n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))
187 local.temp = local.W[( (t) - 3 ) & 0x0F] ^ \
188 local.W[( (t) - 8 ) & 0x0F] ^ \
189 local.W[( (t) - 14 ) & 0x0F] ^ \
190 local.W[ (t) & 0x0F], \
191 ( local.W[(t) & 0x0F] = S(local.temp,1) ) \
194#define P(a,b,c,d,e,x) \
197 (e) += S((a),5) + F((b),(c),(d)) + K + (x); \
207#define F(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
234#define F(x,y,z) ((x) ^ (y) ^ (z))
261#define F(x,y,z) (((x) & (y)) | ((z) & ((x) | (y))))
288#define F(x,y,z) ((x) ^ (y) ^ (z))
327#if !defined(MBEDTLS_DEPRECATED_REMOVED)
329 const unsigned char data[64] )
340 const unsigned char *
input,
347 SHA1_VALIDATE_RET(
ctx !=
NULL );
348 SHA1_VALIDATE_RET( ilen == 0 ||
input !=
NULL );
357 ctx->total[0] &= 0xFFFFFFFF;
389#if !defined(MBEDTLS_DEPRECATED_REMOVED)
391 const unsigned char *
input,
402 unsigned char output[20] )
408 SHA1_VALIDATE_RET(
ctx !=
NULL );
409 SHA1_VALIDATE_RET( (
unsigned char *)output !=
NULL );
437 high = (
ctx->total[0] >> 29 )
438 | (
ctx->total[1] << 3 );
439 low = (
ctx->total[0] << 3 );
441 PUT_UINT32_BE( high,
ctx->buffer, 56 );
442 PUT_UINT32_BE( low,
ctx->buffer, 60 );
450 PUT_UINT32_BE(
ctx->state[0], output, 0 );
451 PUT_UINT32_BE(
ctx->state[1], output, 4 );
452 PUT_UINT32_BE(
ctx->state[2], output, 8 );
453 PUT_UINT32_BE(
ctx->state[3], output, 12 );
454 PUT_UINT32_BE(
ctx->state[4], output, 16 );
459#if !defined(MBEDTLS_DEPRECATED_REMOVED)
461 unsigned char output[20] )
474 unsigned char output[20] )
479 SHA1_VALIDATE_RET( ilen == 0 ||
input !=
NULL );
480 SHA1_VALIDATE_RET( (
unsigned char *)output !=
NULL );
499#if !defined(MBEDTLS_DEPRECATED_REMOVED)
502 unsigned char output[20] )
508#if defined(MBEDTLS_SELF_TEST)
512static const unsigned char sha1_test_buf[3][57] =
515 {
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
519static const size_t sha1_test_buflen[3] =
524static const unsigned char sha1_test_sum[3][20] =
526 { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
527 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
528 { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
529 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
530 { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
531 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
537int mbedtls_sha1_self_test(
int verbose )
539 int i,
j, buflen,
ret = 0;
540 unsigned char buf[1024];
541 unsigned char sha1sum[20];
549 for(
i = 0;
i < 3;
i++ )
561 for(
j = 0;
j < 1000;
j++ )
571 sha1_test_buflen[
i] );
579 if(
memcmp( sha1sum, sha1_test_sum[
i], 20 ) != 0 )
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLenum GLenum input
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
This file contains SHA-1 definitions and functions.
MBEDTLS_DEPRECATED void mbedtls_sha1_finish(mbedtls_sha1_context *ctx, unsigned char output[20])
This function finishes the SHA-1 operation, and writes the result to the output buffer.
void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
This function clears a SHA-1 context.
void mbedtls_sha1_clone(mbedtls_sha1_context *dst, const mbedtls_sha1_context *src)
This function clones the state of a SHA-1 context.
MBEDTLS_DEPRECATED void mbedtls_sha1_starts(mbedtls_sha1_context *ctx)
This function starts a SHA-1 checksum calculation.
MBEDTLS_DEPRECATED void mbedtls_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])
SHA-1 process data block (internal use only).
int mbedtls_sha1_ret(const unsigned char *input, size_t ilen, unsigned char output[20])
This function calculates the SHA-1 checksum of a buffer.
int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-1 checksum calculation.
int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])
SHA-1 process data block (internal use only).
int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx)
This function starts a SHA-1 checksum calculation.
MBEDTLS_DEPRECATED void mbedtls_sha1_update(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-1 checksum calculation.
MBEDTLS_DEPRECATED void mbedtls_sha1(const unsigned char *input, size_t ilen, unsigned char output[20])
This function calculates the SHA-1 checksum of a buffer.
int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, unsigned char output[20])
This function finishes the SHA-1 operation, and writes the result to the output buffer.
void mbedtls_sha1_init(mbedtls_sha1_context *ctx)
This function initializes a SHA-1 context.
#define memcpy(s1, s2, n)
Configuration options (set of defines)
The SHA-1 context structure.