sha3
Embeddable C11 SHA-3 implementation.
Data Structures | Functions
KangarooTwelve

Faster, reduced-round XOF with a customzation string, as defined in the draft KangarooTwelve and TurboSHAKE specification. More...

Data Structures

struct  k12_t
 KangarooTwelve XOF context (all members are private). More...
 

Functions

void k12_once (const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Absorb data into KangarooTwelve, then squeeze bytes out. More...
 
void k12_custom_once (const uint8_t *src, const size_t src_len, const uint8_t *custom, const size_t custom_len, uint8_t *dst, const size_t dst_len)
 Absorb data into KangarooTwelve with customization string, then squeeze bytes out. More...
 
void k12_init (k12_t *k12, const uint8_t *src, const size_t src_len, const uint8_t *custom, const size_t custom_len)
 Initialize KangarooTwelve context. More...
 
void k12_squeeze (k12_t *k12, uint8_t *dst, const size_t len)
 Squeeze bytes from KangarooTwelve context. More...
 

Detailed Description

Faster, reduced-round XOF with a customzation string, as defined in the draft KangarooTwelve and TurboSHAKE specification.

Function Documentation

◆ k12_custom_once()

void k12_custom_once ( const uint8_t *  src,
const size_t  src_len,
const uint8_t *  custom,
const size_t  custom_len,
uint8_t *  dst,
const size_t  dst_len 
)

Absorb data into KangarooTwelve with customization string, then squeeze bytes out.

Initialize internal KangarooTwelve context with custom string custom of length custom_len, absorb src_len bytes of input from source buffer src, then squeeze dst_len bytes of output into destination buffer dst.

Parameters
[in]srcSource buffer.
[in]src_lenSource buffer length, in bytes.
[in]customCustom string buffer.
[in]custom_lenCustom string length, in bytes.
[out]dstDestination buffer.
[in]dst_lenDestination buffer length, in bytes.

Example:

// get 1024 random bytes
uint8_t buf[1024] = { 0 };
rand_bytes(buf, sizeof(buf));
// customization string and length (in bytes, w/o NUL)
const uint8_t custom[] = "hello";
const size_t custom_len = sizeof(custom) - 1;
// absorb `buf` and `custom` into KangarooTwelve, write 32 bytes to
// `out`
uint8_t out[32] = { 0 };
k12_custom_once(buf, sizeof(buf), custom, custom_len, out, sizeof(out));
void k12_custom_once(const uint8_t *src, const size_t src_len, const uint8_t *custom, const size_t custom_len, uint8_t *dst, const size_t dst_len)
Absorb data into KangarooTwelve with customization string, then squeeze bytes out.

◆ k12_init()

void k12_init ( k12_t k12,
const uint8_t *  src,
const size_t  src_len,
const uint8_t *  custom,
const size_t  custom_len 
)

Initialize KangarooTwelve context.

Initialize KangarooTwelve context with message src of length src_len bytes and custom string custom of length custom_len bytes.

Note
This KangarooTwelve implementation is sequential, not parallel.
Parameters
[out]k12KangarooTwelve context.
[in]srcSource buffer.
[in]src_lenSource buffer length, in bytes.
[in]customCustom string buffer.
[in]custom_lenCustom string length, in bytes.

Example:

// get 1024 random bytes
uint8_t buf[1024] = { 0 };
rand_bytes(buf, sizeof(buf));
// customization string and length (in bytes, w/o NUL)
const uint8_t custom[] = "hello";
const size_t custom_len = sizeof(custom) - 1;
// create KangarooTwelve context from `buf and `custom`
k12_t ctx = { 0 };
k12_init(&ctx, buf, sizeof(buf), custom, custom_len);
// print result prefix to stdout
printf("%s: ", __func__);
// squeeze first 128 bytes of of result in 32 byte chunks
for (size_t i = 0; i < 128; i += 32) {
// squeeze 32 bytes of result into `out`
uint8_t out[32] = { 0 };
k12_squeeze(&ctx, out, sizeof(out));
// encode as hex, print to stdout
hex_write(stdout, out, sizeof(out));
}
// print result suffix to stdout
fputs("\n", stdout);
void k12_squeeze(k12_t *k12, uint8_t *dst, const size_t len)
Squeeze bytes from KangarooTwelve context.
void k12_init(k12_t *k12, const uint8_t *src, const size_t src_len, const uint8_t *custom, const size_t custom_len)
Initialize KangarooTwelve context.
KangarooTwelve XOF context (all members are private).
Definition: sha3.h:2287

◆ k12_once()

void k12_once ( const uint8_t *  src,
const size_t  src_len,
uint8_t *  dst,
const size_t  dst_len 
)

Absorb data into KangarooTwelve, then squeeze bytes out.

Initialize internal KangarooTwelve context, absorb src_len bytes of input from source buffer src, then squeeze dst_len bytes of output into destination buffer dst.

Parameters
[in]srcSource buffer.
[in]src_lenSource buffer length, in bytes.
[out]dstDestination buffer.
[in]dst_lenDestination buffer length, in bytes.

Example:

// get 1024 random bytes
uint8_t buf[1024] = { 0 };
rand_bytes(buf, sizeof(buf));
// absorb `buf` into KangarooTwelve, write 32 bytes to `out`
uint8_t out[32] = { 0 };
k12_once(buf, sizeof(buf), out, sizeof(out));
void k12_once(const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
Absorb data into KangarooTwelve, then squeeze bytes out.

◆ k12_squeeze()

void k12_squeeze ( k12_t k12,
uint8_t *  dst,
const size_t  len 
)

Squeeze bytes from KangarooTwelve context.

Squeeze dst_len bytes of output into destination buffer dst from KangarooTwelve context k12. Can be called iteratively to squeeze output data in chunks.

Note
This KangarooTwelve implementation is sequential, not parallel.
Parameters
[in,out]k12KangarooTwelve context.
[out]dstDestination buffer.
[in]lenDestination buffer length, in bytes.

Example:

// get 1024 random bytes
uint8_t buf[1024] = { 0 };
rand_bytes(buf, sizeof(buf));
// customization string and length (in bytes, w/o NUL)
const uint8_t custom[] = "hello";
const size_t custom_len = sizeof(custom) - 1;
// create KangarooTwelve context from `buf and `custom`
k12_t ctx = { 0 };
k12_init(&ctx, buf, sizeof(buf), custom, custom_len);
// print result prefix to stdout
printf("%s: ", __func__);
// squeeze first 128 bytes of of result in 32 byte chunks
for (size_t i = 0; i < 128; i += 32) {
// squeeze 32 bytes of result into `out`
uint8_t out[32] = { 0 };
k12_squeeze(&ctx, out, sizeof(out));
// encode as hex, print to stdout
hex_write(stdout, out, sizeof(out));
}
// print result suffix to stdout
fputs("\n", stdout);