Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions demos/latex-tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ static int print_hash_descriptors(void)
HASH_DESC(sha1_portable_desc),
#ifdef LTC_SHA1_X86
HASH_DESC(sha1_x86_desc),
#endif
HASH_DESC(sha512_portable_desc),
#ifdef LTC_SHA512_X86
HASH_DESC(sha512_x86_desc),
#endif
HASH_DESC(sha384_portable_desc),
#ifdef LTC_SHA384_X86
HASH_DESC(sha384_x86_desc),
#endif
HASH_DESC(sha512_224_portable_desc),
#ifdef LTC_SHA512_224_X86
HASH_DESC(sha512_224_x86_desc),
#endif
HASH_DESC(sha512_256_portable_desc),
#ifdef LTC_SHA512_256_X86
HASH_DESC(sha512_256_x86_desc),
#endif
};
struct desc descs[TAB_SIZE + 1] = {0};
Expand Down
8 changes: 8 additions & 0 deletions doc/crypt.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3128,6 +3128,14 @@ \subsection{Hash Registration}
\hline SHA224 & \code{sha224\_x86\_desc} & 28 & 10 \\
\hline SHA1 & \code{sha1\_portable\_desc} & 20 & 2 \\
\hline SHA1 & \code{sha1\_x86\_desc} & 20 & 2 \\
\hline SHA512 & \code{sha512\_portable\_desc} & 64 & 5 \\
\hline SHA512 & \code{sha512\_x86\_desc} & 64 & 5 \\
\hline SHA384 & \code{sha384\_portable\_desc} & 48 & 4 \\
\hline SHA384 & \code{sha384\_x86\_desc} & 48 & 4 \\
\hline SHA512-224 & \code{sha512\_224\_portable\_desc} & 28 & 15 \\
\hline SHA512-224 & \code{sha512\_224\_x86\_desc} & 28 & 15 \\
\hline SHA512-256 & \code{sha512\_256\_portable\_desc} & 32 & 16 \\
\hline SHA512-256 & \code{sha512\_256\_x86\_desc} & 32 & 16 \\
\hline
\end{tabular}
\end{center}
Expand Down
32 changes: 32 additions & 0 deletions libtomcrypt_VS2008.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,14 @@
RelativePath="src\hashes\sha2\sha384.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha384_desc.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha384_x86.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha512.c"
>
Expand All @@ -946,10 +954,34 @@
RelativePath="src\hashes\sha2\sha512_224.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha512_224_desc.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha512_224_x86.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha512_256.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha512_256_desc.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha512_256_x86.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha512_desc.c"
>
</File>
<File
RelativePath="src\hashes\sha2\sha512_x86.c"
>
</File>
</Filter>
<Filter
Name="whirl"
Expand Down
9 changes: 6 additions & 3 deletions makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ src/hashes/helper/hash_memory_multi.o src/hashes/md2.o src/hashes/md4.o src/hash
src/hashes/rmd128.o src/hashes/rmd160.o src/hashes/rmd256.o src/hashes/rmd320.o src/hashes/sha1.o \
src/hashes/sha1_desc.o src/hashes/sha1_x86.o src/hashes/sha2/sha224.o src/hashes/sha2/sha224_desc.o \
src/hashes/sha2/sha224_x86.o src/hashes/sha2/sha256.o src/hashes/sha2/sha256_desc.o \
src/hashes/sha2/sha256_x86.o src/hashes/sha2/sha384.o src/hashes/sha2/sha512.o \
src/hashes/sha2/sha512_224.o src/hashes/sha2/sha512_256.o src/hashes/sha3.o src/hashes/sha3_test.o \
src/hashes/sm3.o src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/blake2/blake2bmac.o \
src/hashes/sha2/sha256_x86.o src/hashes/sha2/sha384.o src/hashes/sha2/sha384_desc.o \
src/hashes/sha2/sha384_x86.o src/hashes/sha2/sha512.o src/hashes/sha2/sha512_224.o \
src/hashes/sha2/sha512_224_desc.o src/hashes/sha2/sha512_224_x86.o src/hashes/sha2/sha512_256.o \
src/hashes/sha2/sha512_256_desc.o src/hashes/sha2/sha512_256_x86.o src/hashes/sha2/sha512_desc.o \
src/hashes/sha2/sha512_x86.o src/hashes/sha3.o src/hashes/sha3_test.o src/hashes/sm3.o \
src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/blake2/blake2bmac.o \
src/mac/blake2/blake2bmac_file.o src/mac/blake2/blake2bmac_memory.o \
src/mac/blake2/blake2bmac_memory_multi.o src/mac/blake2/blake2bmac_test.o src/mac/blake2/blake2smac.o \
src/mac/blake2/blake2smac_file.o src/mac/blake2/blake2smac_memory.o \
Expand Down
9 changes: 6 additions & 3 deletions makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ src/hashes/helper/hash_memory_multi.obj src/hashes/md2.obj src/hashes/md4.obj sr
src/hashes/rmd128.obj src/hashes/rmd160.obj src/hashes/rmd256.obj src/hashes/rmd320.obj src/hashes/sha1.obj \
src/hashes/sha1_desc.obj src/hashes/sha1_x86.obj src/hashes/sha2/sha224.obj src/hashes/sha2/sha224_desc.obj \
src/hashes/sha2/sha224_x86.obj src/hashes/sha2/sha256.obj src/hashes/sha2/sha256_desc.obj \
src/hashes/sha2/sha256_x86.obj src/hashes/sha2/sha384.obj src/hashes/sha2/sha512.obj \
src/hashes/sha2/sha512_224.obj src/hashes/sha2/sha512_256.obj src/hashes/sha3.obj src/hashes/sha3_test.obj \
src/hashes/sm3.obj src/hashes/tiger.obj src/hashes/whirl/whirl.obj src/mac/blake2/blake2bmac.obj \
src/hashes/sha2/sha256_x86.obj src/hashes/sha2/sha384.obj src/hashes/sha2/sha384_desc.obj \
src/hashes/sha2/sha384_x86.obj src/hashes/sha2/sha512.obj src/hashes/sha2/sha512_224.obj \
src/hashes/sha2/sha512_224_desc.obj src/hashes/sha2/sha512_224_x86.obj src/hashes/sha2/sha512_256.obj \
src/hashes/sha2/sha512_256_desc.obj src/hashes/sha2/sha512_256_x86.obj src/hashes/sha2/sha512_desc.obj \
src/hashes/sha2/sha512_x86.obj src/hashes/sha3.obj src/hashes/sha3_test.obj src/hashes/sm3.obj \
src/hashes/tiger.obj src/hashes/whirl/whirl.obj src/mac/blake2/blake2bmac.obj \
src/mac/blake2/blake2bmac_file.obj src/mac/blake2/blake2bmac_memory.obj \
src/mac/blake2/blake2bmac_memory_multi.obj src/mac/blake2/blake2bmac_test.obj src/mac/blake2/blake2smac.obj \
src/mac/blake2/blake2smac_file.obj src/mac/blake2/blake2smac_memory.obj \
Expand Down
9 changes: 6 additions & 3 deletions makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ src/hashes/helper/hash_memory_multi.o src/hashes/md2.o src/hashes/md4.o src/hash
src/hashes/rmd128.o src/hashes/rmd160.o src/hashes/rmd256.o src/hashes/rmd320.o src/hashes/sha1.o \
src/hashes/sha1_desc.o src/hashes/sha1_x86.o src/hashes/sha2/sha224.o src/hashes/sha2/sha224_desc.o \
src/hashes/sha2/sha224_x86.o src/hashes/sha2/sha256.o src/hashes/sha2/sha256_desc.o \
src/hashes/sha2/sha256_x86.o src/hashes/sha2/sha384.o src/hashes/sha2/sha512.o \
src/hashes/sha2/sha512_224.o src/hashes/sha2/sha512_256.o src/hashes/sha3.o src/hashes/sha3_test.o \
src/hashes/sm3.o src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/blake2/blake2bmac.o \
src/hashes/sha2/sha256_x86.o src/hashes/sha2/sha384.o src/hashes/sha2/sha384_desc.o \
src/hashes/sha2/sha384_x86.o src/hashes/sha2/sha512.o src/hashes/sha2/sha512_224.o \
src/hashes/sha2/sha512_224_desc.o src/hashes/sha2/sha512_224_x86.o src/hashes/sha2/sha512_256.o \
src/hashes/sha2/sha512_256_desc.o src/hashes/sha2/sha512_256_x86.o src/hashes/sha2/sha512_desc.o \
src/hashes/sha2/sha512_x86.o src/hashes/sha3.o src/hashes/sha3_test.o src/hashes/sm3.o \
src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/blake2/blake2bmac.o \
src/mac/blake2/blake2bmac_file.o src/mac/blake2/blake2bmac_memory.o \
src/mac/blake2/blake2bmac_memory_multi.o src/mac/blake2/blake2bmac_test.o src/mac/blake2/blake2smac.o \
src/mac/blake2/blake2smac_file.o src/mac/blake2/blake2smac_memory.o \
Expand Down
9 changes: 6 additions & 3 deletions makefile_include.mk
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,12 @@ src/hashes/helper/hash_memory_multi.o src/hashes/md2.o src/hashes/md4.o src/hash
src/hashes/rmd128.o src/hashes/rmd160.o src/hashes/rmd256.o src/hashes/rmd320.o src/hashes/sha1.o \
src/hashes/sha1_desc.o src/hashes/sha1_x86.o src/hashes/sha2/sha224.o src/hashes/sha2/sha224_desc.o \
src/hashes/sha2/sha224_x86.o src/hashes/sha2/sha256.o src/hashes/sha2/sha256_desc.o \
src/hashes/sha2/sha256_x86.o src/hashes/sha2/sha384.o src/hashes/sha2/sha512.o \
src/hashes/sha2/sha512_224.o src/hashes/sha2/sha512_256.o src/hashes/sha3.o src/hashes/sha3_test.o \
src/hashes/sm3.o src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/blake2/blake2bmac.o \
src/hashes/sha2/sha256_x86.o src/hashes/sha2/sha384.o src/hashes/sha2/sha384_desc.o \
src/hashes/sha2/sha384_x86.o src/hashes/sha2/sha512.o src/hashes/sha2/sha512_224.o \
src/hashes/sha2/sha512_224_desc.o src/hashes/sha2/sha512_224_x86.o src/hashes/sha2/sha512_256.o \
src/hashes/sha2/sha512_256_desc.o src/hashes/sha2/sha512_256_x86.o src/hashes/sha2/sha512_desc.o \
src/hashes/sha2/sha512_x86.o src/hashes/sha3.o src/hashes/sha3_test.o src/hashes/sm3.o \
src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/blake2/blake2bmac.o \
src/mac/blake2/blake2bmac_file.o src/mac/blake2/blake2bmac_memory.o \
src/mac/blake2/blake2bmac_memory_multi.o src/mac/blake2/blake2bmac_test.o src/mac/blake2/blake2smac.o \
src/mac/blake2/blake2smac_file.o src/mac/blake2/blake2smac_memory.o \
Expand Down
8 changes: 8 additions & 0 deletions sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ src/hashes/sha2/sha256.c
src/hashes/sha2/sha256_desc.c
src/hashes/sha2/sha256_x86.c
src/hashes/sha2/sha384.c
src/hashes/sha2/sha384_desc.c
src/hashes/sha2/sha384_x86.c
src/hashes/sha2/sha512.c
src/hashes/sha2/sha512_224.c
src/hashes/sha2/sha512_224_desc.c
src/hashes/sha2/sha512_224_x86.c
src/hashes/sha2/sha512_256.c
src/hashes/sha2/sha512_256_desc.c
src/hashes/sha2/sha512_256_x86.c
src/hashes/sha2/sha512_desc.c
src/hashes/sha2/sha512_x86.c
src/hashes/sha3.c
src/hashes/sha3_test.c
src/hashes/sm3.c
Expand Down
83 changes: 10 additions & 73 deletions src/hashes/sha2/sha384.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#if defined(LTC_SHA384) && defined(LTC_SHA512)

