[libfko] remove unused digest *_End(), *_Data(), and *_hex() functions in favor of better test coverage (always can be reinstantiated if needed)

This commit is contained in:
Michael Rash 2014-04-04 22:54:38 -04:00
parent f9885d0657
commit 0b6a407392
4 changed files with 0 additions and 209 deletions

View File

@ -29,36 +29,6 @@
#include "digest.h"
#include "base64.h"
/* Convert a raw digest into its hex string representation.
*/
static void
digest_to_hex(char *out, size_t size_out, const unsigned char *in, const size_t size_in)
{
size_t i;
/* Assume the output buffer must be a NULL terminated string */
memset(out, 0, size_out);
size_out -= 1;
/* The hex string representation must be long enough */
if (size_out >= (size_in * 2))
{
/* For each byte... */
for(i=0; i<size_in; i++)
{
/* Append the hex string to the output buffer */
snprintf(out, 2, "%02x", in[i]);
/* Moved the pointer on the output buffer to the next place */
out += 2;
}
}
/* Not enough space in the output buffer - Should not occur */
else;
}
/* Compute MD5 hash on in and store result in out.
*/
void
@ -71,17 +41,6 @@ md5(unsigned char *out, unsigned char *in, size_t size)
MD5Final(out, &ctx);
}
/* Compute MD5 hash on in and store the hex string result in out.
*/
void
md5_hex(char *out, size_t size_out, unsigned char *in, size_t size_in)
{
uint8_t md[MD5_DIGEST_LEN];
md5(md, in, size_in);
digest_to_hex(out, size_out, md, MD5_DIGEST_LEN);
}
/* Compute MD5 hash on in and store the base64 string result in out.
*/
void
@ -107,17 +66,6 @@ sha1(unsigned char *out, unsigned char *in, size_t size)
sha1_final(out, &sha1_info);
}
/* Compute SHA1 hash on in and store the hex string result in out.
*/
void
sha1_hex(char *out, size_t size_out, unsigned char *in, size_t size_in)
{
uint8_t md[SHA1_DIGEST_LEN];
sha1(md, in, size_in);
digest_to_hex(out, size_out, md, SHA1_DIGEST_LEN);
}
/* Compute SHA1 hash on in and store the base64 string result in out.
*/
void
@ -143,17 +91,6 @@ sha256(unsigned char *out, unsigned char *in, size_t size)
SHA256_Final(out, &sha256_ctx);
}
/* Compute SHA256 hash on in and store the hex string result in out.
*/
void
sha256_hex(char *out, size_t size_out, unsigned char *in, size_t size_in)
{
uint8_t md[SHA256_DIGEST_LEN];
sha256(md, in, size_in);
digest_to_hex(out, size_out, md, SHA256_DIGEST_LEN);
}
/* Compute SHA256 hash on in and store the base64 string result in out.
*/
void
@ -179,17 +116,6 @@ sha384(unsigned char *out, unsigned char *in, size_t size)
SHA384_Final(out, &sha384_ctx);
}
/* Compute SHA384 hash on in and store the hex string result in out.
*/
void
sha384_hex(char *out, size_t size_out, unsigned char *in, size_t size_in)
{
uint8_t md[SHA384_DIGEST_LEN];
sha384(md, in, size_in);
digest_to_hex(out, size_out, md, SHA384_DIGEST_LEN);
}
/* Compute SHA384 hash on in and store the base64 string result in out.
*/
void
@ -215,17 +141,6 @@ sha512(unsigned char *out, unsigned char *in, size_t size)
SHA512_Final(out, &sha512_ctx);
}
/* Compute SHA512 hash on in and store the hex string result in out.
*/
void
sha512_hex(char *out, size_t size_out, unsigned char *in, size_t size_in)
{
uint8_t md[SHA512_DIGEST_LEN];
sha512(md, in, size_in);
digest_to_hex(out, size_out, md, SHA512_DIGEST_LEN);
}
/* Compute SHA512 hash on in and store the base64 string result in out.
*/
void

View File

@ -40,19 +40,14 @@
#define MD_HEX_SIZE(x) x * 2
void md5(unsigned char* out, unsigned char* in, size_t size);
void md5_hex(char* out, size_t size_out, unsigned char* in, size_t size);
void md5_base64(char* out, unsigned char* in, size_t size);
void sha1(unsigned char* out, unsigned char* in, size_t size);
void sha1_hex(char* out, size_t size_out, unsigned char* in, size_t size);
void sha1_base64(char* out, unsigned char* in, size_t size);
void sha256(unsigned char* out, unsigned char* in, size_t size);
void sha256_hex(char* out, size_t size_out, unsigned char* in, size_t size);
void sha256_base64(char* out, unsigned char* in, size_t size);
void sha384(unsigned char* out, unsigned char* in, size_t size);
void sha384_hex(char* out, size_t size_out, unsigned char* in, size_t size);
void sha384_base64(char* out, unsigned char* in, size_t size);
void sha512(unsigned char* out, unsigned char* in, size_t size);
void sha512_hex(char* out, size_t size_out, unsigned char* in, size_t size);
void sha512_base64(char* out, unsigned char* in, size_t size);
#endif /* DIGEST_H */

View File

