Skip to content

Commit

Permalink
Fix shared builds
Browse files Browse the repository at this point in the history
  • Loading branch information
FAlbertDev committed Jan 10, 2024
1 parent eff28ee commit 63c1b8c
Show file tree
Hide file tree
Showing 17 changed files with 220 additions and 198 deletions.
2 changes: 1 addition & 1 deletion src/lib/pubkey/classic_mceliece/cmce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Classic_McEliece_PrivateKey::Classic_McEliece_PrivateKey(Classic_McEliece_Parame

Classic_McEliece_PrivateKey::Classic_McEliece_PrivateKey(const AlgorithmIdentifier& alg_id,
std::span<const uint8_t> key_bits) :
Classic_McEliece_PrivateKey(Classic_McEliece_Parameters::param_set_from_oid(alg_id.oid()), key_bits) {}
Classic_McEliece_PrivateKey(param_set_from_oid(alg_id.oid()), key_bits) {}

std::unique_ptr<Public_Key> Classic_McEliece_PrivateKey::public_key() const {
return std::make_unique<Classic_McEliece_PublicKey>(*this);
Expand Down
9 changes: 4 additions & 5 deletions src/lib/pubkey/classic_mceliece/cmce.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

#include <botan/pk_keys.h>

#include <botan/cmce_parameters.h>
#include <botan/internal/cmce_field_ordering.h>
#include <botan/internal/cmce_keys_internal.h>
#include <botan/internal/cmce_matrix.h>
#include <botan/internal/cmce_poly.h>
#include <botan/cmce_parameter_set.h>

namespace Botan {

class Classic_McEliece_PublicKeyInternal;
class Classic_McEliece_PrivateKeyInternal;

/**
* Classic McEliece is a Code-Based KEM. It is a round 4 candidate in NIST's PQC competition.
* It is endorsed by the German Federal Office for Information Security for its conservative security
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pubkey/classic_mceliece/cmce_decaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <botan/internal/bitvector.h>
#include <botan/internal/cmce_debug_utils.h>
#include <botan/internal/cmce_field_ordering.h>
#include <botan/internal/cmce_keys_internal.h>
#include <botan/internal/cmce_matrix.h>
#include <botan/internal/pk_ops.h>
#include <botan/internal/pk_ops_impl.h>
Expand All @@ -23,7 +24,7 @@ namespace Botan {
/**
* Classic McEliece Decapsulation Operation
*/
class Classic_McEliece_Decryptor final : public PK_Ops::KEM_Decryption {
class BOTAN_TEST_API Classic_McEliece_Decryptor final : public PK_Ops::KEM_Decryption {
public:
/**
* @brief Constructs a Classic_McEliece_Decryptor object with the given private key.
Expand Down
5 changes: 3 additions & 2 deletions src/lib/pubkey/classic_mceliece/cmce_encaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#include <botan/pk_keys.h>

#include <botan/cmce.h>
#include <botan/cmce_parameters.h>
#include <botan/internal/cmce_field_ordering.h>
#include <botan/internal/cmce_keys_internal.h>
#include <botan/internal/cmce_matrix.h>
#include <botan/internal/cmce_parameters.h>
#include <botan/internal/cmce_poly.h>
#include <botan/internal/pk_ops.h>
#include <botan/internal/pk_ops_impl.h>
Expand All @@ -25,7 +26,7 @@ namespace Botan {
* @brief Classic McEliece Encapsulation Operation
*/
class Classic_McEliece_Encryptor final : public PK_Ops::KEM_Encryption {
class BOTAN_TEST_API Classic_McEliece_Encryptor final : public PK_Ops::KEM_Encryption {
public:
Classic_McEliece_Encryptor(std::shared_ptr<Classic_McEliece_PublicKeyInternal> key) : m_key(std::move(key)) {}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/pubkey/classic_mceliece/cmce_field_ordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Botan is released under the Simplified BSD License (see license.txt)
**/
#include "cmce_field_ordering.h"
#include <botan/internal/cmce_field_ordering.h>

#include <botan/cmce.h>
#include <botan/internal/loadstor.h>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pubkey/classic_mceliece/cmce_field_ordering.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef BOTAN_CMCE_FIELD_ORDERING_H_
#define BOTAN_CMCE_FIELD_ORDERING_H_

#include <botan/cmce_parameters.h>
#include <botan/internal/cmce_parameters.h>
#include <numeric>

namespace Botan {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pubkey/classic_mceliece/cmce_gf.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class BOTAN_TEST_API Classic_McEliece_GF {
/**
* @brief Constant time mask wrapper for GF(q) elements.
*/
class GF_Mask final {
class BOTAN_TEST_API GF_Mask final {
public:
static GF_Mask expand(const Classic_McEliece_GF& v) { return GF_Mask(CT::Mask<uint16_t>::expand(v.elem())); }

Expand Down
8 changes: 4 additions & 4 deletions src/lib/pubkey/classic_mceliece/cmce_keys_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#ifndef BOTAN_CMCE_KEYS_INTERNAL_H_
#define BOTAN_CMCE_KEYS_INTERNAL_H_

#include <botan/cmce_parameters.h>
#include <botan/internal/cmce_field_ordering.h>
#include <botan/internal/cmce_matrix.h>
#include <botan/internal/cmce_parameters.h>
#include <botan/internal/cmce_poly.h>

namespace Botan {
Expand All @@ -26,7 +26,7 @@ class Classic_McEliece_PrivateKeyInternal;
* - The Classic McEliece parameters
* - The public key matrix
*/
class Classic_McEliece_PublicKeyInternal {
class BOTAN_TEST_API Classic_McEliece_PublicKeyInternal {
public:
/**
* @brief Construct a Classic McEliece public key.
Expand Down Expand Up @@ -83,7 +83,7 @@ class Classic_McEliece_PublicKeyInternal {
* - The field ordering alpha
* - The seed s for implicit rejection
*/
class Classic_McEliece_PrivateKeyInternal {
class BOTAN_TEST_API Classic_McEliece_PrivateKeyInternal {
public:
/**
* @brief Construct a Classic McEliece private key.
Expand Down Expand Up @@ -169,7 +169,7 @@ class Classic_McEliece_PrivateKeyInternal {
/**
* @brief Representation of a Classic McEliece key pair.
*/
struct Classic_McEliece_KeyPair_Internal {
struct BOTAN_TEST_API Classic_McEliece_KeyPair_Internal {
std::shared_ptr<Classic_McEliece_PrivateKeyInternal> private_key;
std::shared_ptr<Classic_McEliece_PublicKeyInternal> public_key;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/pubkey/classic_mceliece/cmce_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#ifndef BOTAN_CMCE_MATRIX_H_
#define BOTAN_CMCE_MATRIX_H_

#include <botan/cmce_parameters.h>
#include <botan/internal/bitvector.h>
#include <botan/internal/cmce_field_ordering.h>
#include <botan/internal/cmce_parameters.h>
#include <botan/internal/cmce_poly.h>

namespace Botan {
Expand Down
124 changes: 124 additions & 0 deletions src/lib/pubkey/classic_mceliece/cmce_parameter_set.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <botan/cmce_parameter_set.h>

namespace Botan {

Classic_McEliece_Parameter_Set param_set_from_str(std::string_view param_name) {
if(param_name == "mceliece348864") {
return Classic_McEliece_Parameter_Set::mceliece348864;
}
if(param_name == "mceliece348864f") {
return Classic_McEliece_Parameter_Set::mceliece348864f;
}
if(param_name == "mceliece460896") {
return Classic_McEliece_Parameter_Set::mceliece460896;
}
if(param_name == "mceliece460896f") {
return Classic_McEliece_Parameter_Set::mceliece460896f;
}
if(param_name == "mceliece6688128") {
return Classic_McEliece_Parameter_Set::mceliece6688128;
}
if(param_name == "mceliece6688128f") {
return Classic_McEliece_Parameter_Set::mceliece6688128f;
}
if(param_name == "mceliece6688128pc") {
return Classic_McEliece_Parameter_Set::mceliece6688128pc;
}
if(param_name == "mceliece6688128pcf") {
return Classic_McEliece_Parameter_Set::mceliece6688128pcf;
}
if(param_name == "mceliece6960119") {
return Classic_McEliece_Parameter_Set::mceliece6960119;
}
if(param_name == "mceliece6960119f") {
return Classic_McEliece_Parameter_Set::mceliece6960119f;
}
if(param_name == "mceliece6960119pc") {
return Classic_McEliece_Parameter_Set::mceliece6960119pc;
}
if(param_name == "mceliece6960119pcf") {
return Classic_McEliece_Parameter_Set::mceliece6960119pcf;
}
if(param_name == "mceliece8192128") {
return Classic_McEliece_Parameter_Set::mceliece8192128;
}
if(param_name == "mceliece8192128f") {
return Classic_McEliece_Parameter_Set::mceliece8192128f;
}
if(param_name == "mceliece8192128pc") {
return Classic_McEliece_Parameter_Set::mceliece8192128pc;
}
if(param_name == "mceliece8192128pcf") {
return Classic_McEliece_Parameter_Set::mceliece8192128pcf;
}
// TODO: Remove on final PR
if(param_name == "test") {
return Classic_McEliece_Parameter_Set::test;
}
if(param_name == "testf") {
return Classic_McEliece_Parameter_Set::testf;
}
if(param_name == "testpc") {
return Classic_McEliece_Parameter_Set::testpc;
}
if(param_name == "testpcf") {
return Classic_McEliece_Parameter_Set::testpcf;
}

throw Decoding_Error("Cannot convert string to CMCE parameter set");
}

std::string str_from_param_set(Classic_McEliece_Parameter_Set param) {
switch(param) {
case Classic_McEliece_Parameter_Set::mceliece348864:
return "mceliece348864";
case Classic_McEliece_Parameter_Set::mceliece348864f:
return "mceliece348864f";
case Classic_McEliece_Parameter_Set::mceliece460896:
return "mceliece460896";
case Classic_McEliece_Parameter_Set::mceliece460896f:
return "mceliece460896f";
case Classic_McEliece_Parameter_Set::mceliece6688128:
return "mceliece6688128";
case Classic_McEliece_Parameter_Set::mceliece6688128f:
return "mceliece6688128f";
case Classic_McEliece_Parameter_Set::mceliece6688128pc:
return "mceliece6688128pc";
case Classic_McEliece_Parameter_Set::mceliece6688128pcf:
return "mceliece6688128pcf";
case Classic_McEliece_Parameter_Set::mceliece6960119:
return "mceliece6960119";
case Classic_McEliece_Parameter_Set::mceliece6960119f:
return "mceliece6960119f";
case Classic_McEliece_Parameter_Set::mceliece6960119pc:
return "mceliece6960119pc";
case Classic_McEliece_Parameter_Set::mceliece6960119pcf:
return "mceliece6960119pcf";
case Classic_McEliece_Parameter_Set::mceliece8192128:
return "mceliece8192128";
case Classic_McEliece_Parameter_Set::mceliece8192128f:
return "mceliece8192128f";
case Classic_McEliece_Parameter_Set::mceliece8192128pc:
return "mceliece8192128pc";
case Classic_McEliece_Parameter_Set::mceliece8192128pcf:
return "mceliece8192128pcf";
// TODO: Remove on final PR
case Classic_McEliece_Parameter_Set::test:
return "test";
case Classic_McEliece_Parameter_Set::testf:
return "testf";
case Classic_McEliece_Parameter_Set::testpc:
return "testpc";
case Classic_McEliece_Parameter_Set::testpcf:
return "testpcf";
default:
throw Decoding_Error("Parameter set not supported");
}
BOTAN_ASSERT_UNREACHABLE();
}

Classic_McEliece_Parameter_Set param_set_from_oid(const OID& oid) {
return param_set_from_str(oid.to_formatted_string());
}

} // namespace Botan
69 changes: 69 additions & 0 deletions src/lib/pubkey/classic_mceliece/cmce_parameter_set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef CMCE_PARAMETER_SET_H
#define CMCE_PARAMETER_SET_H

#include <botan/oids.h>

namespace Botan {

/**
* All Classic McEliece parameter sets defined in the NIST Round 4
* submission and the Classic McEliece ISO Draft.
*
* Instances are defined in the following format:
* mceliece{n}{t}{[pc]}{[f]}
*
* Instance with 'pc' use plaintext confirmation as defined in the ISO Draft.
* Instance with 'f' use matrix reduction with the semi-systematic form.
*/
enum class Classic_McEliece_Parameter_Set {
mceliece348864, // NIST
mceliece348864f, // NIST

mceliece460896, // NIST
mceliece460896f, // NIST

mceliece6688128, // ISO + NIST
mceliece6688128f, // ISO + NIST
mceliece6688128pc, // ISO
mceliece6688128pcf, // ISO

mceliece6960119, // ISO + NIST
mceliece6960119f, // ISO + NIST
mceliece6960119pc, // ISO
mceliece6960119pcf, // ISO

mceliece8192128, // ISO + NIST
mceliece8192128f, // ISO + NIST
mceliece8192128pc, // ISO
mceliece8192128pcf, // ISO

toy,
/// Self-created test instance: m=8, n=128, t=8, f(z)=z^8+z^7+z^2+z+1, F(y)=y^8+y^4+y^3+y^2+1
/// Minimal instance without semi-systematic matrix creation and no plaintext confirmation
test,
/// Minimal instance with semi-systematic matrix creation and no plaintext confirmation
testf,
/// Minimal instance without semi-systematic matrix creation and with plaintext confirmation
testpc,
/// Minimal instance with semi-systematic matrix creation and with plaintext confirmation
testpcf
};

/**
* @brief Get the parameter set for a given parameter set name.
*/
Classic_McEliece_Parameter_Set param_set_from_str(std::string_view param_name);

/**
* @brief Get the parameter set name for a given parameter set.
*/
std::string str_from_param_set(Classic_McEliece_Parameter_Set param);

/**
* @brief Get the parameter set for a given OID.
*/
Classic_McEliece_Parameter_Set param_set_from_oid(const OID& oid);

} // namespace Botan

#endif // CMCE_PARAMETER_SET_H
Loading

0 comments on commit 63c1b8c

Please sign in to comment.