Changeset efd19aa in rtems


Ignore:
Timestamp:
07/09/18 07:24:05 (5 years ago)
Author:
Conrad Meyer <cem@…>
Branches:
master
Children:
f5ee9a0
Parents:
48f7979
git-author:
Conrad Meyer <cem@…> (07/09/18 07:24:05)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/08/22 14:14:56)
Message:

Implement SHA2-224 submode of SHA2-256

Like SHA2-384:SHA2-512, SHA2-224 is simply a truncated SHA2-256 with a
different initial vector. Add to round out the complete basic SHA2 family.

Location:
cpukit
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmd/sha256c.c

    r48f7979 refd19aa  
    3333#include <string.h>
    3434
     35#include "sha224.h"
    3536#include "sha256.h"
    3637
     
    297298        memset(ctx, 0, sizeof(*ctx));
    298299}
     300
     301/*** SHA-224: *********************************************************/
     302/*
     303 * the SHA224 and SHA256 transforms are identical
     304 */
     305
     306/* SHA-224 initialization.  Begins a SHA-224 operation. */
     307void
     308SHA224_Init(SHA224_CTX * ctx)
     309{
     310
     311        /* Zero bits processed so far */
     312        ctx->count = 0;
     313
     314        /* Magic initialization constants */
     315        ctx->state[0] = 0xC1059ED8;
     316        ctx->state[1] = 0x367CD507;
     317        ctx->state[2] = 0x3070DD17;
     318        ctx->state[3] = 0xF70E5939;
     319        ctx->state[4] = 0xFFC00B31;
     320        ctx->state[5] = 0x68581511;
     321        ctx->state[6] = 0x64f98FA7;
     322        ctx->state[7] = 0xBEFA4FA4;
     323}
     324
     325/* Add bytes into the SHA-224 hash */
     326void
     327SHA224_Update(SHA224_CTX * ctx, const void *in, size_t len)
     328{
     329
     330        SHA256_Update((SHA256_CTX *)ctx, in, len);
     331}
     332
     333/*
     334 * SHA-224 finalization.  Pads the input data, exports the hash value,
     335 * and clears the context state.
     336 */
     337void
     338SHA224_Final(unsigned char digest[static SHA224_DIGEST_LENGTH], SHA224_CTX *ctx)
     339{
     340
     341        /* Add padding */
     342        SHA256_Pad((SHA256_CTX *)ctx);
     343
     344        /* Write the hash */
     345        be32enc_vect(digest, ctx->state, SHA224_DIGEST_LENGTH);
     346
     347        /* Clear the context state */
     348        explicit_bzero(ctx, sizeof(*ctx));
     349}
Note: See TracChangeset for help on using the changeset viewer.