@ -345,12 +345,6 @@ const static sha2_word64 sha512_initial_hash_value[8] = {
0x5be0cd19137e2179ULL
};
/*
* Constant used by SHA256/384/512_End() functions for converting the
* digest to a readable hexadecimal character string:
*/
static const char *sha2_hex_digits = "0123456789abcdef";
/*** SHA-256: *********************************************************/
void SHA256_Init(SHA256_CTX* context) {
@ -648,38 +642,6 @@ void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
usedspace = 0;
}
char *SHA256_End(SHA256_CTX* context, char buffer[]) {
sha2_byte digest[SHA256_DIGEST_LEN], *d = digest;
int i;
/* Sanity check: */
assert(context != (SHA256_CTX*)0);
if (buffer != (char*)0) {
SHA256_Final(digest, context);
for (i = 0; i < SHA256_DIGEST_LEN; i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
*buffer++ = sha2_hex_digits[*d & 0x0f];
d++;
}
*buffer = (char)0;
} else {
MEMSET_BZERO(context, sizeof(*context));
}
MEMSET_BZERO(digest, SHA256_DIGEST_LEN);
return buffer;
}
char* SHA256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_STR_LEN]) {
SHA256_CTX context;
SHA256_Init(&context);
SHA256_Update(&context, data, len);
return SHA256_End(&context, digest);
}
/*** SHA-512: *********************************************************/
void SHA512_Init(SHA512_CTX* context) {
if (context == (SHA512_CTX*)0) {
@ -977,37 +939,6 @@ void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
MEMSET_BZERO(context, sizeof(*context));
}
char *SHA512_End(SHA512_CTX* context, char buffer[]) {
sha2_byte digest[SHA512_DIGEST_LEN], *d = digest;
int i;
/* Sanity check: */
assert(context != (SHA512_CTX*)0);
if (buffer != (char*)0) {
SHA512_Final(digest, context);
for (i = 0; i < SHA512_DIGEST_LEN; i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
*buffer++ = sha2_hex_digits[*d & 0x0f];
d++;
}
*buffer = (char)0;
} else {
MEMSET_BZERO(context, sizeof(*context));
}
MEMSET_BZERO(digest, SHA512_DIGEST_LEN);
return buffer;
}
char* SHA512_Data(const sha2_byte* data, size_t len, char digest[SHA512_DIGEST_STR_LEN]) {
SHA512_CTX context;
SHA512_Init(&context);
SHA512_Update(&context, data, len);
return SHA512_End(&context, digest);
}
/*** SHA-384: *********************************************************/
void SHA384_Init(SHA384_CTX* context) {
@ -1051,35 +982,3 @@ void SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
/* Zero out state data */
MEMSET_BZERO(context, sizeof(*context));
}
char *SHA384_End(SHA384_CTX* context, char buffer[]) {
sha2_byte digest[SHA384_DIGEST_LEN], *d = digest;
int i;
/* Sanity check: */
assert(context != (SHA384_CTX*)0);
if (buffer != (char*)0) {
SHA384_Final(digest, context);
for (i = 0; i < SHA384_DIGEST_LEN; i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
*buffer++ = sha2_hex_digits[*d & 0x0f];
d++;
}
*buffer = (char)0;
} else {
MEMSET_BZERO(context, sizeof(*context));
}
MEMSET_BZERO(digest, SHA384_DIGEST_LEN);
return buffer;
}
char* SHA384_Data(const sha2_byte* data, size_t len, char digest[SHA384_DIGEST_STR_LEN]) {
SHA384_CTX context;
SHA384_Init(&context);
SHA384_Update(&context, data, len);
return SHA384_End(&context, digest);
}

View File

@ -147,40 +147,28 @@ typedef SHA512_CTX SHA384_CTX;
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
void SHA256_Final(uint8_t[SHA256_DIGEST_LEN], SHA256_CTX*);
char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STR_LEN]);
char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STR_LEN]);
void SHA384_Init(SHA384_CTX*);
void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
void SHA384_Final(uint8_t[SHA384_DIGEST_LEN], SHA384_CTX*);
char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STR_LEN]);
char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STR_LEN]);
void SHA512_Init(SHA512_CTX*);
void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
void SHA512_Final(uint8_t[SHA512_DIGEST_LEN], SHA512_CTX*);
char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STR_LEN]);
char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STR_LEN]);
#else /* SHA2_USE_INTTYPES_H */
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX*, const u_int8_t*, size_t);
void SHA256_Final(u_int8_t[SHA256_DIGEST_LEN], SHA256_CTX*);
char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STR_LEN]);
char* SHA256_Data(const u_int8_t*, size_t, char[SHA256_DIGEST_STR_LEN]);
void SHA384_Init(SHA384_CTX*);
void SHA384_Update(SHA384_CTX*, const u_int8_t*, size_t);
void SHA384_Final(u_int8_t[SHA384_DIGEST_LEN], SHA384_CTX*);
char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STR_LEN]);
char* SHA384_Data(const u_int8_t*, size_t, char[SHA384_DIGEST_STR_LEN]);
void SHA512_Init(SHA512_CTX*);
void SHA512_Update(SHA512_CTX*, const u_int8_t*, size_t);
void SHA512_Final(u_int8_t[SHA512_DIGEST_LEN], SHA512_CTX*);
char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STR_LEN]);
char* SHA512_Data(const u_int8_t*, size_t, char[SHA512_DIGEST_STR_LEN]);
#endif /* SHA2_USE_INTTYPES_H */
@ -189,20 +177,14 @@ char* SHA512_Data(const u_int8_t*, size_t, char[SHA512_DIGEST_STR_LEN]);
void SHA256_Init();
void SHA256_Update();
void SHA256_Final();
char* SHA256_End();
char* SHA256_Data();
void SHA384_Init();
void SHA384_Update();
void SHA384_Final();
char* SHA384_End();
char* SHA384_Data();
void SHA512_Init();
void SHA512_Update();
void SHA512_Final();
char* SHA512_End();
char* SHA512_Data();
#endif /* NOPROTO */