const struct ltc_hash_descriptor sha384_desc =
const struct ltc_hash_descriptor sha384_portable_desc =
{
"sha384",
4,
Expand All @@ -21,104 +21,41 @@ const struct ltc_hash_descriptor sha384_desc =
9,

&sha384_init,
&sha512_process,
&sha384_done,
&sha384_test,
&sha384_c_process,
&sha384_c_done,
&sha384_c_test,
NULL
};

/**
Initialize the hash state
@param md The hash state you wish to initialize
@return CRYPT_OK if successful
*/
int sha384_init(hash_state * md)
{
LTC_ARGCHK(md != NULL);

md->sha512.curlen = 0;
md->sha512.length = 0;
md->sha512.state[0] = CONST64(0xcbbb9d5dc1059ed8);
md->sha512.state[1] = CONST64(0x629a292a367cd507);
md->sha512.state[2] = CONST64(0x9159015a3070dd17);
md->sha512.state[3] = CONST64(0x152fecd8f70e5939);
md->sha512.state[4] = CONST64(0x67332667ffc00b31);
md->sha512.state[5] = CONST64(0x8eb44a8768581511);
md->sha512.state[6] = CONST64(0xdb0c2e0d64f98fa7);
md->sha512.state[7] = CONST64(0x47b5481dbefa4fa4);
return CRYPT_OK;
}

