Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests examples command #621

Merged
merged 13 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions examples/custom_backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ An application using mlkem-native with a custom FIPS-202 backend and custom conf
demonstration, we set a custom namespace. We set `MLKEM_NATIVE_FIPS202_BACKEND` to point to our custom FIPS-202
backend, but leave `MLKEM_NATIVE_ARITH_BACKEND` undefined to indicate that we wish to use the C backend.

## Note

The tiny_sha3 code uses a byte-reversed presentation of the Keccakf1600 state for big-endian targets. Since
mlkem-native's FIPS202 frontend assumes a standard presentation, the corresponding byte-reversal in
[sha3.c](mlkem_native/fips202/native/custom/src/sha3.c) is removed.

## Usage

Build this example with `make build`, run with `make run`.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,25 @@ void sha3_keccakf(uint64_t st[25])
int i, j, r;
uint64_t t, bc[5];

#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
uint8_t *v;

/* endianess conversion. this is redundant on little-endian targets */
for (i = 0; i < 25; i++)
{
v = (uint8_t *)&st[i];
st[i] = ((uint64_t)v[0]) | (((uint64_t)v[1]) << 8) |
(((uint64_t)v[2]) << 16) | (((uint64_t)v[3]) << 24) |
(((uint64_t)v[4]) << 32) | (((uint64_t)v[5]) << 40) |
(((uint64_t)v[6]) << 48) | (((uint64_t)v[7]) << 56);
}
#endif
/* NOTE:
* This is present in the tiny_sha3 implementation because it uses
* a byte-reversed presentation of the Keccakf1600 state for big endian
* targets. mlkem-native uses the standard presentation, hence we don't
* the reversal here. */
/* #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ */
/* uint8_t *v; */

/* /\* endianess conversion. this is redundant on little-endian targets *\/
*/
/* for (i = 0; i < 25; i++) */
/* { */
/* v = (uint8_t *)&st[i]; */
/* st[i] = ((uint64_t)v[0]) | (((uint64_t)v[1]) << 8) | */
/* (((uint64_t)v[2]) << 16) | (((uint64_t)v[3]) << 24) | */
/* (((uint64_t)v[4]) << 32) | (((uint64_t)v[5]) << 40) | */
/* (((uint64_t)v[6]) << 48) | (((uint64_t)v[7]) << 56); */
/* } */
/* #endif */
mkannwischer marked this conversation as resolved.
Show resolved Hide resolved

/* actual iteration */
for (r = 0; r < KECCAKF_ROUNDS; r++)
Expand Down Expand Up @@ -82,22 +88,28 @@ void sha3_keccakf(uint64_t st[25])
st[0] ^= keccakf_rndc[r];
}

#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
/* endianess conversion. this is redundant on little-endian targets */
for (i = 0; i < 25; i++)
{
v = (uint8_t *)&st[i];
t = st[i];
v[0] = t & 0xFF;
v[1] = (t >> 8) & 0xFF;
v[2] = (t >> 16) & 0xFF;
v[3] = (t >> 24) & 0xFF;
v[4] = (t >> 32) & 0xFF;
v[5] = (t >> 40) & 0xFF;
v[6] = (t >> 48) & 0xFF;
v[7] = (t >> 56) & 0xFF;
}
#endif
/* NOTE:
* This is present in the tiny_sha3 implementation because it uses
* a byte-reversed presentation of the Keccakf1600 state for big endian
* targets. mlkem-native uses the standard presentation, hence we don't
* the reversal here. */
/* #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ */
/* /\* endianess conversion. this is redundant on little-endian targets *\/
*/
/* for (i = 0; i < 25; i++) */
/* { */
/* v = (uint8_t *)&st[i]; */
/* t = st[i]; */
/* v[0] = t & 0xFF; */
/* v[1] = (t >> 8) & 0xFF; */
/* v[2] = (t >> 16) & 0xFF; */
/* v[3] = (t >> 24) & 0xFF; */
/* v[4] = (t >> 32) & 0xFF; */
/* v[5] = (t >> 40) & 0xFF; */
/* v[6] = (t >> 48) & 0xFF; */
/* v[7] = (t >> 56) & 0xFF; */
/* } */
/* #endif */
}

/* Initialize the context for SHA3 */
Expand Down
Loading