Changeset View
Changeset View
Standalone View
Standalone View
sys/crypto/sha2/sha512c.c
/*- | /*- | ||||
* Copyright 2005 Colin Percival | * Copyright 2005 Colin Percival | ||||
* Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org> | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
Show All 21 Lines | |||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#else | #else | ||||
#include <string.h> | #include <string.h> | ||||
#endif | #endif | ||||
#include "sha512.h" | #include "sha512.h" | ||||
#include "sha512t.h" | |||||
#include "sha384.h" | #include "sha384.h" | ||||
#if BYTE_ORDER == BIG_ENDIAN | #if BYTE_ORDER == BIG_ENDIAN | ||||
/* Copy a vector of big-endian uint64_t into a vector of bytes */ | /* Copy a vector of big-endian uint64_t into a vector of bytes */ | ||||
#define be64enc_vect(dst, src, len) \ | #define be64enc_vect(dst, src, len) \ | ||||
memcpy((void *)dst, (const void *)src, (size_t)len) | memcpy((void *)dst, (const void *)src, (size_t)len) | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | SHA512_Final(unsigned char digest[SHA512_DIGEST_LENGTH], SHA512_CTX * ctx) | ||||
/* Write the hash */ | /* Write the hash */ | ||||
be64enc_vect(digest, ctx->state, SHA512_DIGEST_LENGTH); | be64enc_vect(digest, ctx->state, SHA512_DIGEST_LENGTH); | ||||
/* Clear the context state */ | /* Clear the context state */ | ||||
memset((void *)ctx, 0, sizeof(*ctx)); | memset((void *)ctx, 0, sizeof(*ctx)); | ||||
} | } | ||||
/*** SHA-512t: *********************************************************/ | |||||
/* | |||||
* the SHA512t transforms are identical to SHA512 so are skipped | |||||
cem: what's "so are skipped" mean? | |||||
allanjudeAuthorUnsubmitted Done Inline ActionsI didn't define the _transform function because it just uses the regular SHA512 one. I'll reword this allanjude: I didn't define the _transform function because it just uses the regular SHA512 one. I'll… | |||||
Done Inline Actionsstill needs rewording cem: still needs rewording | |||||
*/ | |||||
void | |||||
SHA512_224_Init(SHA512_CTX * ctx) | |||||
{ | |||||
/* Zero bits processed so far */ | |||||
ctx->count[0] = ctx->count[1] = 0; | |||||
/* Magic initialization constants */ | |||||
ctx->state[0] = 0x8c3d37c819544da2ULL; | |||||
ctx->state[1] = 0x73e1996689dcd4d6ULL; | |||||
ctx->state[2] = 0x1dfab7ae32ff9c82ULL; | |||||
ctx->state[3] = 0x679dd514582f9fcfULL; | |||||
ctx->state[4] = 0x0f6d2b697bd44da8ULL; | |||||
ctx->state[5] = 0x77e36f7304c48942ULL; | |||||
ctx->state[6] = 0x3f9d85a86a1d36c8ULL; | |||||
ctx->state[7] = 0x1112e6ad91d692a1ULL; | |||||
} | |||||
void | |||||
SHA512_224_Update(SHA512_CTX * ctx, const void *in, size_t len) | |||||
{ | |||||
SHA512_Update(ctx, in, len); | |||||
} | |||||
cemUnsubmitted Done Inline ActionsIt seems like these aren't really necessary. I'd suggest removing them and adding a comment where they were in the header to use the SHA512_Update() routine. cem: It seems like these aren't really necessary. I'd suggest removing them and adding a comment… | |||||
allanjudeAuthorUnsubmitted Done Inline ActionsUserland applications that implement this algo expect this symbol to exist in libmd. allanjude: Userland applications that implement this algo expect this symbol to exist in libmd. | |||||
cemUnsubmitted Not Done Inline ActionsIt seems like userland-only routines and declarations should live in userland, like the _File/_Data routines. But whatever. cem: It seems like userland-only routines and declarations should live in userland, like the… | |||||
void | |||||
SHA512_224_Final(unsigned char digest[SHA512_224_DIGEST_LENGTH], SHA512_CTX * ctx) | |||||
cemUnsubmitted Done Inline ActionsUse digest[static ...] here :). cem: Use `digest[static ...]` here :). | |||||
allanjudeAuthorUnsubmitted Done Inline Actionsok allanjude: ok | |||||
{ | |||||
/* Add padding */ | |||||
SHA512_Pad(ctx); | |||||
/* Write the hash */ | |||||
be64enc_vect(digest, ctx->state, SHA512_224_DIGEST_LENGTH); | |||||
/* Clear the context state */ | |||||
memset((void *)ctx, 0, sizeof(*ctx)); | |||||
cemUnsubmitted Done Inline Actionsdon't need to cast here. cem: don't need to cast here. | |||||
allanjudeAuthorUnsubmitted Done Inline Actionsright allanjude: right | |||||
Done Inline Actionscast still present cem: cast still present | |||||
} | |||||
void | |||||
SHA512_256_Init(SHA512_CTX * ctx) | |||||
{ | |||||
/* Zero bits processed so far */ | |||||
ctx->count[0] = ctx->count[1] = 0; | |||||
/* Magic initialization constants */ | |||||
ctx->state[0] = 0x22312194fc2bf72cULL; | |||||
ctx->state[1] = 0x9f555fa3c84c64c2ULL; | |||||
ctx->state[2] = 0x2393b86b6f53b151ULL; | |||||
ctx->state[3] = 0x963877195940eabdULL; | |||||
ctx->state[4] = 0x96283ee2a88effe3ULL; | |||||
ctx->state[5] = 0xbe5e1e2553863992ULL; | |||||
ctx->state[6] = 0x2b0199fc2c85b8aaULL; | |||||
ctx->state[7] = 0x0eb72ddc81c52ca2ULL; | |||||
} | |||||
void | |||||
SHA512_256_Update(SHA512_CTX * ctx, const void *in, size_t len) | |||||
{ | |||||
SHA512_Update(ctx, in, len); | |||||
} | |||||
cemUnsubmitted Done Inline ActionsSame quibble here. cem: Same quibble here. | |||||
void | |||||
SHA512_256_Final(unsigned char digest[SHA512_256_DIGEST_LENGTH], SHA512_CTX * ctx) | |||||
cemUnsubmitted Done Inline ActionsUse digest[static DIGEST_LEN] :) cem: Use `digest[static DIGEST_LEN]` :) | |||||
{ | |||||
/* Add padding */ | |||||
SHA512_Pad(ctx); | |||||
/* Write the hash */ | |||||
be64enc_vect(digest, ctx->state, SHA512_256_DIGEST_LENGTH); | |||||
/* Clear the context state */ | |||||
memset((void *)ctx, 0, sizeof(*ctx)); | |||||
cemUnsubmitted Done Inline Actionssame as above cem: same as above | |||||
Done Inline ActionsThis extra cast got missed :) cem: This extra cast got missed :) | |||||
} | |||||
/*** SHA-384: *********************************************************/ | /*** SHA-384: *********************************************************/ | ||||
/* | /* | ||||
* the SHA384 and SHA512 transforms are identical, so SHA384 is skipped | * the SHA384 and SHA512 transforms are identical, so SHA384 is skipped | ||||
*/ | */ | ||||
/* SHA-384 initialization. Begins a SHA-384 operation. */ | /* SHA-384 initialization. Begins a SHA-384 operation. */ | ||||
void | void | ||||
SHA384_Init(SHA384_CTX * ctx) | SHA384_Init(SHA384_CTX * ctx) | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
#undef SHA512_Init | #undef SHA512_Init | ||||
__weak_reference(_libmd_SHA512_Init, SHA512_Init); | __weak_reference(_libmd_SHA512_Init, SHA512_Init); | ||||
#undef SHA512_Update | #undef SHA512_Update | ||||
__weak_reference(_libmd_SHA512_Update, SHA512_Update); | __weak_reference(_libmd_SHA512_Update, SHA512_Update); | ||||
#undef SHA512_Final | #undef SHA512_Final | ||||
__weak_reference(_libmd_SHA512_Final, SHA512_Final); | __weak_reference(_libmd_SHA512_Final, SHA512_Final); | ||||
#undef SHA512_Transform | #undef SHA512_Transform | ||||
__weak_reference(_libmd_SHA512_Transform, SHA512_Transform); | __weak_reference(_libmd_SHA512_Transform, SHA512_Transform); | ||||
#undef SHA512_224_Init | |||||
__weak_reference(_libmd_SHA512_224_Init, SHA512_224_Init); | |||||
#undef SHA512_224_Update | |||||
__weak_reference(_libmd_SHA512_224_Update, SHA512_224_Update); | |||||
#undef SHA512_224_Final | |||||
__weak_reference(_libmd_SHA512_224_Final, SHA512_224_Final); | |||||
#undef SHA512_256_Init | |||||
__weak_reference(_libmd_SHA512_256_Init, SHA512_256_Init); | |||||
#undef SHA512_256_Update | |||||
__weak_reference(_libmd_SHA512_256_Update, SHA512_256_Update); | |||||
#undef SHA512_256_Final | |||||
__weak_reference(_libmd_SHA512_256_Final, SHA512_256_Final); | |||||
#undef SHA384_Init | #undef SHA384_Init | ||||
__weak_reference(_libmd_SHA384_Init, SHA384_Init); | __weak_reference(_libmd_SHA384_Init, SHA384_Init); | ||||
#undef SHA384_Update | #undef SHA384_Update | ||||
__weak_reference(_libmd_SHA384_Update, SHA384_Update); | __weak_reference(_libmd_SHA384_Update, SHA384_Update); | ||||
#undef SHA384_Final | #undef SHA384_Final | ||||
__weak_reference(_libmd_SHA384_Final, SHA384_Final); | __weak_reference(_libmd_SHA384_Final, SHA384_Final); | ||||
#endif | #endif |
what's "so are skipped" mean?