/**
Terminate the hash to get the digest
@param md The hash state
@param out [out] The destination of the hash (48 bytes)
@return CRYPT_OK if successful
*/
int sha384_done(hash_state * md, unsigned char *out)
int sha384_c_done(hash_state * md, unsigned char *out)
{
unsigned char buf[64];
int err;

LTC_ARGCHK(md != NULL);
LTC_ARGCHK(out != NULL);

if (md->sha512.curlen >= sizeof(md->sha512.buf)) {
return CRYPT_INVALID_ARG;
}

sha512_done(md, buf);
err = sha512_c_done(md, buf);
XMEMCPY(out, buf, 48);
#ifdef LTC_CLEAN_STACK
zeromem(buf, sizeof(buf));
#endif
return CRYPT_OK;
return err;
}

/**
Self-test the hash
@return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
*/
int sha384_test(void)
int sha384_c_test(void)
{
#ifndef LTC_TEST
return CRYPT_NOP;
#else
static const struct {
const char *msg;
unsigned char hash[48];
} tests[] = {
{ "abc",
{ 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7 }
},
{ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
{ 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39 }
},
};

int i;
unsigned char tmp[48];
hash_state md;

for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
sha384_init(&md);
sha384_process(&md, (unsigned char*)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
sha384_done(&md, tmp);
if (ltc_compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "SHA384", i)) {
return CRYPT_FAIL_TESTVECTOR;
}
}
return CRYPT_OK;
#endif
return sha384_test_desc(&sha384_portable_desc, "SHA384 portable");
}

#endif /* defined(LTC_SHA384) && defined(LTC_SHA512) */
Loading
Loading