-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement FrodoKEM and eFrodoKEM according to ISO 20230314
Integrated into CLI benchmarking tool and X.509 tests Co-Authored-By: René Meusel <[email protected]>
- Loading branch information
1 parent
fac04ab
commit 21b52d3
Showing
24 changed files
with
3,993 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* FrodoKEM matrix generator based on SHAKE | ||
* | ||
* The Fellowship of the FrodoKEM: | ||
* (C) 2023 Jack Lloyd | ||
* 2023 René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity | ||
* | ||
* Botan is released under the Simplified BSD License (see license.txt) | ||
*/ | ||
|
||
#ifndef BOTAN_FRODOKEM_SHAKE_GENERATOR_H_ | ||
#define BOTAN_FRODOKEM_SHAKE_GENERATOR_H_ | ||
|
||
#include <botan/internal/frodo_constants.h> | ||
#include <botan/internal/frodo_types.h> | ||
#include <botan/internal/loadstor.h> | ||
#include <botan/internal/shake_xof.h> | ||
|
||
#include <span> | ||
|
||
namespace Botan { | ||
|
||
inline auto create_shake_row_generator(const FrodoKEMConstants& constants, StrongSpan<const FrodoSeedA> seed_a) { | ||
BOTAN_ASSERT_NOMSG(constants.mode().is_shake()); | ||
|
||
return [xof = SHAKE_128_XOF(), a = FrodoSeedA(seed_a)](std::span<uint8_t> out, uint16_t i) mutable { | ||
xof.clear(); | ||
// TODO: update that once #3707 is merged | ||
// potentially add a new method: std::array<uint8_t, XX> as_le(uintXX_t) | ||
std::array<uint8_t, 2> le; | ||
store_le(i, le.data()); | ||
xof.update(le); | ||
xof.update(a); | ||
xof.output(out); | ||
}; | ||
} | ||
|
||
} // namespace Botan | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<defines> | ||
FRODOKEM_SHAKE -> 20231114 | ||
</defines> | ||
|
||
<module_info> | ||
name -> "FrodoKEM" | ||
</module_info> | ||
|
||
<requires> | ||
shake_xof | ||
frodokem_common | ||
</requires> |
56 changes: 56 additions & 0 deletions
56
src/lib/pubkey/frodokem/frodokem_aes/frodo_aes_generator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* FrodoKEM matrix generator based on AES | ||
* | ||
* The Fellowship of the FrodoKEM: | ||
* (C) 2023 Jack Lloyd | ||
* 2023 René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity | ||
* | ||
* Botan is released under the Simplified BSD License (see license.txt) | ||
*/ | ||
|
||
#ifndef BOTAN_FRODOKEM_AES_GENERATOR_H_ | ||
#define BOTAN_FRODOKEM_AES_GENERATOR_H_ | ||
|
||
#include <botan/internal/aes.h> | ||
#include <botan/internal/frodo_constants.h> | ||
#include <botan/internal/frodo_types.h> | ||
#include <botan/internal/loadstor.h> | ||
#include <botan/internal/stl_util.h> | ||
|
||
#include <functional> | ||
#include <span> | ||
|
||
namespace Botan { | ||
|
||
inline auto create_aes_row_generator(const FrodoKEMConstants& constants, StrongSpan<const FrodoSeedA> seed_a) { | ||
BOTAN_ASSERT_NOMSG(constants.mode().is_aes()); | ||
|
||
auto setup_aes = [](StrongSpan<const FrodoSeedA> seed) { | ||
AES_128 aes; | ||
aes.set_key(seed); | ||
return aes; | ||
}; | ||
|
||
return [n = constants.n(), aes = setup_aes(seed_a)](std::span<uint8_t> out, uint16_t i) { | ||
BufferStuffer out_bs(out); | ||
|
||
for(size_t j = 0; j < n; j += 8) { | ||
// set up the to-be-encrypted 'b' value in the out variable | ||
// for in-place encryption of the block cipher | ||
auto out_coefs = out_bs.next(aes.block_size()); | ||
|
||
// b = i || j || 0000... | ||
store_le(static_cast<uint16_t>(i), out_coefs.data()); | ||
store_le(static_cast<uint16_t>(j), out_coefs.data() + sizeof(uint16_t)); | ||
for(size_t ii = 4; ii < out_coefs.size(); ++ii) { | ||
out_coefs[ii] = 0; | ||
} | ||
|
||
aes.encrypt(out_coefs); | ||
} | ||
}; | ||
} | ||
|
||
} // namespace Botan | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<defines> | ||
FRODOKEM_AES -> 20231103 | ||
</defines> | ||
|
||
<module_info> | ||
name -> "FrodoKEM (AES)" | ||
</module_info> | ||
|
||
<requires> | ||
aes | ||
frodokem_common | ||
</requires> |
Oops, something went wrong.