Skip to content

Commit 63bf8b1

Browse files
committed
Add KangarooTwelve XOF functions.
KangarooTwelve 128bits and KangarooTwelve 256 bits. https://keccak.team/files/TurboSHAKE.pdf https://www.rfc-editor.org/rfc/rfc9861.txt https://datatracker.ietf.org/doc/html/rfc9861
1 parent 3ef136e commit 63bf8b1

File tree

7 files changed

+320
-1
lines changed

7 files changed

+320
-1
lines changed

doc/crypt.tex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,6 +3143,21 @@ \subsection{TurboSHAKE}
31433143
The init function \code{turbo\_shake\_init()} is implemented as a macro which calls \code{sha3\_shake\_init()}.
31443144

31453145

3146+
\subsection{KangarooTwelve}
3147+
Another variation of SHA3 SHAKE is KangarooTwelve, which has been specified in \href{https://datatracker.ietf.org/doc/rfc9861/}{\texttt{RFC 9861}}.
3148+
3149+
The API works equivalent to the one of SHA3 SHAKE, where the APIs only have a different name. Additionally, KangarooTwelve supports customization. You can append any or none customization bytes after all input bytes and before squeezing any output digest bytes.
3150+
3151+
\begin{small}
3152+
\begin{verbatim}
3153+
int kt_init(hash_state *md, int num);
3154+
int kt_process(hash_state *md, const unsigned char *in, unsigned long inlen);
3155+
int kt_customization(hash_state *md, const unsigned char *in, unsigned long inlen);
3156+
int kt_done(hash_state *md, unsigned char *out, unsigned long outlen);
3157+
\end{verbatim}
3158+
\end{small}
3159+
3160+
31463161
\mysection{Extended Tiger API}
31473162

31483163
The Tiger and Tiger2 hash algorithms \url{http://www.cs.technion.ac.il/~biham/Reports/Tiger/} specify the possibility to run the algorithm with

src/hashes/sha3.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,152 @@ int sha3_shake_memory(int num, const unsigned char *in, unsigned long inlen, uns
416416
}
417417
#endif
418418

419+
#ifdef LTC_KT
420+
421+
static const unsigned char kt_filler[] = { 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
422+
423+
int kt_init(hash_state *md, int num)
424+
{
425+
int err;
426+
427+
LTC_ARGCHK(md != NULL);
428+
LTC_ARGCHK(num == 128 || num == 256);
429+
430+
if ((err = sha3_shake_init((hash_state*)&md->kt.outer, num)) != CRYPT_OK) return err;
431+
if ((err = sha3_shake_init((hash_state*)&md->kt.inner, num)) != CRYPT_OK) return err;
432+
md->kt.blocks_count = 0;
433+
md->kt.customization_len = 0;
434+
md->kt.remaining = 8 * 1024;
435+
md->kt.phase = 0;
436+
md->kt.finished = 0;
437+
return CRYPT_OK;
438+
}
439+
440+
static LTC_INLINE int s_kt_process(hash_state *md, const unsigned char *in, unsigned long inlen)
441+
{
442+
unsigned long rem;
443+
unsigned long amount;
444+
int err;
445+
int variant;
446+
int digest_len;
447+
unsigned char digest_buf[64];
448+
449+
LTC_ARGCHK(md != NULL);
450+
LTC_ARGCHK(in != NULL || inlen == 0);
451+
452+
if (md->kt.phase == 0)
453+
{
454+
rem = md->kt.remaining;
455+
amount = rem < inlen ? rem : inlen;
456+
md->kt.remaining -= amount;
457+
if ((err = turbo_shake_process((hash_state*)&md->kt.outer, in, amount)) != CRYPT_OK) return err;
458+
in += amount;
459+
inlen -= amount;
460+
if (md->kt.remaining == 0 && inlen != 0)
461+
{
462+
md->kt.remaining = 8 * 1024;
463+
md->kt.phase = 1;
464+
md->kt.blocks_count += 1;
465+
if ((err = turbo_shake_process((hash_state*)&md->kt.outer, &kt_filler[0], sizeof(kt_filler))) != CRYPT_OK) return err;
466+
}
467+
}
468+
if (md->kt.phase == 1)
469+
{
470+
do
471+
{
472+
rem = md->kt.remaining;
473+
amount = rem < inlen ? rem : inlen;
474+
md->kt.remaining -= amount;
475+
if ((err = turbo_shake_process((hash_state*)&md->kt.inner, in, amount)) != CRYPT_OK) return err;
476+
in += amount;
477+
inlen -= amount;
478+
if (md->kt.remaining == 0 && inlen != 0)
479+
{
480+
md->kt.remaining = 8 * 1024;
481+
md->kt.blocks_count += 1;
482+
assert(md->kt.outer.capacity_words == 4 || md->kt.outer.capacity_words == 8);
483+
variant = md->kt.outer.capacity_words == 4 ? 128 : 256;
484+
digest_len = variant == 128 ? 32 : 64;
485+
if ((err = s_sha3_shake_done((hash_state*)&md->kt.inner, &digest_buf[0], digest_len, 0x0b, s_keccak_turbo_f)) != CRYPT_OK) return err;
486+
if ((err = turbo_shake_init((hash_state*)&md->kt.inner, variant)) != CRYPT_OK) return err;
487+
if ((err = turbo_shake_process((hash_state*)&md->kt.outer, &digest_buf[0], digest_len)) != CRYPT_OK) return err;
488+
}
489+
} while (inlen != 0);
490+
}
491+
return CRYPT_OK;
492+
}
493+
494+
int kt_process(hash_state *md, const unsigned char *in, unsigned long inlen)
495+
{
496+
LTC_ARGCHK(md != NULL);
497+
LTC_ARGCHK(in != NULL || inlen == 0);
498+
LTC_ARGCHK(md->kt.customization_len == 0);
499+
LTC_ARGCHK(md->kt.finished == 0);
500+
501+
return s_kt_process(md, in, inlen);
502+
}
503+
504+
int kt_customization(hash_state *md, const unsigned char *in, unsigned long inlen)
505+
{
506+
LTC_ARGCHK(md != NULL);
507+
LTC_ARGCHK(in != NULL || inlen == 0);
508+
LTC_ARGCHK(md->kt.finished == 0);
509+
510+
md->kt.customization_len += inlen;
511+
return s_kt_process(md, in, inlen);
512+
}
513+
514+
int kt_done(hash_state *md, unsigned char *out, unsigned long outlen)
515+
{
516+
int couner_len;
517+
unsigned char couner_buf[sizeof(unsigned long) + 1];
518+
int err;
519+
int variant;
520+
int digest_len;
521+
unsigned char digest_buf[64];
522+
unsigned char ffff[2];
523+
unsigned char domain;
524+
525+
LTC_ARGCHK(md != NULL);
526+
LTC_ARGCHK(out != NULL || outlen == 0);
527+
528+
if (md->kt.finished == 0)
529+
{
530+
md->kt.finished = 1;
531+
couner_len = 0;
532+
while (md->kt.customization_len != 0)
533+
{
534+
couner_buf[sizeof(couner_buf) - 1 - 1 - couner_len] = md->kt.customization_len & 0xff;
535+
md->kt.customization_len >>= 8;
536+
++couner_len;
537+
}
538+
couner_buf[sizeof(couner_buf) - 1] = couner_len;
539+
if ((err = s_kt_process(md, &couner_buf[sizeof(couner_buf) - 1 - couner_len], couner_len + 1)) != CRYPT_OK) return err;
540+
if(md->kt.phase != 0)
541+
{
542+
assert(md->kt.outer.capacity_words == 4 || md->kt.outer.capacity_words == 8);
543+
variant = md->kt.outer.capacity_words == 4 ? 128 : 256;
544+
digest_len = variant == 128 ? 32 : 64;
545+
if ((err = s_sha3_shake_done((hash_state*)&md->kt.inner, &digest_buf[0], digest_len, 0x0b, s_keccak_turbo_f)) != CRYPT_OK) return err;
546+
if ((err = turbo_shake_process((hash_state*)&md->kt.outer, &digest_buf[0], digest_len)) != CRYPT_OK) return err;
547+
couner_len = 0;
548+
while (md->kt.blocks_count != 0)
549+
{
550+
couner_buf[sizeof(couner_buf) - 1 - 1 - couner_len] = md->kt.blocks_count & 0xff;
551+
md->kt.blocks_count >>= 8;
552+
++couner_len;
553+
}
554+
couner_buf[sizeof(couner_buf) - 1] = couner_len;
555+
if ((err = turbo_shake_process((hash_state*)&md->kt.outer, &couner_buf[sizeof(couner_buf) - 1 - couner_len], couner_len + 1)) != CRYPT_OK) return err;
556+
ffff[0] = 0xff;
557+
ffff[1] = 0xff;
558+
if ((err = turbo_shake_process((hash_state*)&md->kt.outer, &ffff[0], sizeof(ffff))) != CRYPT_OK) return err;
559+
}
560+
}
561+
domain = md->kt.phase == 0 ? 0x07 : 0x06;
562+
return s_sha3_shake_done(md, out, outlen, domain, s_keccak_turbo_f);
563+
}
564+
565+
#endif
566+
419567
#endif

src/hashes/sha3_test.c

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ int sha3_shake_test(void)
388388
#endif
389389
}
390390

391-
#if defined LTC_TURBO_SHAKE
391+
#if defined LTC_TURBO_SHAKE || defined LTC_KT
392392
static LTC_INLINE int s_turbo_shake_generate_ptn(unsigned char* buffer, long offset, long amount)
393393
{
394394
long i;
@@ -517,6 +517,132 @@ int turbo_shake_test(void)
517517
}
518518
#endif
519519

520+
#ifdef LTC_KT
521+
static LTC_INLINE int s_kt_test_one(int bits_count, int is_ptn, long input_bytes_count, long customization_bytes_count, long skip_digest_bytes, long digest_bytes_count, int counter, char const *expected_digest_hex)
522+
{
523+
int err;
524+
hash_state md;
525+
long offset;
526+
long rem;
527+
long count;
528+
unsigned char input[1024];
529+
unsigned char digest[64];
530+
char const *expected_hex;
531+
unsigned char expected_digest_bin[sizeof(digest)];
532+
533+
LTC_ARGCHK(bits_count == 128 || bits_count == 256);
534+
LTC_ARGCHK(is_ptn == 0 || is_ptn == 1);
535+
LTC_ARGCHK(input_bytes_count >= 0);
536+
LTC_ARGCHK(customization_bytes_count >= 0);
537+
LTC_ARGCHK(skip_digest_bytes >= 0);
538+
LTC_ARGCHK(digest_bytes_count >= 1);
539+
LTC_ARGCHK(counter >= 0);
540+
LTC_ARGCHK(expected_digest_hex && expected_digest_hex[0] != '\0');
541+
542+
if ((err = kt_init(&md, bits_count)) != CRYPT_OK) return err;
543+
offset = 0;
544+
rem = input_bytes_count;
545+
do
546+
{
547+
count = rem < ((long)(sizeof(input))) ? rem : ((long)(sizeof(input)));
548+
if (is_ptn)
549+
{
550+
if ((err = s_turbo_shake_generate_ptn(&input[0], offset, count)) != CRYPT_OK) return err;
551+
}
552+
else
553+
{
554+
XMEMSET(&input[0], 0xff, count);
555+
}
556+
if ((err = kt_process(&md, &input[0], count)) != CRYPT_OK) return err;
557+
offset += count;
558+
rem -= count;
559+
}while(rem != 0);
560+
offset = 0;
561+
rem = customization_bytes_count;
562+
do
563+
{
564+
count = rem < ((long)(sizeof(input))) ? rem : ((long)(sizeof(input)));
565+
if ((err = s_turbo_shake_generate_ptn(&input[0], offset, count)) != CRYPT_OK) return err;
566+
if ((err = kt_customization(&md, &input[0], count)) != CRYPT_OK) return err;
567+
offset += count;
568+
rem -= count;
569+
}while(rem != 0);
570+
rem = skip_digest_bytes;
571+
do
572+
{
573+
count = rem < ((long)(sizeof(digest))) ? rem : ((long)(sizeof(digest)));
574+
if ((err = kt_done(&md, &digest[0], count)) != CRYPT_OK) return err;
575+
rem -= count;
576+
}while(rem != 0);
577+
rem = digest_bytes_count;
578+
expected_hex = expected_digest_hex;
579+
do
580+
{
581+
count = rem < ((long)(sizeof(digest))) ? rem : ((long)(sizeof(digest)));
582+
if ((err = s_turbo_shake_hex_to_bin(&expected_hex[0], &expected_digest_bin[0], count)) != CRYPT_OK) return err;
583+
if ((err = kt_done(&md, &digest[0], count)) != CRYPT_OK) return err;
584+
LTC_COMPARE_TESTVECTOR(digest, count, expected_digest_bin, count, "KangarooTwelve", counter);
585+
rem -= count;
586+
expected_hex += count * 2;
587+
}while(rem != 0);
588+
return CRYPT_OK;
589+
}
590+
#endif
591+
592+
#ifdef LTC_KT
593+
int kt_test(void)
594+
{
595+
#ifndef LTC_TEST
596+
return CRYPT_NOP;
597+
#else
598+
int counter;
599+
int err;
600+
601+
/* https://datatracker.ietf.org/doc/html/rfc9861#name-test-vectors */
602+
/* https://www.rfc-editor.org/rfc/rfc9861.txt */
603+
604+
counter = 1;
605+
if ((err = s_kt_test_one(128, 1, 0, 0, 0, 32, counter++, "1ac2d450fc3b4205d19da7bfca1b37513c0803577ac7167f06fe2ce1f0ef39e5")) != CRYPT_OK) return err;
606+
if ((err = s_kt_test_one(128, 1, 0, 0, 0, 64, counter++, "1ac2d450fc3b4205d19da7bfca1b37513c0803577ac7167f06fe2ce1f0ef39e54269c056b8c82e48276038b6d292966cc07a3d4645272e31ff38508139eb0a71")) != CRYPT_OK) return err;
607+
if ((err = s_kt_test_one(128, 1, 0, 0, 10000, 32, counter++, "e8dc563642f7228c84684c898405d3a834799158c079b12880277a1d28e2ff6d")) != CRYPT_OK) return err;
608+
if ((err = s_kt_test_one(128, 1, 1, 0, 0, 32, counter++, "2bda92450e8b147f8a7cb629e784a058efca7cf7d8218e02d345dfaa65244a1f")) != CRYPT_OK) return err;
609+
if ((err = s_kt_test_one(128, 1, 17, 0, 0, 32, counter++, "6bf75fa2239198db4772e36478f8e19b0f371205f6a9a93a273f51df37122888")) != CRYPT_OK) return err;
610+
if ((err = s_kt_test_one(128, 1, 17*17, 0, 0, 32, counter++, "0c315ebcdedbf61426de7dcf8fb725d1e74675d7f5327a5067f367b108ecb67c")) != CRYPT_OK) return err;
611+
if ((err = s_kt_test_one(128, 1, 17*17*17, 0, 0, 32, counter++, "cb552e2ec77d9910701d578b457ddf772c12e322e4ee7fe417f92c758f0d59d0")) != CRYPT_OK) return err;
612+
if ((err = s_kt_test_one(128, 1, 17*17*17*17, 0, 0, 32, counter++, "8701045e22205345ff4dda05555cbb5c3af1a771c2b89baef37db43d9998b9fe")) != CRYPT_OK) return err;
613+
if ((err = s_kt_test_one(128, 1, 17*17*17*17*17, 0, 0, 32, counter++, "844d610933b1b9963cbdeb5ae3b6b05cc7cbd67ceedf883eb678a0a8e0371682")) != CRYPT_OK) return err;
614+
if ((err = s_kt_test_one(128, 1, 17*17*17*17*17*17, 0, 0, 32, counter++, "3c390782a8a4e89fa6367f72feaaf13255c8d95878481d3cd8ce85f58e880af8")) != CRYPT_OK) return err;
615+
if ((err = s_kt_test_one(128, 1, 0, 1, 0, 32, counter++, "fab658db63e94a246188bf7af69a133045f46ee984c56e3c3328caaf1aa1a583")) != CRYPT_OK) return err;
616+
if ((err = s_kt_test_one(128, 0, 1, 41, 0, 32, counter++, "d848c5068ced736f4462159b9867fd4c20b808acc3d5bc48e0b06ba0a3762ec4")) != CRYPT_OK) return err;
617+
if ((err = s_kt_test_one(128, 0, 3, 41*41, 0, 32, counter++, "c389e5009ae57120854c2e8c64670ac01358cf4c1baf89447a724234dc7ced74")) != CRYPT_OK) return err;
618+
if ((err = s_kt_test_one(128, 0, 7, 41*41*41, 0, 32, counter++, "75d2f86a2e644566726b4fbcfc5657b9dbcf070c7b0dca06450ab291d7443bcf")) != CRYPT_OK) return err;
619+
if ((err = s_kt_test_one(128, 1, 8191, 0, 0, 32, counter++, "1b577636f723643e990cc7d6a659837436fd6a103626600eb8301cd1dbe553d6")) != CRYPT_OK) return err;
620+
if ((err = s_kt_test_one(128, 1, 8192, 0, 0, 32, counter++, "48f256f6772f9edfb6a8b661ec92dc93b95ebd05a08a17b39ae3490870c926c3")) != CRYPT_OK) return err;
621+
if ((err = s_kt_test_one(128, 1, 8192, 8189, 0, 32, counter++, "3ed12f70fb05ddb58689510ab3e4d23c6c6033849aa01e1d8c220a297fedcd0b")) != CRYPT_OK) return err;
622+
if ((err = s_kt_test_one(128, 1, 8192, 8190, 0, 32, counter++, "6a7c1b6a5cd0d8c9ca943a4a216cc64604559a2ea45f78570a15253d67ba00ae")) != CRYPT_OK) return err;
623+
if ((err = s_kt_test_one(256, 1, 0, 0, 0, 64, counter++, "b23d2e9cea9f4904e02bec06817fc10ce38ce8e93ef4c89e6537076af8646404e3e8b68107b8833a5d30490aa33482353fd4adc7148ecb782855003aaebde4a9")) != CRYPT_OK) return err;
624+
if ((err = s_kt_test_one(256, 1, 0, 0, 0, 128, counter++, "b23d2e9cea9f4904e02bec06817fc10ce38ce8e93ef4c89e6537076af8646404e3e8b68107b8833a5d30490aa33482353fd4adc7148ecb782855003aaebde4a9b0925319d8ea1e121a609821ec19efea89e6d08daee1662b69c840289f188ba860f55760b61f82114c030c97e5178449608ccd2cd2d919fc7829ff69931ac4d0")) != CRYPT_OK) return err;
625+
if ((err = s_kt_test_one(256, 1, 0, 0, 10000, 64, counter++, "ad4a1d718cf950506709a4c33396139b4449041fc79a05d68da35f1e453522e056c64fe94958e7085f2964888259b9932752f3ccd855288efee5fcbb8b563069")) != CRYPT_OK) return err;
626+
if ((err = s_kt_test_one(256, 1, 1, 0, 0, 64, counter++, "0d005a194085360217128cf17f91e1f71314efa5564539d444912e3437efa17f82db6f6ffe76e781eaa068bce01f2bbf81eacb983d7230f2fb02834a21b1ddd0")) != CRYPT_OK) return err;
627+
if ((err = s_kt_test_one(256, 1, 17, 0, 0, 64, counter++, "1ba3c02b1fc514474f06c8979978a9056c8483f4a1b63d0dccefe3a28a2f323e1cdcca40ebf006ac76ef0397152346837b1277d3e7faa9c9653b19075098527b")) != CRYPT_OK) return err;
628+
if ((err = s_kt_test_one(256, 1, 17*17, 0, 0, 64, counter++, "de8ccbc63e0f133ebb4416814d4c66f691bbf8b6a61ec0a7700f836b086cb029d54f12ac7159472c72db118c35b4e6aa213c6562caaa9dcc518959e69b10f3ba")) != CRYPT_OK) return err;
629+
if ((err = s_kt_test_one(256, 1, 17*17*17, 0, 0, 64, counter++, "647efb49fe9d717500171b41e7f11bd491544443209997ce1c2530d15eb1ffbb598935ef954528ffc152b1e4d731ee2683680674365cd191d562bae753b84aa5")) != CRYPT_OK) return err;
630+
if ((err = s_kt_test_one(256, 1, 17*17*17*17, 0, 0, 64, counter++, "b06275d284cd1cf205bcbe57dccd3ec1ff6686e3ed15776383e1f2fa3c6ac8f08bf8a162829db1a44b2a43ff83dd89c3cf1ceb61ede659766d5ccf817a62ba8d")) != CRYPT_OK) return err;
631+
if ((err = s_kt_test_one(256, 1, 17*17*17*17*17, 0, 0, 64, counter++, "9473831d76a4c7bf77ace45b59f1458b1673d64bcd877a7c66b2664aa6dd149e60eab71b5c2bab858c074ded81ddce2b4022b5215935c0d4d19bf511aeeb0772")) != CRYPT_OK) return err;
632+
if ((err = s_kt_test_one(256, 1, 17*17*17*17*17*17, 0, 0, 64, counter++, "0652b740d78c5e1f7c8dcc1777097382768b7ff38f9a7a20f29f413bb1b3045b31a5578f568f911e09cf44746da84224a5266e96a4a535e871324e4f9c7004da")) != CRYPT_OK) return err;
633+
if ((err = s_kt_test_one(256, 1, 0, 1, 0, 64, counter++, "9280f5cc39b54a5a594ec63de0bb99371e4609d44bf845c2f5b8c316d72b159811f748f23e3fabbe5c3226ec96c62186df2d33e9df74c5069ceecbb4dd10eff6")) != CRYPT_OK) return err;
634+
if ((err = s_kt_test_one(256, 0, 1, 41, 0, 64, counter++, "47ef96dd616f200937aa7847e34ec2feae8087e3761dc0f8c1a154f51dc9ccf845d7adbce57ff64b639722c6a1672e3bf5372d87e00aff89be97240756998853")) != CRYPT_OK) return err;
635+
if ((err = s_kt_test_one(256, 0, 3, 41*41, 0, 64, counter++, "3b48667a5051c5966c53c5d42b95de451e05584e7806e2fb765eda959074172cb438a9e91dde337c98e9c41bed94c4e0aef431d0b64ef2324f7932caa6f54969")) != CRYPT_OK) return err;
636+
if ((err = s_kt_test_one(256, 0, 7, 41*41*41, 0, 64, counter++, "e0911cc00025e1540831e266d94add9b98712142b80d2629e643aac4efaf5a3a30a88cbf4ac2a91a2432743054fbcc9897670e86ba8cec2fc2ace9c966369724")) != CRYPT_OK) return err;
637+
if ((err = s_kt_test_one(256, 1, 8191, 0, 0, 64, counter++, "3081434d93a4108d8d8a3305b89682cebedc7ca4ea8a3ce869fbb73cbe4a58eef6f24de38ffc170514c70e7ab2d01f03812616e863d769afb3753193ba045b20")) != CRYPT_OK) return err;
638+
if ((err = s_kt_test_one(256, 1, 8192, 0, 0, 64, counter++, "c6ee8e2ad3200c018ac87aaa031cdac22121b412d07dc6e0dccbb53423747e9a1c18834d99df596cf0cf4b8dfafb7bf02d139d0c9035725adc1a01b7230a41fa")) != CRYPT_OK) return err;
639+
if ((err = s_kt_test_one(256, 1, 8192, 8189, 0, 64, counter++, "74e47879f10a9c5d11bd2da7e194fe57e86378bf3c3f7448eff3c576a0f18c5caae0999979512090a7f348af4260d4de3c37f1ecaf8d2c2c96c1d16c64b12496")) != CRYPT_OK) return err;
640+
if ((err = s_kt_test_one(256, 1, 8192, 8190, 0, 64, counter++, "f4b5908b929ffe01e0f79ec2f21243d41a396b2e7303a6af1d6399cd6c7a0a2dd7c4f607e8277f9c9b1cb4ab9ddc59d4b92d1fc7558441f1832c3279a4241b8b")) != CRYPT_OK) return err;
641+
return CRYPT_OK;
642+
#endif
643+
}
644+
#endif
645+
520646
#endif
521647

522648
#ifdef LTC_KECCAK

src/headers/tomcrypt_custom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@
259259
#define LTC_SHA3
260260
#define LTC_KECCAK
261261
#define LTC_TURBO_SHAKE
262+
#define LTC_KT
262263
#define LTC_SHA512
263264
#define LTC_SHA512_256
264265
#define LTC_SHA512_224

src/headers/tomcrypt_hash.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ struct sha3_state {
1414
};
1515
#endif
1616

17+
#ifdef LTC_KT
18+
struct kt_state {
19+
struct sha3_state outer;
20+
struct sha3_state inner;
21+
unsigned long blocks_count;
22+
unsigned long customization_len;
23+
unsigned short remaining; /* bytes out of 8kB block */
24+
unsigned char phase; /* 0 -- initial, 1 -- additional */
25+
unsigned char finished; /* 0 -- false, 1 -- true */
26+
};
27+
#endif
28+
1729
#ifdef LTC_SHA512
1830
struct sha512_state {
1931
ulong64 length, state[8];
@@ -152,6 +164,9 @@ typedef union Hash_state {
152164
#if defined(LTC_SHA3) || defined(LTC_KECCAK)
153165
struct sha3_state sha3;
154166
#endif
167+
#ifdef LTC_KT
168+
struct kt_state kt;
169+
#endif
155170
#ifdef LTC_SHA512
156171
struct sha512_state sha512;
157172
#endif
@@ -309,6 +324,14 @@ int turbo_shake_done(hash_state *md, unsigned char *out, unsigned long outlen);
309324
int turbo_shake_test(void);
310325
#endif
311326

327+
#ifdef LTC_KT
328+
int kt_init(hash_state *md, int num);
329+
int kt_process(hash_state *md, const unsigned char *in, unsigned long inlen);
330+
int kt_customization(hash_state *md, const unsigned char *in, unsigned long inlen);
331+
int kt_done(hash_state *md, unsigned char *out, unsigned long outlen);
332+
int kt_test(void);
333+
#endif
334+
312335
#ifdef LTC_SHA512
313336
int sha512_init(hash_state * md);
314337
int sha512_process(hash_state * md, const unsigned char *in, unsigned long inlen);

src/misc/crypt/crypt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ const char *crypt_build_settings =
160160
#if defined(LTC_TURBO_SHAKE)
161161
" TurboSHAKE\n"
162162
#endif
163+
#if defined(LTC_KT)
164+
" KangarooTwelve\n"
165+
#endif
163166
#if defined(LTC_KECCAK)
164167
" KECCAK\n"
165168
#endif

tests/cipher_hash_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ int cipher_hash_test(void)
6363
#ifdef LTC_TURBO_SHAKE
6464
DO(turbo_shake_test());
6565
#endif
66+
#ifdef LTC_KT
67+
DO(kt_test());
68+
#endif
6669

6770
return 0;
6871
}

0 commit comments

Comments
 (0)