Skip to content

Commit e20d5a2

Browse files
committed
crypto: lib/blake2s - Split up test function to halve stack usage
Reduce the stack usage further by splitting up the test function. Also squash blocks and unaligned_blocks into one array. Reported-by: kernel test robot <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 49bc6a7 commit e20d5a2

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/crypto/blake2s-selftest.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static const u8 blake2s_testvecs[][BLAKE2S_HASH_SIZE] __initconst = {
545545
0xd6, 0x98, 0x6b, 0x07, 0x10, 0x65, 0x52, 0x65, },
546546
};
547547

548-
bool __init blake2s_selftest(void)
548+
static bool __init noinline_for_stack blake2s_digest_test(void)
549549
{
550550
u8 key[BLAKE2S_KEY_SIZE];
551551
u8 buf[ARRAY_SIZE(blake2s_testvecs)];
@@ -589,11 +589,20 @@ bool __init blake2s_selftest(void)
589589
}
590590
}
591591

592+
return success;
593+
}
594+
595+
static bool __init noinline_for_stack blake2s_random_test(void)
596+
{
597+
struct blake2s_state state;
598+
bool success = true;
599+
int i, l;
600+
592601
for (i = 0; i < 32; ++i) {
593602
enum { TEST_ALIGNMENT = 16 };
594-
u8 unaligned_block[BLAKE2S_BLOCK_SIZE + TEST_ALIGNMENT - 1]
603+
u8 blocks[BLAKE2S_BLOCK_SIZE * 2 + TEST_ALIGNMENT - 1]
595604
__aligned(TEST_ALIGNMENT);
596-
u8 blocks[BLAKE2S_BLOCK_SIZE * 2];
605+
u8 *unaligned_block = blocks + BLAKE2S_BLOCK_SIZE;
597606
struct blake2s_state state1, state2;
598607

599608
get_random_bytes(blocks, sizeof(blocks));
@@ -630,3 +639,13 @@ bool __init blake2s_selftest(void)
630639

631640
return success;
632641
}
642+
643+
bool __init blake2s_selftest(void)
644+
{
645+
bool success;
646+
647+
success = blake2s_digest_test();
648+
success &= blake2s_random_test();
649+
650+
return success;
651+
}

0 commit comments

Comments
 (0)