Botan 3.14.1
Crypto and TLS for C&
Botan Namespace Reference

Namespaces

namespace  ARIA_AVX512
namespace  ARIA_F
namespace  ARIA_HWAES
namespace  ASN1
namespace  BLS12_381
namespace  Camellia_AVX2_GFNI
namespace  Camellia_AVX512
namespace  Camellia_F
namespace  Camellia_HWAES
namespace  Cert_Extension
namespace  CMCE_CT
namespace  concepts
namespace  CryptoBox
namespace  CRYSTALS
namespace  CT
namespace  detail
namespace  Dilithium_Algos
namespace  fmt_detail
namespace  FPE
namespace  HPKE
namespace  HTTP
namespace  HWRNG
namespace  KeyPair
namespace  Kuznyechik_F
namespace  Kyber_Algos
namespace  Kyber_AVX2
namespace  OCSP
namespace  OIDS
namespace  OS
namespace  PCurve
namespace  PEM_Code
namespace  PK_Ops
namespace  PKCS11
namespace  PKCS8
namespace  PKIX
namespace  ranges
namespace  Roughtime
namespace  SEED_AVX512_GFNI
namespace  SEED_HWAES
namespace  Serpent_F
namespace  SHA1_F
namespace  SHA512_AVX512
namespace  SHACAL2_AVX512_F
namespace  SHACAL2_SIMD8x32_F
namespace  SM4_AVX512_GFNI
namespace  Sodium
namespace  SPAKE2p
namespace  Threefish_F
namespace  TLS
namespace  TPM2
namespace  Twofish_AVX512
namespace  Twofish_KS
namespace  WhirlpoolAVX512
namespace  WhirlpoolSIMD8x32
namespace  X509

Classes

class  Adler32
class  AEAD_Mode
class  AES_128
class  AES_192
class  AES_256
class  AES_256_CTR_XOF
class  AffineCurvePoint
class  Algorithm_Not_Found
class  AlgorithmIdentifier
class  AlgorithmMatch
class  AlgorithmPattern
class  AlgorithmSpec
class  AlignmentBuffer
 Alignment buffer helper. More...
struct  all_same
class  Allocator_Initializer
class  AlternativeName
class  ANSI_X919_MAC
class  ANSI_X923_Padding
class  Argon2
class  Argon2_Family
class  ARIA_128
class  ARIA_192
class  ARIA_256
class  Ascon_AEAD128_Decryption
class  Ascon_AEAD128_Encryption
class  Ascon_AEAD128_Mode
class  Ascon_Hash256
class  Ascon_p
class  Ascon_XOF128
class  ASN1_BitString
class  ASN1_Formatter
class  ASN1_Object
class  ASN1_Pretty_Printer
class  ASN1_String
class  ASN1_Time
class  Asymmetric_Key
class  Atomic
class  Attribute
class  AutoSeeded_RNG
class  Barrett_Reduction
class  Barrier
class  Base64_Decoder
class  Base64_Encoder
class  Bcrypt_PBKDF
class  Bcrypt_PBKDF_Family
class  BER_Bad_Tag
class  BER_Decoder
class  BER_Decoding_Error
class  BER_Object
class  BigInt
class  BitBucket
class  bitvector_base
class  BLAKE2b
class  BLAKE2bMAC
class  BLAKE2s
class  BlindedScalarBits
class  Blinder
class  BlindingRandomness
class  Block_Cipher_Fixed_Params
class  BlockCipher
class  BlockCipherModePaddingMethod
class  Blowfish
class  Buffered_Computation
class  Buffered_Filter
class  BufferSlicer
class  BufferStuffer
 Helper class to ease in-place marshalling of concatenated fixed-length values. More...
class  Bzip2_Compression
class  Bzip2_Decompression
class  calendar_point
class  Camellia_128
class  Camellia_192
class  Camellia_256
class  Cascade_Cipher
class  CAST_128
class  CBC_Decryption
class  CBC_Encryption
class  CBC_Mode
class  CCM_Decryption
class  CCM_Encryption
class  CCM_Mode
class  Certificate_Extension
class  Certificate_Store
class  Certificate_Store_In_Memory
class  Certificate_Store_In_SQL
class  Certificate_Store_In_SQLite
class  Certificate_Store_MacOS
class  Certificate_Store_Windows
class  CFB_Decryption
class  CFB_Encryption
class  CFB_Mode
class  ChaCha
class  ChaCha20Poly1305_Decryption
class  ChaCha20Poly1305_Encryption
class  ChaCha20Poly1305_Mode
class  ChaCha_RNG
class  Chain
class  CharacterValidityTable
class  Cipher_Mode
class  Cipher_Mode_Filter
class  Classic_McEliece_Decryptor
class  Classic_McEliece_Encryptor
class  Classic_McEliece_Field_Ordering
 Represents a field ordering for the Classic McEliece cryptosystem. More...
class  Classic_McEliece_GF
 Represents an element of the finite field GF(q) for q = 2^m. More...
struct  Classic_McEliece_KeyPair_Internal
 Representation of a Classic McEliece key pair. More...
class  Classic_McEliece_Matrix
 Representation of the binary Classic McEliece matrix H, with H = (I_mt | T). More...
class  Classic_McEliece_Minimal_Polynomial
 Representation of a minimal polynomial in GF(q)[y]. More...
class  Classic_McEliece_Parameter_Set
class  Classic_McEliece_Parameters
class  Classic_McEliece_Polynomial
 Representation of a Classic McEliece polynomial. More...
class  Classic_McEliece_Polynomial_Ring
 Represents the polynomial ring GF(q)[y]/F(y) where F(y) is the modulus polynomial in GF(q)[y] of degree t. More...
class  Classic_McEliece_PrivateKey
class  Classic_McEliece_PrivateKeyInternal
 Representation of a Classic McEliece private key. More...
class  Classic_McEliece_PublicKey
class  Classic_McEliece_PublicKeyInternal
 Representation of a Classic McEliece public key. More...
class  CMAC
class  Comb4P
class  CommonCrypto_Error
struct  CommonCryptor_Opts
class  Compression_Algorithm
class  Compression_Alloc_Info
class  Compression_Error
class  Compression_Stream
class  CPUFeature
class  CPUID
class  CRC24
class  CRC32
class  Credentials_Manager
class  CRL_Entry
class  cSHAKE_128_XOF
class  cSHAKE_256_XOF
class  cSHAKE_XOF
class  CTR_BE
class  CTS_Decryption
class  CTS_Encryption
class  CurveGFp
class  DataSink
class  DataSink_Stream
class  DataSource
class  DataSource_Memory
class  DataSource_Stream
class  Decoding_Error
class  Decompression_Algorithm
class  Deflate_Compression
class  Deflate_Decompression
class  DER_Encoder
class  DES
class  DH_PrivateKey
class  DH_PublicKey
class  Dilithium_AES_Symmetric_Primitives
class  Dilithium_Expanded_Keypair_Codec
class  Dilithium_Keypair_Codec
class  Dilithium_PrivateKey
class  Dilithium_PrivateKeyInternal
class  Dilithium_PublicKey
class  Dilithium_PublicKeyInternal
class  Dilithium_Round3_Symmetric_Primitives
class  Dilithium_Symmetric_Primitives
class  Dilithium_Symmetric_Primitives_Base
class  DilithiumConstants
struct  DilithiumDecodedKeypair
 A decoded private key together with the encoding format it was found in. More...
class  DilithiumMessageHash
class  DilithiumMode
class  DilithiumPolyTraits
class  DilithiumShakeXOF
class  DilithiumXOF
struct  DistributionPointMatch
class  divide_precomp
class  DL_Group
class  DL_PrivateKey
class  DL_PublicKey
class  DLIES_Decryptor
class  DLIES_Encryptor
class  DNSName
class  donna128
class  DSA_PrivateKey
class  DSA_PublicKey
class  Dynamically_Loaded_Library
class  EAX_Decryption
class  EAX_Encryption
class  EAX_Mode
class  EC_AffinePoint
class  EC_AffinePoint_Data
class  EC_AffinePoint_Data_BN
class  EC_AffinePoint_Data_PC
class  EC_Group
class  EC_Group_Data
class  EC_Mul2Table_Data
class  EC_Mul2Table_Data_BN
class  EC_Mul2Table_Data_PC
class  EC_Point
class  EC_Point_Base_Point_Precompute
class  EC_Point_Multi_Point_Precompute
class  EC_Point_Var_Point_Precompute
class  EC_PrivateKey
class  EC_PrivateKey_Data
class  EC_PublicKey
class  EC_PublicKey_Data
class  EC_Scalar
class  EC_Scalar_Data
class  EC_Scalar_Data_BN
class  EC_Scalar_Data_PC
class  ECDH_PrivateKey
class  ECDH_PublicKey
class  ECDSA_PrivateKey
class  ECDSA_PublicKey
class  ECGDSA_PrivateKey
class  ECGDSA_PublicKey
class  ECIES_Decryptor
class  ECIES_Encryptor
class  ECIES_KA_Operation
class  ECIES_KA_Params
class  ECIES_System_Params
class  ECKCDSA_PrivateKey
class  ECKCDSA_PublicKey
class  Ed25519_FieldElement
class  Ed25519_PrivateKey
class  Ed25519_PublicKey
class  Ed25519_Scalar
class  Ed448_PrivateKey
 A private key for Ed448/Ed448ph according to RFC 8032. More...
class  Ed448_PublicKey
 A public key for Ed448/Ed448ph according to RFC 8032. More...
class  Ed448Point
 Representation of a point on the Ed448 curve. More...
struct  eea_result
class  ElGamal_PrivateKey
class  ElGamal_PublicKey
class  EllipticCurve
class  EllipticCurveParameters
class  EmailAddress
class  EME_PKCS1v15
class  EME_Raw
struct  EnableArithmeticWithPlainNumber
class  Encoding_Error
class  Encrypted_PSK_Database
class  Encrypted_PSK_Database_SQL
class  EncryptionPaddingScheme
class  Entropy_Accumulator
class  Entropy_Source
class  Entropy_Sources
class  ESDM_RNG
class  ESP_Padding
class  Exception
class  Expanded_Keypair_Codec
 Codec for expanded private keys (as specified in FIPS 203). More...
class  Extensions
class  Fanout_Filter
class  Filter
class  Flatfile_Certificate_Store
class  Fork
class  FPE_FE1
class  FrodoKEM_PrivateKey
class  FrodoKEM_PublicKey
class  FrodoKEMConstants
class  FrodoKEMMode
class  FrodoMatrix
class  GCM_Decryption
class  GCM_Encryption
class  GCM_Mode
class  GCM_SIV_Decryption
class  GCM_SIV_Encryption
class  GCM_SIV_Mode
class  GeneralName
 X.509 GeneralName Type. More...
class  GeneralSubtree
 A single Name Constraint. More...
class  Getentropy
class  Gf2AffineTransformation
class  GF2m_Field
class  Gf448Elem
class  GF_Mask
 Constant time mask wrapper for GF(q) elements. More...
class  GHASH
class  GMAC
class  GOST_28147_89
class  GOST_28147_89_Params
class  GOST_3410_PrivateKey
class  GOST_3410_PublicKey
class  GOST_34_11
class  Gzip_Compression
class  Gzip_Decompression
class  Hardware_RNG
class  Hash_Engine
class  HashFunction
class  Hex_Decoder
class  Hex_Encoder
class  HKDF
class  HKDF_Expand
class  HKDF_Extract
class  HMAC
class  HMAC_DRBG
class  HOTP
class  HSS_LMS_Params
 The HSS-LMS parameters. More...
class  HSS_LMS_PrivateKey
 An HSS/LMS private key. More...
class  HSS_LMS_PrivateKeyInternal
 The internal HSS-LMS private key. More...
class  HSS_LMS_PublicKey
 An HSS/LMS public key. More...
class  HSS_LMS_PublicKeyInternal
 The internal HSS-LMS public key. More...
class  HSS_Signature
 A HSS-LMS signature. More...
class  Hybrid_PrivateKey
 Abstraction for a combined KEM private key. More...
class  Hybrid_PublicKey
 Abstraction for a combined KEM public key. More...
class  IDEA
class  Intel_Rdseed
class  Internal_Error
class  IntMod
struct  IntParams
class  Invalid_Algorithm_Name
class  Invalid_Argument
class  Invalid_Authentication_Tag
class  Invalid_IV_Length
class  Invalid_Key_Length
class  Invalid_State
class  IPv4Address
class  IPv4Subnet
class  IPv6Address
class  IPv6Subnet
struct  is_bitvector
struct  is_bitvector< bitvector_base< T > >
struct  is_strong_span
struct  is_strong_span< StrongSpan< T > >
struct  is_strong_type
struct  is_strong_type< Strong< Ts... > >
class  ISO_9796_DS2
class  ISO_9796_DS3
class  Jitter_RNG
class  Joining_Future
class  KDF
class  KDF1
class  KDF1_18033
class  KDF2
class  Keccak_1600
class  Keccak_Permutation
struct  KeccakPadding
class  KEM_Decryption_with_Combiner
 Abstract interface for a KEM decryption operation for KEM combiners. More...
class  KEM_Encapsulation
class  KEM_Encryption_with_Combiner
 Abstract interface for a KEM encryption operation for KEM combiners. More...
class  KEX_to_KEM_Adapter_PrivateKey
class  KEX_to_KEM_Adapter_PublicKey
class  Key_Constraints
class  Key_Length_Specification
class  Key_Not_Set
class  Keyed_Filter
class  KMAC
class  KMAC128
class  KMAC256
class  Kuznyechik
class  Kyber_90s_Symmetric_Primitives
class  Kyber_KEM_Decryptor
class  Kyber_KEM_Decryptor_Base
class  Kyber_KEM_Encryptor
class  Kyber_KEM_Encryptor_Base
class  Kyber_KEM_Operation_Base
class  Kyber_Keypair_Codec
class  Kyber_Modern_Symmetric_Primitives
class  Kyber_PrivateKey
class  Kyber_PrivateKeyInternal
class  Kyber_PublicKey
class  Kyber_PublicKeyInternal
class  Kyber_Symmetric_Primitives
class  KyberConstants
struct  KyberDecodedKeypair
 A decoded private key together with the encoding format it was found in. More...
class  KyberMode
class  KyberPolyTraits
struct  KyberPrivateKeySeed
class  Lion
class  LMOTS_Params
 The LM-OTS parameters. More...
class  LMOTS_Private_Key
 Representation of an LMOTS private key. More...
class  LMOTS_Public_Key
 Representation of an OTS public key. More...
class  LMOTS_Signature
 Representation of a LM-OTS signature. More...
class  LMS_Instance
 Base class for LMS private and public key. Contains public data associated with this LMS instance. More...
class  LMS_Params
 The LMS parameters. More...
class  LMS_PrivateKey
 Representation of an LMS Private key. More...
class  LMS_PublicKey
 The LMS public key. More...
class  LMS_Signature
 Container for LMS Signature data. More...
class  lock_guard
class  Lookup_Error
class  LZMA_Compression
class  LZMA_Decompression
struct  McEliece_Params
class  McEliece_PrivateKey
class  McEliece_PrivateKeyInternal
class  McEliece_PublicKey
class  McEliece_PublicKeyInternal
class  MD4
class  MD5
class  MDx_MB_Engine
class  Memory_Pool
class  MerkleDamgard_Hash
class  MessageAuthenticationCode
class  ML_DSA_Expanding_Keypair_Codec
class  ML_DSA_MessageHash
class  ML_DSA_Symmetric_Primitives
class  ML_KEM_Decryptor
class  ML_KEM_Encryptor
class  ML_KEM_Symmetric_Primitives
class  mlock_allocator
class  Modular_Reducer
class  Module_Lattice_PrivateKey
class  Montgomery_Exponentiation_State
class  Montgomery_Int
class  Montgomery_Params
class  MontgomeryRep
class  NameConstraints
 Name Constraints. More...
class  No_Filesystem_Access
class  Noekeon
class  noop_mutex
class  Not_Implemented
class  Null_Padding
class  Null_RNG
class  OAEP
class  OCB_Decryption
class  OCB_Encryption
class  OCB_Mode
class  OctetString
class  OFB
class  OID
class  OID_Map
class  OneAndZeros_Padding
class  OpenPGP_S2K
class  OTS_Instance
 Base class for LMOTS private and public key. Contains the parameters for the specific OTS instance. More...
class  Output_Buffers
struct  overloaded
class  Parallel
class  PasswordHash
class  PasswordHashFamily
class  Path_Validation_Restrictions
class  Path_Validation_Result
class  PBKDF
class  PBKDF2
class  PBKDF2_Family
class  Pipe
class  PK_Decryptor
class  PK_Decryptor_EME
class  PK_Encryption_Options
class  PK_Encryption_Options_Reader
class  PK_Encryptor
class  PK_Encryptor_EME
class  PK_KEM_Decryptor
class  PK_KEM_Encryptor
class  PK_KEM_Options
class  PK_KEM_Options_Reader
class  PK_Key_Agreement
class  PK_Key_Agreement_Key
class  PK_Key_Agreement_Options
class  PK_Key_Agreement_Options_Reader
class  PK_Options_Reader_Access
class  PK_Signature_Options
class  PK_Signature_Options_Reader
class  PK_Signer
class  PK_Verifier
class  PKCS10_Request
class  PKCS12
class  PKCS12_Export_Options
class  PKCS12_KDF
class  PKCS12_KDF_Family
class  PKCS1v15_Raw_SignaturePaddingScheme
class  PKCS1v15_SignaturePaddingScheme
class  PKCS5_PBKDF2
class  PKCS7_Padding
class  PKCS8_Exception
class  Poly1305
class  polyn_gf2m
class  Polyval
class  PrecomputedBaseMulTable
class  Private_Key
class  PRNG_Unseeded
class  Processor_RNG
class  ProjectiveCurvePoint
class  Provider_Not_Found
class  PseudorandomKeyGeneration
 Helper class used to derive secret values based in the pseudorandom key generation described in RFC 8554 Appendix A. More...
class  PSK_Database
class  PSS_Params
class  PSS_Raw
class  PSSR
class  Public_Key
class  RandomNumberGenerator
class  RawHashFunction
class  RC4
class  ReasonFlags
class  RFC4880_S2K
class  RFC4880_S2K_Family
class  RFC6979_Nonce_Generator
class  RIPEMD_160
class  RSA_PrivateKey
class  RSA_PublicKey
class  RTSS_Share
class  RWLock
class  Salsa20
class  Scalar448
 Representation of a scalar for X448. More...
class  scoped_cleanup
 Helper class to create a RAII-style cleanup callback. More...
class  Scrypt
class  Scrypt_Family
class  secure_allocator
class  SecureQueue
class  SEED
class  Seed_Expanding_Keypair_Codec
 Codec for private keys as 64-byte seeds: d || z. More...
class  Semaphore
class  Serpent
class  SHA_1
class  SHA_224
class  SHA_256
class  SHA_3
class  SHA_384
class  SHA_3_224
class  SHA_3_256
class  SHA_3_384
class  SHA_3_512
class  SHA_512
class  SHA_512_256
class  SHACAL2
class  SHAKE_128
class  SHAKE_128_Cipher
class  SHAKE_128_XOF
class  SHAKE_256
class  SHAKE_256_Cipher
class  SHAKE_256_XOF
class  SHAKE_Cipher
class  SHAKE_XOF
class  SharedZPointTable
class  SignaturePaddingScheme
class  SignRawBytes
class  SIMD_16x32
class  SIMD_2x64
class  SIMD_4x32
class  SIMD_4x64
class  SIMD_8x32
class  SIMD_8x64
class  SipHash
class  SIV_Decryption
class  SIV_Encryption
class  SIV_Mode
class  Skein_512
class  SM2_PrivateKey
class  SM2_PublicKey
class  SM3
class  SM4
class  SmtpUtf8Mailbox
class  SolinasAccum
class  SP800_108_Counter
class  SP800_108_Feedback
class  SP800_108_Pipeline
class  SP800_56A_One_Step_KMAC_Abstract
class  SP800_56C_One_Step_Hash
class  SP800_56C_One_Step_HMAC
class  SP800_56C_One_Step_KMAC128
class  SP800_56C_One_Step_KMAC256
class  SP800_56C_Two_Step
class  Sphincs_Address
class  Sphincs_Hash_Functions
class  Sphincs_Hash_Functions_Sha2
class  Sphincs_Hash_Functions_Shake
class  Sphincs_Parameters
struct  SphincsMessageInternal
 M' representation of FIPS 205 (the input to slh_sign_internal and slh_verify_internal). More...
class  SphincsPlus_PrivateKey
 An SLH-DSA private key. More...
class  SphincsPlus_PublicKey
 An SLH-DSA (or SPHINCS+ Round 3.1) public key. More...
class  Sponge
class  SQL_Database
class  Sqlite3_Database
class  SRP6_Server_Session
class  Stateful_Key_Index_Registry
class  Stateful_RNG
class  Stream_Compression
class  Stream_Decompression
class  Stream_IO_Error
class  StreamCipher
class  Streebog
class  StringLiteral
class  Strong
class  StrongSpan
class  SymmetricAlgorithm
class  System_Certificate_Store
class  System_Error
class  System_RNG
class  TelephoneNumber
class  TelephoneNumberRange
class  Thread_Pool
class  Threefish_512
class  TLS_12_PRF
class  TOTP
class  TPM_Context
class  TPM_Error
class  TPM_PrivateKey
class  TPM_RNG
class  TripleDES
class  Truncated_Hash
class  Tweakable_Block_Cipher
class  Twofish
class  UnblindedScalarBits
class  Unknown_PK_Field_Name
class  URI
class  UUID
struct  variant_append
struct  variant_append< std::variant< Ts... >, T >
class  VartimeMul2Table
class  Whirlpool
class  Win32_EntropySource
class  WnafScalar
class  word3
struct  WordInfo
struct  WordInfo< uint32_t >
struct  WordInfo< uint64_t >
class  Work_Executor
class  X25519_FE
class  X25519_PrivateKey
class  X25519_PublicKey
class  X448_PrivateKey
 A private key for the X448 key agreement scheme according to RFC 7748. More...
class  X448_PublicKey
 A public key for the X448 key agreement scheme according to RFC 7748. More...
class  X509_CA
class  X509_Cert_Options
class  X509_Certificate
class  X509_Certificate_Cache
class  X509_CRL
class  X509_DN
class  X509_Object
class  X509_Serial_Number
class  X931_SignaturePadding
class  X942_PRF
class  XMSS_Address
class  XMSS_Common_Ops
class  XMSS_Hash
class  XMSS_Parameters
class  XMSS_PrivateKey
class  XMSS_PublicKey
class  XMSS_Signature
class  XMSS_Signature_Operation
class  XMSS_Tree_Builder
struct  XMSS_TreeSignature
class  XMSS_Verification_Operation
class  XMSS_WOTS_Base
class  XMSS_WOTS_Parameters
class  XMSS_WOTS_PrivateKey
class  XMSS_WOTS_PublicKey
class  XOF
class  XTS_Decryption
class  XTS_Encryption
class  XTS_Mode
class  ZFEC
class  Zlib_Compression
class  Zlib_Decompression
class  Zlib_Style_Stream

Concepts

concept  absorbing_object
concept  appendable_object
concept  bitvectorish
concept  curve_supports_fe_invert2
concept  curve_supports_fe_sqrt
concept  md_hash_implementation
concept  updatable_object
concept  WordType

Typedefs

using bitvector = bitvector_base<std::allocator>
template<size_t bound>
using Bounded_XOF = detail::Bounded_XOF<XOF&, bound>
using byte = std::uint8_t
 Unsigned 8 bit integer; retained for compatibility with older versions.
typedef int32_t CCCryptorStatus
typedef std::vector< std::set< Certificate_Status_Code > > CertificatePathStatusCodes
using CmceCodeWord = Strong<secure_bitvector, struct CmceCodeWord_>
 Represents C of decapsulation.
using CmceColumnSelection = Strong<secure_bitvector, struct CmceColumnSelection_>
 Represents c of private key.
using CmceErrorVector = Strong<secure_bitvector, struct CmceErrorVector_>
 Represents e of encapsulation.
using CmceGfElem = Strong<uint16_t, struct CmceGfElem_>
 Represents a GF(q) element.
using CmceGfMod = Strong<uint16_t, struct CmceGfMod_>
 Represents a GF(q) modulus.
using CmceInitialSeed = Strong<secure_vector<uint8_t>, struct CmceInitialSeed_>
 Represents initial delta of keygen.
using CmceIrreducibleBits = Strong<secure_vector<uint8_t>, struct CmceIrreducibleBits_>
using CmceKeyGenSeed = Strong<secure_vector<uint8_t>, struct CmceKeyGenSeed_>
 Represents a delta (can be altered; final value stored in private key).
using CmceOrderingBits = Strong<secure_vector<uint8_t>, struct CmceOrderingBits_>
using CmcePermutation = Strong<secure_vector<uint16_t>, struct CmcePermutation_>
 Represents a permutation (pi in spec). Used in field ordering creation.
using CmcePermutationElement = Strong<uint16_t, struct CmcePermutationElement_>
 Represents an element of a permutation (pi in spec). Used in field ordering creation.
using CmceRejectionSeed = Strong<secure_vector<uint8_t>, struct CmceRejectionSeed_>
 Represents s of private key.
typedef X25519_PrivateKey Curve25519_PrivateKey
typedef X25519_PublicKey Curve25519_PublicKey
using DilithiumCommitmentHash = Strong<std::vector<uint8_t>, struct DilithiumCommitmentHash_>
 Hash of the message representative and the signer's commitment.
using DilithiumHashedPublicKey = Strong<std::vector<uint8_t>, struct DilithiumHashedPublicKey_>
using DilithiumInternalKeypair
 Internal representation of a Dilithium key pair.
using DilithiumMessageRepresentative = Strong<std::vector<uint8_t>, struct DilithiumMessageRepresentative_>
 Representation of the message to be signed.
using DilithiumOptionalRandomness = Strong<secure_vector<uint8_t>, struct DilithiumOptionalRandomness_>
 Optional randomness 'rnd' used for rho prime computation in ML-DSA.
using DilithiumPoly = Botan::CRYSTALS::Polynomial<DilithiumPolyTraits, Botan::CRYSTALS::Domain::Normal>
using DilithiumPolyMatNTT = Botan::CRYSTALS::PolynomialMatrix<DilithiumPolyTraits>
using DilithiumPolyNTT = Botan::CRYSTALS::Polynomial<DilithiumPolyTraits, Botan::CRYSTALS::Domain::NTT>
using DilithiumPolyVec = Botan::CRYSTALS::PolynomialVector<DilithiumPolyTraits, Botan::CRYSTALS::Domain::Normal>
using DilithiumPolyVecNTT = Botan::CRYSTALS::PolynomialVector<DilithiumPolyTraits, Botan::CRYSTALS::Domain::NTT>
using DilithiumSeedRandomness = Strong<secure_vector<uint8_t>, struct DilithiumSeedRandomness_>
 Principal seed used to generate Dilithium key pairs.
using DilithiumSeedRho = Strong<std::vector<uint8_t>, struct DilithiumPublicSeed_>
 Public seed to sample the polynomial matrix A from.
using DilithiumSeedRhoPrime = Strong<secure_vector<uint8_t>, struct DilithiumSeedRhoPrime_>
 Private seed to sample the polynomial vectors s1 and s2 from.
using DilithiumSerializedCommitment = Strong<std::vector<uint8_t>, struct DilithiumSerializedCommitment_>
 Serialized representation of a commitment w1.
using DilithiumSerializedPrivateKey = Strong<secure_vector<uint8_t>, struct DilithiumSerializedPrivateKey_>
 Serialized private key data.
using DilithiumSerializedPublicKey = Strong<std::vector<uint8_t>, struct DilithiumSerializedPublicKey_>
 Serialized public key data (result of pkEncode(pk)).
using DilithiumSerializedSignature = Strong<std::vector<uint8_t>, struct DilithiumSerializedSignature_>
 Serialized signature data.
using DilithiumSigningSeedK = Strong<secure_vector<uint8_t>, struct DilithiumSeedK_>
 Private seed K used during signing.
using ForsLeafSecret = Strong<secure_vector<uint8_t>, struct ForsLeafSecret_>
using ForsSignature = Strong<std::vector<uint8_t>, struct ForsSignature_>
using FrodoDomainSeparator = Strong<std::array<uint8_t, 1>, struct FrodoDomainSeparator_>
using FrodoIntermediateSharedSecret = Strong<secure_vector<uint8_t>, struct FrodoIntermediateSharedSecret_>
using FrodoPackedMatrix = Strong<std::vector<uint8_t>, struct FrodoPackedMatrix_>
using FrodoPlaintext = Strong<secure_vector<uint8_t>, struct FrodoPlaintext_>
using FrodoPublicKeyHash = Strong<std::vector<uint8_t>, struct FrodoPublicKeyHash_>
using FrodoSalt = Strong<std::vector<uint8_t>, struct FrodoSalt_>
using FrodoSampleR = Strong<secure_vector<uint8_t>, struct FrodoSampleR_>
using FrodoSeedA = Strong<std::vector<uint8_t>, struct FrodoSeedA_>
using FrodoSeedS = Strong<secure_vector<uint8_t>, struct FrodoSeedS_>
using FrodoSeedSE = Strong<secure_vector<uint8_t>, struct FrodoSeedSE_>
using FrodoSeedZ = Strong<std::vector<uint8_t>, struct FrodoSeedZ_>
using FrodoSerializedMatrix = Strong<secure_vector<uint8_t>, struct FrodoSerializedMatrix_>
using GenerateLeavesFunction
typedef uint16_t gf2m
using HSS_Level = Strong<uint32_t, struct HSS_Level_, EnableArithmeticWithPlainNumber>
 The HSS layer in the HSS multi tree starting at 0 from the root.
using HSS_Sig_Idx = Strong<uint64_t, struct HSS_Sig_Idx_, EnableArithmeticWithPlainNumber>
 The index of a node within a specific LMS tree layer.
using HypertreeLayerIndex = Strong<uint32_t, struct HypertreeLayerIndex_>
 Index of a layer in the XMSS hyper-tree.
using InitializationVector = OctetString
typedef Invalid_Authentication_Tag Integrity_Failure
using KyberCompressedCiphertext = Strong<std::vector<uint8_t>, struct KyberCompressedCiphertext_>
 Compressed and serialized ciphertext value.
using KyberEncryptionRandomness = Strong<secure_vector<uint8_t>, struct KyberEncryptionRandomness_>
 Random value used to generate the Kyber ciphertext.
using KyberHashedCiphertext = Strong<std::vector<uint8_t>, struct KyberHashedCiphertext_>
using KyberHashedPublicKey = Strong<std::vector<uint8_t>, struct KyberHashedPublicKey_>
 Hash value of the serialized public key.
using KyberImplicitRejectionValue = Strong<secure_vector<uint8_t>, struct KyberImplicitRejectionValue_>
 Secret random value (called Z in the spec), used for implicit rejection in the decapsulation.
using KyberInternalKeypair
using KyberMessage = Strong<secure_vector<uint8_t>, struct KyberMessage_>
 Random message value to be encrypted by the CPA-secure Kyber encryption scheme.
using KyberPoly = Botan::CRYSTALS::Polynomial<KyberPolyTraits, Botan::CRYSTALS::Domain::Normal>
using KyberPolyMat = Botan::CRYSTALS::PolynomialMatrix<KyberPolyTraits>
using KyberPolyNTT = Botan::CRYSTALS::Polynomial<KyberPolyTraits, Botan::CRYSTALS::Domain::NTT>
using KyberPolyVec = Botan::CRYSTALS::PolynomialVector<KyberPolyTraits, Botan::CRYSTALS::Domain::Normal>
using KyberPolyVecNTT = Botan::CRYSTALS::PolynomialVector<KyberPolyTraits, Botan::CRYSTALS::Domain::NTT>
using KyberSamplingRandomness = Strong<secure_vector<uint8_t>, struct KyberSamplingRandomness_>
 PRF value used for sampling of error polynomials.
using KyberSeedRandomness = Strong<secure_vector<uint8_t>, struct KyberSeedRandomness_>
 Principal seed used to generate Kyber key pairs.
using KyberSeedRho = Strong<std::vector<uint8_t>, struct KyberSeedRho_>
 Public seed value to generate the Kyber matrix A.
using KyberSeedSigma = Strong<secure_vector<uint8_t>, struct KyberSeedSigma_>
 Private seed used to generate polynomial vectors s and e during key generation.
using KyberSerializedPublicKey = Strong<std::vector<uint8_t>, struct KyberSerializedPublicKey_>
 Public key in serialized form (t || rho).
using KyberSharedSecret = Strong<secure_vector<uint8_t>, struct KyberSharedSecret_>
 Shared secret value generated during encapsulation and recovered during decapsulation.
using KyberSigmaOrEncryptionRandomness
 Variant value of either a KyberSeedSigma or a KyberEncryptionRandomness.
using LMOTS_K = Strong<std::vector<uint8_t>, struct LMOTS_K_>
 The K value from the LM-OTS public key.
using LMOTS_Node = Strong<secure_vector<uint8_t>, struct LMOTS_Node_>
 One node within one LM-OTS hash chain.
using LMOTS_Signature_Bytes = Strong<std::vector<uint8_t>, struct LMOTS_Signature_Bytes_>
 Byte vector of an LM-OTS signature.
using LMS_AuthenticationPath = Strong<std::vector<uint8_t>, struct LMS_AuthenticationPath_>
 The authentication path of an LMS signature.
using LMS_Identifier = Strong<std::vector<uint8_t>, struct LMS_Identifier_>
 The identifier of an LMS tree (I in RFC 8554).
using LMS_Message = Strong<std::vector<uint8_t>, struct LMS_Message_>
 A message that is signed with an LMS tree.
using LMS_Seed = Strong<secure_vector<uint8_t>, struct LMS_SEED_>
 Seed of the LMS tree, used to generate the LM-OTS private keys.
using LMS_Signature_Bytes = Strong<std::vector<uint8_t>, struct LMS_Signature_Bytes_>
 Raw bytes of an LMS signature.
using LMS_Tree_Node = Strong<std::vector<uint8_t>, struct LMS_Tree_Node_>
 A node with the LMS tree.
using LMS_Tree_Node_Idx = Strong<uint32_t, struct LMS_Tree_Node_Idx_, EnableArithmeticWithPlainNumber>
 The index of a node within a specific LMS tree layer.
template<typename T>
using lock_guard_type = lock_guard<T>
typedef MessageAuthenticationCode MAC
using ML_DSA_Mode = DilithiumMode
using ML_DSA_PrivateKey = Dilithium_PrivateKey
using ML_DSA_PublicKey = Dilithium_PublicKey
using ML_KEM_Mode = KyberMode
using ML_KEM_PrivateKey = Kyber_PrivateKey
using ML_KEM_PublicKey = Kyber_PublicKey
using mutex_type = noop_mutex
template<std::signed_integral T>
using next_longer_int_t
template<std::unsigned_integral T>
using next_longer_uint_t
using Point448 = Strong<std::array<uint8_t, X448_LEN>, struct Point448_>
typedef EC_Point PointGFp
using recursive_mutex_type = noop_mutex
typedef RandomNumberGenerator RNG
typedef PBKDF S2K
using s32bit = std::int32_t
 Signed 32 bit integer; retained for compatibility with older versions.
using ScalarX448 = Strong<std::array<uint8_t, X448_LEN>, struct ScalarX448_>
using secure_bitvector = bitvector_base<secure_allocator>
template<typename T>
using secure_deque = std::deque<T, secure_allocator<T>>
template<typename T>
using secure_vector = std::vector<T, secure_allocator<T>>
template<typename T>
using SecureVector = secure_vector<T>
typedef SM2_PrivateKey SM2_Encryption_PrivateKey
typedef SM2_PublicKey SM2_Encryption_PublicKey
typedef SM2_PrivateKey SM2_Signature_PrivateKey
typedef SM2_PublicKey SM2_Signature_PublicKey
using SphincsAuthenticationPath = Strong<std::vector<uint8_t>, struct SphincsAuthenticationPath_>
using SphincsContext = Strong<std::vector<uint8_t>, struct SphincsContext_>
using SphincsHashedMessage = Strong<std::vector<uint8_t>, struct SphincsHashedMessage_>
using SphincsHypertreeSignature = Strong<std::vector<uint8_t>, struct SphincsXmssSignature_>
using SphincsInputMessage = Strong<std::vector<uint8_t>, struct SphincsInputMessage_>
using SphincsMessagePrefix = Strong<std::vector<uint8_t>, struct SphincsMessagePrefix_>
using SphincsMessageRandomness = Strong<secure_vector<uint8_t>, struct SphincsMessageRandomness_>
using SphincsOptionalRandomness = Strong<secure_vector<uint8_t>, struct SphincsOptionalRandomness_>
using SphincsPublicSeed = Strong<std::vector<uint8_t>, struct SphincsPublicSeed_>
using SphincsSecretPRF = Strong<secure_vector<uint8_t>, struct SphincsSecretPRF_>
using SphincsSecretSeed = Strong<secure_vector<uint8_t>, struct SphincsSecretSeed_>
using SphincsTreeNode = Strong<std::vector<uint8_t>, struct SphincsTreeNode_>
 Either an XMSS or FORS tree node or leaf.
using SphincsXmssSignature = Strong<std::vector<uint8_t>, struct SphincsXmssSignature_>
template<typename T>
using strong_type_wrapped_type = typename detail::wrapped_type_helper<std::remove_cvref_t<T>>::type
 Extracts the wrapped type from a strong type.
using SymmetricKey = OctetString
using TreeLayerIndex = Strong<uint32_t, struct TreeLayerIndex_, EnableArithmeticWithPlainNumber>
 Index of the layer within a FORS/XMSS tree.
using TreeNodeIndex = Strong<uint32_t, struct TreeNodeIndex_, EnableArithmeticWithPlainNumber>
 Index of an individual node inside an XMSS or FORS tree.
using u16bit = std::uint16_t
 Unsigned 16 bit integer; retained for compatibility with older versions.
using u32bit = std::uint32_t
 Unsigned 32 bit integer; retained for compatibility with older versions.
using u64bit = std::uint64_t
 Unsigned 64 bit integer; retained for compatibility with older versions.
typedef donna128 uint128_t
template<typename Variant, typename T>
using variant_append_t = typename variant_append<Variant, T>::type
 Converts a given variant into another variant with all its alternative types and an additional alternative type T.
using word = std::conditional_t<HasNative64BitRegisters, std::uint64_t, uint32_t>
 The native machine word, used as the limb type for multiprecision integers.
typedef std::vector< secure_vector< uint8_t > > wots_keysig_t
using WotsChainIndex = Strong<uint32_t, struct WotsChainIndex_>
 Index of a WOTS chain within a single usage of WOTS.
using WotsHashIndex = Strong<uint8_t, struct WotsHashIndex_, EnableArithmeticWithPlainNumber>
 Index of a hash application inside a single WOTS chain (integers in "base_w").
using WotsNode = Strong<secure_vector<uint8_t>, struct WotsNode_>
 Start (or intermediate) node of a WOTS+ chain.
using WotsPublicKey = Strong<std::vector<uint8_t>, struct WotsPublicKey_>
using WotsPublicKeyNode = Strong<std::vector<uint8_t>, struct WotsPublicKeyNode_>
 End node of a WOTS+ chain (part of the WOTS+ public key).
using WotsSignature = Strong<secure_vector<uint8_t>, struct WotsSignature_>
typedef ASN1_Time X509_Time
using XmssTreeIndexInLayer = Strong<uint64_t, struct XmssTreeIndexInLayer_, EnableArithmeticWithPlainNumber>
 Index of an XMSS tree (unique for just the local hyper-tree layer).

Enumerations

enum class  AlignmentBufferFinalBlock : uint8_t { is_not_special = 0 , must_be_deferred = 1 }
enum class  ASN1_Class : uint32_t {
  Universal = 0b0000'0000 , Application = 0b0100'0000 , ContextSpecific = 0b1000'0000 , Private = 0b1100'0000 ,
  Constructed = 0b0010'0000 , ExplicitContextSpecific = Constructed | ContextSpecific , NoObject = 0xFF00
}
enum class  ASN1_Type : uint32_t {
  Eoc = 0x00 , Boolean = 0x01 , Integer = 0x02 , BitString = 0x03 ,
  OctetString = 0x04 , Null = 0x05 , ObjectId = 0x06 , Enumerated = 0x0A ,
  Sequence = 0x10 , Set = 0x11 , Utf8String = 0x0C , NumericString = 0x12 ,
  PrintableString = 0x13 , TeletexString = 0x14 , Ia5String = 0x16 , VisibleString = 0x1A ,
  UniversalString = 0x1C , BmpString = 0x1E , UtcTime = 0x17 , GeneralizedTime = 0x18 ,
  NoObject = 0xFF00
}
enum class  Certificate_Status_Code : uint16_t {
  OK = 0 , VERIFIED = 0 , OCSP_RESPONSE_GOOD = 1 , OCSP_SIGNATURE_OK = 2 ,
  VALID_CRL_CHECKED = 3 , FIRST_WARNING_STATUS = 500 , CERT_SERIAL_NEGATIVE = 500 , DN_TOO_LONG = 501 ,
  OCSP_NO_REVOCATION_URL = 502 , OCSP_SERVER_NOT_AVAILABLE = 503 , TRUSTED_CERT_HAS_EXPIRED = 504 , TRUSTED_CERT_NOT_YET_VALID = 505 ,
  OCSP_NO_HTTP = 506 , FIRST_ERROR_STATUS = 1000 , SIGNATURE_METHOD_TOO_WEAK = 1000 , UNTRUSTED_HASH = 1001 ,
  NO_REVOCATION_DATA = 1002 , NO_MATCHING_CRLDP = 1003 , OCSP_ISSUER_NOT_TRUSTED = 1004 , CERT_NOT_YET_VALID = 2000 ,
  CERT_HAS_EXPIRED = 2001 , OCSP_NOT_YET_VALID = 2002 , OCSP_HAS_EXPIRED = 2003 , CRL_NOT_YET_VALID = 2004 ,
  CRL_HAS_EXPIRED = 2005 , OCSP_IS_TOO_OLD = 2006 , FIRST_ERROR_STATUS_TO_SKIP_REVOCATION = 3000 , CERT_ISSUER_NOT_FOUND = 3000 ,
  CANNOT_ESTABLISH_TRUST = 3001 , CERT_CHAIN_LOOP = 3002 , CHAIN_LACKS_TRUST_ROOT = 3003 , CHAIN_NAME_MISMATCH = 3004 ,
  POLICY_ERROR = 4000 , INVALID_USAGE = 4001 , CERT_CHAIN_TOO_LONG = 4002 , CA_CERT_NOT_FOR_CERT_ISSUER = 4003 ,
  NAME_CONSTRAINT_ERROR = 4004 , CA_CERT_NOT_FOR_CRL_ISSUER = 4005 , OCSP_CERT_NOT_LISTED = 4006 , OCSP_BAD_STATUS = 4007 ,
  CERT_NAME_NOMATCH = 4008 , UNKNOWN_CRITICAL_EXTENSION = 4009 , DUPLICATE_CERT_EXTENSION = 4010 , IPADDR_BLOCKS_ERROR = 4011 ,
  AS_BLOCKS_ERROR = 4012 , NO_REV_AVAIL_INVALID_USE = 4013 , INVALID_OCSP_NOCHECK = 4014 , CRL_HAS_UNKNOWN_CRITICAL_EXTENSION = 4015 ,
  TN_AUTH_LIST_ERROR = 4016 , OCSP_SIGNATURE_ERROR = 4501 , OCSP_ISSUER_NOT_FOUND = 4502 , OCSP_RESPONSE_MISSING_KEYUSAGE = 4503 ,
  OCSP_RESPONSE_INVALID = 4504 , EXT_IN_V1_V2_CERT = 4505 , DUPLICATE_CERT_POLICY = 4506 , V2_IDENTIFIERS_IN_V1_CERT = 4507 ,
  EXTENSION_ENCODING_ERROR = 4508 , CERT_IS_REVOKED = 5000 , CRL_BAD_SIGNATURE = 5001 , SIGNATURE_ERROR = 5002 ,
  CERT_PUBKEY_INVALID = 5003 , SIGNATURE_ALGO_UNKNOWN = 5004 , SIGNATURE_ALGO_BAD_PARAMS = 5005 , EXCEEDED_SEARCH_LIMITS = 5006
}
enum class  Cipher_Dir : uint8_t { Encryption = 0 , Decryption = 1 , ENCRYPTION = Encryption , DECRYPTION = Decryption }
enum class  CRL_Code : uint8_t {
  Unspecified = 0 , KeyCompromise = 1 , CaCompromise = 2 , AffiliationChanged = 3 ,
  Superseded = 4 , CessationOfOperation = 5 , CertificateHold = 6 , RemoveFromCrl = 8 ,
  PrivilegeWithdrawn = 9 , AaCompromise = 10
}
enum  Decoder_Checking : uint8_t { NONE , IGNORE_WS , FULL_CHECK }
enum class  DL_Group_Format : uint8_t {
  ANSI_X9_42 = 0 , ANSI_X9_57 = 1 , PKCS_3 = 2 , DSA_PARAMETERS = ANSI_X9_57 ,
  DH_PARAMETERS = ANSI_X9_42 , ANSI_X9_42_DH_PARAMETERS = ANSI_X9_42 , PKCS3_DH_PARAMETERS = PKCS_3
}
enum class  DL_Group_Source : uint8_t { Builtin , RandomlyGenerated , ExternalSource }
enum class  EC_Group_Encoding : uint8_t {
  Explicit = 0 , ImplicitCA = 1 , NamedCurve = 2 , EC_DOMPAR_ENC_EXPLICIT = Explicit ,
  EC_DOMPAR_ENC_IMPLICITCA = ImplicitCA , EC_DOMPAR_ENC_OID = NamedCurve
}
enum class  EC_Group_Engine : uint8_t { Optimized , Generic , Legacy }
enum class  EC_Group_Source : uint8_t { Builtin , ExternalSource }
enum class  EC_Point_Format : uint8_t {
  Uncompressed = 0 , Compressed = 1 , UNCOMPRESSED = Uncompressed , COMPRESSED = Compressed ,
  Hybrid = 2 , HYBRID = 2
}
enum class  ECIES_Flags : uint8_t {
  None = 0 , SingleHashMode = 1 , CofactorMode = 2 , OldCofactorMode = 4 ,
  CheckMode = 8 , NONE = None , SINGLE_HASH_MODE = SingleHashMode , COFACTOR_MODE = CofactorMode ,
  OLD_COFACTOR_MODE = OldCofactorMode , CHECK_MODE = CheckMode
}
enum class  ErrorType : uint16_t {
  Unknown = 1 , SystemError = 2 , NotImplemented = 3 , OutOfMemory = 4 ,
  InternalError = 5 , IoError = 6 , InvalidObjectState = 100 , KeyNotSet = 101 ,
  InvalidArgument = 102 , InvalidKeyLength = 103 , InvalidNonceLength = 104 , LookupError = 105 ,
  EncodingFailure = 106 , DecodingFailure = 107 , TLSError = 108 , HttpError = 109 ,
  InvalidTag = 110 , RoughtimeError = 111 , CommonCryptoError = 201 , Pkcs11Error = 202 ,
  TPMError = 203 , DatabaseError = 204 , ZlibError = 300 , Bzip2Error = 301 ,
  LzmaError = 302
}
enum class  Extension_Context : uint8_t {
  Certificate , CRL , CRL_Entry , OCSP_Request ,
  OCSP_Response
}
enum class  LMOTS_Algorithm_Type : uint32_t {
  RESERVED = 0x00 , SHA256_N32_W1 = 0x01 , SHA256_N32_W2 = 0x02 , SHA256_N32_W4 = 0x03 ,
  SHA256_N32_W8 = 0x04 , SHA256_N24_W1 = 0x05 , SHA256_N24_W2 = 0x06 , SHA256_N24_W4 = 0x07 ,
  SHA256_N24_W8 = 0x08 , SHAKE_N32_W1 = 0x09 , SHAKE_N32_W2 = 0x0a , SHAKE_N32_W4 = 0x0b ,
  SHAKE_N32_W8 = 0x0c , SHAKE_N24_W1 = 0x0d , SHAKE_N24_W2 = 0x0e , SHAKE_N24_W4 = 0x0f ,
  SHAKE_N24_W8 = 0x10
}
 Enum of available LM-OTS algorithm types. More...
enum class  LMS_Algorithm_Type : uint32_t {
  RESERVED = 0x00 , SHA256_M32_H5 = 0x05 , SHA256_M32_H10 = 0x06 , SHA256_M32_H15 = 0x07 ,
  SHA256_M32_H20 = 0x08 , SHA256_M32_H25 = 0x09 , SHA256_M24_H5 = 0x0a , SHA256_M24_H10 = 0x0b ,
  SHA256_M24_H15 = 0x0c , SHA256_M24_H20 = 0x0d , SHA256_M24_H25 = 0x0e , SHAKE_M32_H5 = 0x0f ,
  SHAKE_M32_H10 = 0x10 , SHAKE_M32_H15 = 0x11 , SHAKE_M32_H20 = 0x12 , SHAKE_M32_H25 = 0x13 ,
  SHAKE_M24_H5 = 0x14 , SHAKE_M24_H10 = 0x15 , SHAKE_M24_H15 = 0x16 , SHAKE_M24_H20 = 0x17 ,
  SHAKE_M24_H25 = 0x18
}
 Enum of available LMS algorithm types. More...
enum class  MD_Endian : uint8_t { Little , Big }
enum class  MlPrivateKeyFormat : uint8_t { Seed , Expanded , Both }
enum class  PublicKeyOperation : uint8_t { Encryption , Signature , KeyEncapsulation , KeyAgreement }
enum class  Signature_Format : uint8_t { Standard = 0 , DerSequence = 1 , IEEE_1363 = Standard , DER_SEQUENCE = DerSequence }
enum class  Sphincs_Address_Type : uint32_t {
  WotsHash = 0 , WotsPublicKeyCompression = 1 , HashTree = 2 , ForsTree = 3 ,
  ForsTreeRootsCompression = 4 , WotsKeyGeneration = 5 , ForsKeyGeneration = 6
}
enum class  Sphincs_Hash_Type : uint8_t { Shake256 , Sha256 , Haraka }
enum class  Sphincs_Parameter_Set : uint8_t {
  Sphincs128Small , Sphincs128Fast , Sphincs192Small , Sphincs192Fast ,
  Sphincs256Small , Sphincs256Fast , SLHDSA128Small , SLHDSA128Fast ,
  SLHDSA192Small , SLHDSA192Fast , SLHDSA256Small , SLHDSA256Fast
}
enum class  TPM_Storage_Type { User , System }
enum class  Usage_Type : uint8_t {
  UNSPECIFIED , TLS_SERVER_AUTH , TLS_CLIENT_AUTH , CERTIFICATE_AUTHORITY ,
  OCSP_RESPONDER , ENCRYPTION
}
enum class  WOTS_Derivation_Method : uint8_t { Botan2x = 1 , NIST_SP800_208 = 2 }

Functions

BigInt abs (const BigInt &n)
void absorb_into_sponge (detail::SpongeLikeWithTrivialPermute auto &sponge, std::span< const uint8_t > input)
template<detail::SpongeLike SpongeT>
void absorb_into_sponge (SpongeT &sponge, std::span< const uint8_t > input, const detail::PermutationFn auto &permutation_fn)
void acknowledge_always_deterministic (const PK_Signature_Options_Reader &options)
template<std::unsigned_integral T>
constexpr T add_or_throw (T a, T b, std::string_view msg)
BOTAN_MALLOC_FN void * allocate_memory (size_t elems, size_t elem_size)
template<typename... Ptrs>
bool any_null_pointers (Ptrs... ptr)
template<typename T, typename Alloc>
void append (std::vector< T, Alloc > &out, std::type_identity_t< std::span< const T > > in)
void argon2 (uint8_t output[], size_t output_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len, const uint8_t key[], size_t key_len, const uint8_t ad[], size_t ad_len, uint8_t y, size_t p, size_t M, size_t t)
bool argon2_check_pwhash (const char *password, size_t password_len, std::string_view input_hash)
std::string argon2_generate_pwhash (const char *password, size_t password_len, RandomNumberGenerator &rng, size_t p, size_t M, size_t t, uint8_t y, size_t salt_len, size_t output_len)
std::span< const uint8_t > as_span_of_bytes (const char *s, size_t len)
std::span< const uint8_t > as_span_of_bytes (const std::string &s)
std::span< const uint8_t > as_span_of_bytes (std::string_view s)
std::string asn1_class_to_string (ASN1_Class type)
std::string asn1_tag_to_string (ASN1_Type type)
void assert_unreachable (const char *file, int line)
void assertion_failure (const char *expr_str, const char *assertion_made, const char *func, const char *file, int line)
secure_vector< uint8_t > base32_decode (const char input[], size_t input_length, bool ignore_ws)
secure_vector< uint8_t > base32_decode (std::string_view input, bool ignore_ws)
size_t base32_decode (uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
size_t base32_decode (uint8_t output[], const char input[], size_t input_length, bool ignore_ws)
size_t base32_decode (uint8_t output[], std::string_view input, bool ignore_ws)
size_t base32_decode_max_output (size_t input_length)
size_t base32_encode (char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
std::string base32_encode (const uint8_t input[], size_t input_length)
std::string base32_encode (std::span< const uint8_t > input)
size_t base32_encode_max_output (size_t input_length)
std::vector< uint8_t > base58_check_decode (const char input[], size_t input_length)
std::vector< uint8_t > base58_check_decode (std::string_view s)
std::string base58_check_encode (const uint8_t input[], size_t input_length)
std::string base58_check_encode (std::span< const uint8_t > vec)
std::vector< uint8_t > base58_decode (const char input[], size_t input_length)
std::vector< uint8_t > base58_decode (std::string_view s)
std::string base58_encode (const uint8_t input[], size_t input_length)
std::string base58_encode (std::span< const uint8_t > vec)
secure_vector< uint8_t > base64_decode (const char input[], size_t input_length, bool ignore_ws)
size_t base64_decode (std::span< uint8_t > output, std::string_view input, bool ignore_ws)
secure_vector< uint8_t > base64_decode (std::string_view input, bool ignore_ws)
size_t base64_decode (uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
size_t base64_decode (uint8_t output[], const char input[], size_t input_length, bool ignore_ws)
size_t base64_decode (uint8_t output[], std::string_view input, bool ignore_ws)
BOTAN_FN_ISA_AVX512_POPCNT size_t base64_decode_avx512 (uint8_t out[], const uint8_t in[], size_t length)
size_t base64_decode_max_output (size_t input_length)
size_t base64_encode (char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
std::string base64_encode (const uint8_t input[], size_t input_length)
std::string base64_encode (std::span< const uint8_t > input)
BOTAN_FN_ISA_AVX512 size_t base64_encode_avx512 (char out[], const uint8_t in[], size_t length)
size_t base64_encode_max_output (size_t input_length)
BOTAN_FN_ISA_AVX512_POPCNT size_t base64_strip_ws_avx512 (uint8_t out[], const uint8_t in[], size_t length)
template<typename Base>
size_t base_decode (const Base &base, uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws=true)
template<typename Base>
size_t base_decode_full (const Base &base, uint8_t output[], const char input[], size_t input_length, bool ignore_ws)
template<typename Vector, typename Base>
Vector base_decode_to_vec (const Base &base, const char input[], size_t input_length, bool ignore_ws)
template<class Base>
size_t base_encode (const Base &base, char output[], const uint8_t input[], size_t input_length, size_t &input_consumed, bool final_inputs)
template<typename Base>
std::string base_encode_to_string (const Base &base, const uint8_t input[], size_t input_length)
BOTAN_FUZZER_API void basecase_mul (word z[], size_t z_size, const word x[], size_t x_size, const word y[], size_t y_size)
BOTAN_FUZZER_API void basecase_sqr (word z[], size_t z_size, const word x[], size_t x_size)
template<typename C, size_t WindowBits, typename BlindedScalar, typename Blinding>
C::ProjectivePoint basemul_booth_exec (std::span< const typename C::AffinePoint > table, const BlindedScalar &scalar, const Blinding &blinding)
template<typename C, size_t WindowBits, typename ScalarBits>
C::ProjectivePoint basemul_booth_exec_vartime (std::span< const typename C::AffinePoint > table, const ScalarBits &scalar, typename C::ProjectivePoint accum)
template<typename C, size_t WindowBits>
std::vector< typename C::AffinePoint > basemul_booth_setup (const typename C::AffinePoint &p, size_t max_scalar_bits)
template<typename C, size_t WindowBits, typename BlindedScalar, typename Blinding>
C::ProjectivePoint basemul_exec (std::span< const typename C::AffinePoint > table, const BlindedScalar &scalar, const Blinding &blinding)
template<typename C, size_t WindowBits>
std::vector< typename C::AffinePoint > basemul_setup (const typename C::AffinePoint &p, size_t max_scalar_bits)
void bcrypt_pbkdf (uint8_t output[], size_t output_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len, size_t rounds)
template<WordType W>
constexpr auto bigint_add2 (W x[], size_t x_size, const W y[], size_t y_size) -> W
template<WordType W>
constexpr auto bigint_add3 (W z[], const W x[], size_t x_size, const W y[], size_t y_size) -> W
template<WordType W>
constexpr int32_t bigint_cmp (const W x[], size_t x_size, const W y[], size_t y_size)
template<WordType W>
constexpr void bigint_cnd_abs (W cnd, W x[], size_t size)
template<WordType W>
constexpr W bigint_cnd_add (W cnd, W x[], const W y[], size_t size)
template<WordType W>
constexpr auto bigint_cnd_sub (W cnd, W x[], const W y[], size_t size) -> W
template<WordType W>
constexpr void bigint_cnd_swap (W cnd, W x[], W y[], size_t size)
void bigint_comba_mul16 (word z[32], const word x[16], const word y[16])
void bigint_comba_mul24 (word z[48], const word x[24], const word y[24])
void bigint_comba_mul4 (word z[8], const word x[4], const word y[4])
void bigint_comba_mul6 (word z[12], const word x[6], const word y[6])
void bigint_comba_mul7 (word z[14], const word x[7], const word y[7])
void bigint_comba_mul8 (word z[16], const word x[8], const word y[8])
void bigint_comba_mul9 (word z[18], const word x[9], const word y[9])
void bigint_comba_sqr16 (word z[32], const word x[16])
void bigint_comba_sqr24 (word z[48], const word x[24])
void bigint_comba_sqr4 (word z[8], const word x[4])
void bigint_comba_sqr6 (word z[12], const word x[6])
void bigint_comba_sqr7 (word z[14], const word x[7])
void bigint_comba_sqr8 (word z[16], const word x[8])
void bigint_comba_sqr9 (word z[18], const word x[9])
template<WordType W>
constexpr auto bigint_ct_is_eq (const W x[], size_t x_size, const W y[], size_t y_size) -> CT::Mask< W >
template<WordType W>
constexpr auto bigint_ct_is_lt (const W x[], size_t x_size, const W y[], size_t y_size, bool lt_or_equal=false) -> CT::Mask< W >
template<WordType W>
constexpr auto bigint_linmul2 (W x[], size_t x_size, W y) -> W
template<WordType W>
constexpr void bigint_linmul3 (W z[], const W x[], size_t x_size, W y)
template<WordType W>
constexpr void bigint_monty_maybe_sub (size_t N, W z[], W x0, const W x[], const W p[])
template<size_t N, WordType W>
constexpr void bigint_monty_maybe_sub (W z[N], W x0, const W x[N], const W y[N])
BOTAN_TEST_API void bigint_monty_mul (word z[], const word x[], const word y[], const word p[], size_t p_size, word p_dash, word ws[], size_t ws_size)
void bigint_monty_redc (word r[], const word z[], const word p[], size_t p_size, word p_dash, word ws[], size_t ws_size)
BOTAN_FUZZER_API void bigint_monty_redc_12 (word r[12], const word z[24], const word p[12], word p_dash, word ws[12])
BOTAN_FUZZER_API void bigint_monty_redc_16 (word r[16], const word z[32], const word p[16], word p_dash, word ws[16])
BOTAN_FUZZER_API void bigint_monty_redc_24 (word r[24], const word z[48], const word p[24], word p_dash, word ws[24])
BOTAN_FUZZER_API void bigint_monty_redc_32 (word r[32], const word z[64], const word p[32], word p_dash, word ws[32])
BOTAN_FUZZER_API void bigint_monty_redc_4 (word r[4], const word z[8], const word p[4], word p_dash, word ws[4])
BOTAN_FUZZER_API void bigint_monty_redc_6 (word r[6], const word z[12], const word p[6], word p_dash, word ws[6])
BOTAN_FUZZER_API void bigint_monty_redc_8 (word r[8], const word z[16], const word p[8], word p_dash, word ws[8])
BOTAN_FUZZER_API void bigint_monty_redc_generic (word r[], const word z[], size_t z_size, const word p[], size_t p_size, word p_dash, word ws[])
void bigint_monty_redc_inplace (word z[], const word p[], size_t p_size, word p_dash, word ws[], size_t ws_size)
BOTAN_TEST_API void bigint_monty_sqr (word z[], const word x[], const word p[], size_t p_size, word p_dash, word ws[], size_t ws_size)
void bigint_mul (word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw, word workspace[], size_t ws_size)
void bigint_mulx_monty_mul (word z[], const word x[], const word y[], const word p[], size_t N, word p_dash, word ws[])
void bigint_mulx_monty_redc (word r[], word z[], const word p[], size_t N, word p_dash)
void bigint_mulx_monty_sqr (word z[], const word x[], const word p[], size_t N, word p_dash, word ws[])
void bigint_mulx_mul4 (word z[8], const word x[4], const word y[4])
void bigint_mulx_mul6 (word z[12], const word x[6], const word y[6])
void bigint_mulx_mul8 (word z[16], const word x[8], const word y[8])
void bigint_mulx_mul9 (word z[18], const word x[9], const word y[9])
void bigint_mulx_sqr (word z[], const word x[], size_t N)
void bigint_mulx_sqr4 (word z[8], const word x[4])
void bigint_mulx_sqr6 (word z[12], const word x[6])
void bigint_mulx_sqr8 (word z[16], const word x[8])
void bigint_mulx_sqr9 (word z[18], const word x[9])
template<WordType W>
constexpr void bigint_shl1 (W x[], size_t x_size, size_t x_words, size_t shift)
template<WordType W>
constexpr void bigint_shl2 (W y[], size_t y_size, const W x[], size_t x_size, size_t shift)
template<WordType W>
constexpr void bigint_shr1 (W x[], size_t x_size, size_t shift)
template<WordType W>
constexpr void bigint_shr2 (W y[], size_t y_size, const W x[], size_t x_size, size_t shift)
void bigint_sqr (word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, word workspace[], size_t ws_size)
template<WordType W>
constexpr auto bigint_sub2 (W x[], size_t x_size, const W y[], size_t y_size) -> W
template<WordType W>
constexpr void bigint_sub2_rev (W x[], const W y[], size_t y_size)
template<WordType W>
constexpr auto bigint_sub3 (W z[], const W x[], size_t x_size, const W y[], size_t y_size) -> W
template<WordType W>
constexpr auto bigint_sub_abs (W z[], const W x[], const W y[], size_t N, W ws[]) -> CT::Mask< W >
template<WordType W>
constexpr auto bigint_submul (W z[], const W y[], size_t N, W q) -> W
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T bit_permute_step (T x, T mask, size_t shift)
size_t bit_size_to_32bit_size (size_t bit_size)
size_t bit_size_to_byte_size (size_t bit_size)
constexpr auto bitlen (size_t x)
constexpr size_t booth_full_windows (size_t sb, size_t wb)
constexpr size_t booth_initial_shift (size_t sb, size_t wb)
constexpr std::pair< size_t, CT::Choice > booth_recode (size_t x, size_t window_bits)
template<size_t WindowBits, std::unsigned_integral T>
constexpr std::pair< size_t, CT::Choice > booth_recode (T x)
template<typename T, typename Alloc, typename Alloc2>
size_t buffer_insert (std::vector< T, Alloc > &buf, size_t buf_offset, const std::vector< T, Alloc2 > &input)
template<typename T, typename Alloc>
size_t buffer_insert (std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
std::string bytes_to_string (std::span< const uint8_t > bytes)
template<WordType W, size_t N, size_t L>
constexpr auto bytes_to_words (std::span< const uint8_t, L > bytes)
constexpr uint64_t carry_shift (const donna128 &a, size_t shift)
uint8_t * cast_char_ptr_to_uint8 (char *s)
const uint8_t * cast_char_ptr_to_uint8 (const char *s)
const char * cast_uint8_ptr_to_char (const uint8_t *b)
char * cast_uint8_ptr_to_char (uint8_t *b)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T ceil_division (T a, T b)
template<std::unsigned_integral T>
requires (sizeof(T) < 32)
constexpr uint8_t ceil_log2 (T x)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T ceil_tobytes (T bits)
std::vector< WotsHashIndex > chain_lengths (const SphincsTreeNode &msg, const Sphincs_Parameters &params)
bool check_bcrypt (std::string_view pass, std::string_view hash)
bool check_passhash9 (std::string_view pass, std::string_view hash)
template<std::unsigned_integral T>
constexpr std::optional< T > checked_add (T a, T b)
template<std::unsigned_integral T, std::unsigned_integral... Ts>
constexpr std::optional< T > checked_add (T a, T b, Ts... rest)
template<typename RT, typename AT>
constexpr RT checked_cast_to (AT i)
template<typename RT, typename ExceptionType, typename AT>
constexpr RT checked_cast_to_or_throw (AT i, std::string_view error_msg_on_fail)
template<std::unsigned_integral T>
constexpr std::optional< T > checked_mul (T a, T b)
template<std::unsigned_integral T>
constexpr std::optional< T > checked_sub (T a, T b)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T choose (T mask, T a, T b)
constexpr void clear_bytes (void *ptr, size_t bytes)
template<ranges::contiguous_output_range R>
requires std::is_trivially_copyable_v<std::ranges::range_value_t<R>>
constexpr void clear_mem (R &&mem)
template<typename T>
constexpr void clear_mem (T *ptr, size_t n)
template<int M>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_CLMUL SIMD_4x32 clmul (const SIMD_4x32 &H, const SIMD_4x32 &x)
template<size_t N, WordType W>
constexpr void comba_mul (W z[2 *N], const W x[N], const W y[N])
template<size_t N, WordType W>
constexpr void comba_sqr (W z[2 *N], const W x[N])
constexpr uint64_t combine_lower (const donna128 &a, size_t s1, const donna128 &b, size_t s2)
void commoncrypto_adjust_key_size (const uint8_t key[], size_t length, const CommonCryptor_Opts &opts, secure_vector< uint8_t > &full_key)
CommonCryptor_Opts commoncrypto_opts_from_algo (std::string_view algo)
CommonCryptor_Opts commoncrypto_opts_from_algo_name (std::string_view algo_name)
void compute_root (StrongSpan< SphincsTreeNode > out, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes, const SphincsTreeNode &leaf, TreeNodeIndex leaf_idx, uint32_t idx_offset, StrongSpan< const SphincsAuthenticationPath > authentication_path, uint32_t total_tree_height, Sphincs_Address &tree_address)
template<concepts::contiguous_strong_type TreeNode, concepts::strong_span AuthPathSS, concepts::tree_node_index TreeNodeIndex, concepts::tree_layer_index TreeLayerIndex, typename Address>
void compute_root (StrongSpan< TreeNode > out_root, AuthPathSS authentication_path, TreeNodeIndex leaf_idx, StrongSpan< const TreeNode > leaf, size_t node_size, TreeLayerIndex total_tree_height, uint32_t idx_offset, concepts::tree_hash_node_pair< TreeNodeIndex, TreeLayerIndex, Address, StrongSpan< TreeNode > > auto node_pair_hash, Address &tree_address)
 Uses an authentication path and a leaf node to reconstruct the root node of a merkle tree.
std::optional< BigInt > compute_rsa_secret_exponent (const BigInt &e, const BigInt &phi_n, const BigInt &p, const BigInt &q)
template<typename OutR = detail::AutoDetect, ranges::spanable_range... Rs>
requires (all_same_v<std::ranges::range_value_t<Rs>...>)
constexpr auto concat (Rs &&... ranges)
bool constant_time_compare (const uint8_t x[], const uint8_t y[], size_t len)
bool constant_time_compare (std::span< const uint8_t > x, std::span< const uint8_t > y)
template<ranges::contiguous_output_range OutR, ranges::contiguous_range InR>
constexpr void copy_mem (OutR &&out, const InR &in)
template<typename T>
constexpr void copy_mem (T *out, const T *in, size_t n)
template<ranges::spanable_range InR>
void copy_out_be (std::span< uint8_t > out, const InR &in)
template<ranges::spanable_range InR>
void copy_out_le (std::span< uint8_t > out, const InR &in)
template<WordType W, size_t N>
consteval size_t count_bits (const std::array< W, N > &p)
auto create_aes_row_generator (const FrodoKEMConstants &constants, StrongSpan< const FrodoSeedA > seed_a)
std::unique_ptr< Private_Key > create_ec_private_key (std::string_view alg_name, const EC_Group &ec_group, RandomNumberGenerator &rng)
std::string create_hex_fingerprint (const uint8_t bits[], size_t len, std::string_view hash_name)
std::string create_hex_fingerprint (std::span< const uint8_t > bits, std::string_view hash_name)
std::unique_ptr< Hash_Engine > create_keccak_mb_engine (std::string_view hash_fn, std::span< const uint8_t > common_prefix, std::string_view provider)
std::array< uint8_t, ED448_LEN > create_pk_from_sk (std::span< const uint8_t, ED448_LEN > sk)
 Create a public key point from a secret key (RFC 8032 5.2.5).
std::unique_ptr< Private_Key > create_private_key (std::string_view alg_name, RandomNumberGenerator &rng, std::string_view params, std::string_view provider)
std::unique_ptr< Hash_Engine > create_sha2_32_mb_engine (std::string_view hash_fn, std::span< const uint8_t > common_prefix, std::string_view provider)
std::unique_ptr< Hash_Engine > create_sha2_64_mb_engine (std::string_view hash_fn, std::span< const uint8_t > common_prefix, std::string_view provider)
auto create_shake_row_generator (const FrodoKEMConstants &constants, StrongSpan< const FrodoSeedA > seed_a)
std::span< const uint8_t > cstr_as_span_of_bytes (const char *s)
uint8_t ct_compare_u8 (const uint8_t x[], const uint8_t y[], size_t len)
BigInt ct_divide (const BigInt &x, const BigInt &y)
void ct_divide (const BigInt &x, const BigInt &y, BigInt &q_out, BigInt &r_out)
BigInt ct_divide_pow2k (size_t k, const BigInt &y)
BigInt ct_divide_word (const BigInt &x, word y)
void ct_divide_word (const BigInt &x, word y, BigInt &q_out, word &r_out)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T ct_expand_top_bit (T a)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr size_t ct_if_is_zero_ret (T x, size_t s)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T ct_is_zero (T x)
word ct_mod_word (const BigInt &x, word y)
BigInt ct_modulo (const BigInt &x, const BigInt &y)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr uint8_t ct_popcount (T x)
template<std::unsigned_integral T>
constexpr T ct_reverse_bits (T b)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr size_t ctz (T n)
void curve25519_basepoint (uint8_t mypublic[32], const uint8_t secret[32])
void curve25519_donna (uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32])
template<typename ProjectivePoint>
constexpr ProjectivePoint dbl_a_minus_3 (const ProjectivePoint &pt)
template<typename ProjectivePoint>
constexpr ProjectivePoint dbl_a_zero (const ProjectivePoint &pt)
template<typename ProjectivePoint, typename FieldElement>
constexpr ProjectivePoint dbl_generic (const ProjectivePoint &pt, const FieldElement &A)
template<typename ProjectivePoint>
constexpr ProjectivePoint dbl_n_a_minus_3 (const ProjectivePoint &pt, size_t n)
template<typename ProjectivePoint>
constexpr ProjectivePoint dbl_n_a_zero (const ProjectivePoint &pt, size_t n)
template<typename ProjectivePoint, typename FieldElement>
constexpr ProjectivePoint dbl_n_generic (const ProjectivePoint &pt, const FieldElement &A, size_t n)
void deallocate_memory (void *p, size_t elems, size_t elem_size)
gf2m decode_gf2m (const uint8_t *mem)
KyberDecodedKeypair decode_ml_kem_private_key (std::span< const uint8_t > private_key, KyberConstants mode)
Point448 decode_point (std::span< const uint8_t > p_bytes)
 Decode a point from a byte array. RFC 7748 Section 5 (decodeUCoordinate).
ScalarX448 decode_scalar (std::span< const uint8_t > scalar_bytes)
 Decode a scalar from a byte array. RFC 7748 Section 5 (decodeScalar448).
DistributionPointMatch distribution_point_match (const X509_CRL &crl, const X509_Certificate &cert)
size_t dl_exponent_size (size_t p_bits)
size_t dl_work_factor (size_t bits)
template<typename E, typename... Args>
void do_throw_error (const char *file, int line, const char *func, Args... args)
size_t ecp_work_factor (size_t bits)
void ed25519_basepoint_mul (std::span< uint8_t, 32 > out, const Ed25519_Scalar &scalar)
void ed25519_basepoint_mul_to_x25519 (std::span< uint8_t, 32 > out, const Ed25519_Scalar &scalar)
bool ed25519_check_signature (std::span< const uint8_t, 32 > pk, const Ed25519_Scalar &h, const uint8_t r[32], const Ed25519_Scalar &s)
consteval std::array< word, 256/WordInfo< word >::bits > ed25519_fp_words ()
void ed25519_gen_keypair (uint8_t pk[32], uint8_t sk[64], const uint8_t seed[32])
void ed25519_sign (uint8_t sig[64], const uint8_t msg[], size_t msg_len, const uint8_t sk[64], const uint8_t domain_sep[], size_t domain_sep_len)
bool ed25519_valid_public_key_point (std::span< const uint8_t, 32 > pk)
bool ed25519_verify (const uint8_t msg[], size_t msg_len, const uint8_t sig[64], const uint8_t pk[32], const uint8_t domain_sep[], size_t domain_sep_len)
void ed448_validate_public_key_point (std::span< const uint8_t, ED448_LEN > pk)
uint32_t encode_gf2m (gf2m to_enc, uint8_t *mem)
secure_vector< uint8_t > encode_ml_kem_private_key (const KyberInternalKeypair &keypair, MlPrivateKeyFormat format)
secure_vector< uint8_t > encode_point (const Point448 &p)
 Encode a point to a 56 byte vector. RFC 7748 Section 5 (encodeUCoordinate).
std::string escape_control_chars (std::string_view utf8)
RandomNumberGenerator & esdm_rng ()
template<typename T>
uint16_t expand_mask_16bit (T tst)
void expand_message_xmd (HashFunction &hash, std::span< uint8_t > output, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)
template<std::integral T>
consteval eea_result< T > extended_euclidean_algorithm (T a, T b)
std::optional< std::string > externally_computed_prehash_name (const PK_Signature_Options_Reader &options)
secure_vector< gf2m > find_roots_gf2m_decomp (const polyn_gf2m &polyn, size_t code_length)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T floor_log2 (T n)
template<typename... T>
std::string fmt (std::string_view format, const T &... args)
std::string format_char_for_display (char c)
std::string format_hex_fingerprint (std::span< const uint8_t > bits)
SphincsTreeNode fors_public_key_from_signature (const SphincsHashedMessage &hashed_message, StrongSpan< const ForsSignature > signature, const Sphincs_Address &address, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hash)
 FIPS 205, Algorithm 17: fors_pkFromSig.
SphincsTreeNode fors_sign_and_pkgen (StrongSpan< ForsSignature > sig_out, const SphincsHashedMessage &hashed_message, const SphincsSecretSeed &secret_seed, const Sphincs_Address &address, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
 FIPS 205, Algorithm 16: fors_sign (with simultaneous FORS pk generation).
BigInt gcd (const BigInt &a, const BigInt &b)
template<typename GeneralVariantT, typename SpecialT>
requires (std::is_constructible_v<GeneralVariantT, std::decay_t<SpecialT>>)
constexpr GeneralVariantT generalize_to (SpecialT &&specific)
 Converts a given variant into another variant-ish whose type states are a super set of the given variant.
template<typename GeneralVariantT, typename... SpecialTs>
constexpr GeneralVariantT generalize_to (std::variant< SpecialTs... > specific)
 Converts a given variant into another variant-ish whose type states are a super set of the given variant.
std::string generate_bcrypt (std::string_view pass, RandomNumberGenerator &rng, uint16_t work_factor, char version)
std::vector< uint8_t > generate_dsa_primes (RandomNumberGenerator &rng, BigInt &p, BigInt &q, size_t pbits, size_t qbits)
bool generate_dsa_primes (RandomNumberGenerator &rng, BigInt &p, BigInt &q, size_t pbits, size_t qbits, const std::vector< uint8_t > &seed_c, size_t offset)
McEliece_PrivateKey generate_mceliece_key (RandomNumberGenerator &rng, size_t ext_deg, size_t code_length, size_t t)
std::string generate_passhash9 (std::string_view pass, RandomNumberGenerator &rng, uint16_t work_factor, uint8_t alg_id)
BigInt generate_rfc6979_nonce (const BigInt &x, const BigInt &q, const BigInt &h, std::string_view hash)
BigInt generate_rsa_prime (RandomNumberGenerator &keygen_rng, RandomNumberGenerator &prime_test_rng, size_t bits, const BigInt &coprime, size_t prob)
AEAD_Mode * get_aead (std::string_view name, Cipher_Dir direction)
template<size_t B, typename T>
requires (B < sizeof(T))
constexpr uint8_t get_byte (T input)
template<typename T>
constexpr uint8_t get_byte_var (size_t byte_num, T input)
Keyed_Filter * get_cipher (std::string_view algo_spec, Cipher_Dir direction)
Keyed_Filter * get_cipher (std::string_view algo_spec, const SymmetricKey &key, Cipher_Dir direction)
Keyed_Filter * get_cipher (std::string_view algo_spec, const SymmetricKey &key, const InitializationVector &iv, Cipher_Dir direction)
Cipher_Mode * get_cipher_mode (std::string_view algo_spec, Cipher_Dir direction, std::string_view provider="")
std::vector< std::string > get_files_recursive (std::string_view dir)
KDF * get_kdf (std::string_view algo_spec)
PBKDF * get_pbkdf (std::string_view algo_spec, std::string_view provider="")
PBKDF * get_s2k (std::string_view algo_spec)
template<WordType W>
constexpr uint32_t get_uint32 (const W xw[], size_t i)
template<uint64_t A, uint8_t B>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX512_GFNI SIMD_16x32 gf2p8affine (const SIMD_16x32 &x)
template<uint64_t A, uint8_t B>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX2_GFNI SIMD_8x32 gf2p8affine (const SIMD_8x32 &x)
template<uint64_t A, uint8_t B>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX512_GFNI SIMD_16x32 gf2p8affineinv (const SIMD_16x32 &x)
template<uint64_t A, uint8_t B>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX2_GFNI SIMD_8x32 gf2p8affineinv (const SIMD_8x32 &x)
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX2_GFNI SIMD_8x32 gf2p8mul (const SIMD_8x32 &a, const SIMD_8x32 &b)
consteval uint64_t gfni_matrix (std::string_view s)
gf2m gray_to_lex (gf2m gray)
std::function< void(std::span< uint8_t >)> h2c_expand_message (std::string_view hash_fn, size_t order_bits, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)
bool has_filesystem_impl ()
template<typename C, bool RO, std::invocable< std::span< uint8_t > > ExpandMsg>
auto hash_to_curve_sswu (const ExpandMsg &expand_message) -> std::conditional_t< RO, typename C::ProjectivePoint, typename C::AffinePoint >
std::vector< uint8_t > hex_decode (const char input[], size_t input_length, bool ignore_ws)
size_t hex_decode (std::span< uint8_t > output, std::string_view input, bool ignore_ws)
std::vector< uint8_t > hex_decode (std::string_view input, bool ignore_ws)
size_t hex_decode (uint8_t output[], const char input[], size_t input_length, bool ignore_ws)
size_t hex_decode (uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
size_t hex_decode (uint8_t output[], std::string_view input, bool ignore_ws)
secure_vector< uint8_t > hex_decode_locked (const char input[], size_t input_length, bool ignore_ws)
secure_vector< uint8_t > hex_decode_locked (std::string_view input, bool ignore_ws)
void hex_encode (char output[], const uint8_t input[], size_t input_length, bool uppercase)
std::string hex_encode (const uint8_t input[], size_t input_length, bool uppercase)
std::string hex_encode (std::span< const uint8_t > input, bool uppercase=true)
template<WordType W, size_t N>
constexpr auto hex_to_words (const char(&s)[N])
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr size_t high_bit (T n)
secure_vector< uint8_t > hkdf_expand_label (std::string_view hash_fn, std::span< const uint8_t > secret, std::string_view label, std::span< const uint8_t > hash_val, size_t length)
template<typename... Alts, typename... Ts>
constexpr bool holds_any_of (const std::variant< Ts... > &v) noexcept
void ht_sign (StrongSpan< SphincsHypertreeSignature > out_sig, const SphincsTreeNode &message_to_sign, const SphincsSecretSeed &secret_seed, XmssTreeIndexInLayer tree_index_in_layer, TreeNodeIndex idx_leaf, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
 FIPS 205, Algorithm 12: ht_sign.
bool ht_verify (const SphincsTreeNode &signed_msg, StrongSpan< const SphincsHypertreeSignature > ht_sig, const SphincsTreeNode &pk_root, XmssTreeIndexInLayer tree_index_in_layer, TreeNodeIndex idx_leaf, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
 FIPS 205, Algorithm 13: ht_verify.
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_dec_last_round (SIMD_4x32 B, SIMD_4x32 K)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_dec_round (SIMD_4x32 B, SIMD_4x32 K)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_dec_round_key (SIMD_4x32 K)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_enc_last_round (SIMD_4x32 B, SIMD_4x32 K)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_enc_round (SIMD_4x32 B, SIMD_4x32 K)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_inv_sbox (SIMD_4x32 x)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_load_block (const uint8_t in[16])
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_sbox (SIMD_4x32 x)
SIMD_4x32 BOTAN_FN_ISA_HWAES hw_aes_sbox_splat (SIMD_4x32 x, SIMD_4x32 k)
void BOTAN_FN_ISA_HWAES hw_aes_store_block (SIMD_4x32 B, uint8_t out[16])
uint8_t ieee1363_hash_id (std::string_view name)
size_t if_work_factor (size_t bits)
template<typename... T>
constexpr void ignore_params (const T &... args)
template<std::unsigned_integral T>
constexpr size_t index_of_first_set_byte (T v)
void initialize_allocator ()
bool intersects (ASN1_Class x, ASN1_Class y)
BigInt inverse_mod (const BigInt &n, const BigInt &mod)
std::optional< BigInt > inverse_mod_general (const BigInt &x, const BigInt &mod)
BigInt inverse_mod_public_prime (const BigInt &x, const BigInt &p)
BigInt inverse_mod_rsa_public_modulus (const BigInt &x, const BigInt &n)
BigInt inverse_mod_secret_prime (const BigInt &x, const BigInt &p)
template<typename C>
constexpr auto invert_field_element (const typename C::FieldElement &fe)
bool is_ascii_control_char (char c)
bool is_bailie_psw_probable_prime (const BigInt &n)
bool is_bailie_psw_probable_prime (const BigInt &n, const Montgomery_Params &monty_n)
bool is_bailie_psw_probable_prime_vartime (const BigInt &n)
bool is_bailie_psw_probable_prime_vartime (const BigInt &n, const Montgomery_Params &monty_n)
template<typename GeneralVariantT, typename SpecialT>
constexpr bool is_generalizable_to (const SpecialT &) noexcept
template<typename GeneralVariantT, typename... SpecialTs>
constexpr bool is_generalizable_to (const std::variant< SpecialTs... > &) noexcept
bool is_lucas_probable_prime (const BigInt &n, const Montgomery_Params &monty_n)
bool is_lucas_probable_prime_vartime (const BigInt &n, const Montgomery_Params &monty_n)
bool is_miller_rabin_lucas_probable_prime (const BigInt &n, const Montgomery_Params &monty_n, RandomNumberGenerator &rng, size_t test_iterations)
bool is_miller_rabin_lucas_probable_prime_vartime (const BigInt &n, const Montgomery_Params &monty_n, RandomNumberGenerator &rng, size_t test_iterations)
bool is_miller_rabin_probable_prime (const BigInt &n, const Montgomery_Params &monty_n, RandomNumberGenerator &rng, size_t test_iterations)
bool is_miller_rabin_probable_prime_vartime (const BigInt &n, const Montgomery_Params &monty_n, RandomNumberGenerator &rng, size_t test_iterations)
bool is_passhash9_alg_supported (uint8_t alg_id)
BigInt is_perfect_square (const BigInt &C)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr bool is_power_of_2 (T arg)
bool is_prime (const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
bool is_prime_vartime (const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
std::optional< uint32_t > is_sub_element_of (const OID &oid, std::initializer_list< uint32_t > prefix)
bool is_unicode_control_char (uint32_t cp)
bool is_valid_utf8 (std::string_view utf8)
int32_t jacobi (BigInt a, BigInt n)
template<absorbing_object T, typename... Ts>
size_t keccak_absorb_padded_strings_encoding (T &sink, size_t padding_mod, Ts... byte_strings)
template<typename W>
BOTAN_FORCE_INLINE W keccak_chi (const W &x, const W &y, const W &z)
size_t keccak_int_encoding_size (size_t x)
std::span< const uint8_t > keccak_int_left_encode (std::span< uint8_t > out, size_t x)
std::span< const uint8_t > keccak_int_right_encode (std::span< uint8_t > out, size_t x)
template<typename W>
BOTAN_FORCE_INLINE W keccak_iota (uint64_t rc)
constexpr size_t keccak_max_int_encoding_size ()
BOTAN_FN_ISA_SIMD_4X64 void keccak_mb_absorb_x4 (uint64_t *states, const uint8_t *const *blocks, size_t rate_words, size_t nblocks)
BOTAN_FN_ISA_SIMD_8X64 void keccak_mb_absorb_x8 (uint64_t *states, const uint8_t *const *blocks, size_t rate_words, size_t nblocks)
BOTAN_FN_ISA_SIMD_4X64 void keccak_mb_permute_x4 (uint64_t *states)
BOTAN_FN_ISA_SIMD_8X64 void keccak_mb_permute_x8 (uint64_t *states)
template<typename W>
BOTAN_FORCE_INLINE void Keccak_Permutation_round (W T[25], const W A[25], uint64_t RC)
template<size_t R, typename W>
BOTAN_FORCE_INLINE W keccak_rotl (const W &v)
std::string key_constraints_to_string (Key_Constraints c)
std::string latin1_to_utf8 (std::span< const uint8_t > chars)
BigInt lcm (const BigInt &a, const BigInt &b)
gf2m lex_to_gray (gf2m lex)
LMOTS_K lmots_compute_pubkey_from_sig (const LMOTS_Signature &sig, const LMS_Message &msg, const LMS_Identifier &identifier, LMS_Tree_Node_Idx q)
 Compute a public key candidate for an OTS-signature-message pair and the OTS instance parameters.
void lmots_compute_pubkeys (std::span< uint8_t > out_ks, const LMOTS_Params &params, const LMS_Identifier &identifier, LMS_Tree_Node_Idx first_q, size_t count, const LMS_Seed &seed, Hash_Engine &engine)
 Compute the public key hash values K (RFC 8554 4.3) of count consecutive LM-OTS instances beginning at first_q, deriving the instances' secrets from seed. The hashing is batched across all instances' chains.
template<typename OutT = detail::AutoDetect, typename... ParamTs>
constexpr auto load_be (ParamTs &&... params)
template<bool BSWAP>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_SIMD_4X32 SIMD_4x32 load_block (const uint8_t in[])
template<typename OutT = detail::AutoDetect, typename... ParamTs>
constexpr auto load_le (ParamTs &&... params)
std::unique_ptr< Private_Key > load_private_key (const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
std::unique_ptr< Public_Key > load_public_key (const AlgorithmIdentifier &alg_id, std::span< const uint8_t > key_bits)
template<typename T>
secure_vector< T > lock (const std::vector< T > &in)
size_t low_zero_bits (const BigInt &n)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T majority (T a, T b, T c)
std::unique_ptr< BlockCipher > make_commoncrypto_block_cipher (std::string_view name)
std::unique_ptr< Cipher_Mode > make_commoncrypto_cipher_mode (std::string_view name, Cipher_Dir direction)
std::unique_ptr< HashFunction > make_commoncrypto_hash (std::string_view name)
Compression_Algorithm * make_compressor (std::string_view type)
Decompression_Algorithm * make_decompressor (std::string_view type)
std::unique_ptr< Montgomery_Exponentiation_State > make_monty_exp_avx512 (const Montgomery_Int &g, size_t window_bits)
constexpr uint16_t make_uint16 (uint8_t i0, uint8_t i1)
constexpr uint32_t make_uint32 (uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
constexpr uint64_t make_uint64 (uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3, uint8_t i4, uint8_t i5, uint8_t i6, uint8_t i7)
template<typename T, typename Pred>
void map_remove_if (Pred pred, T &assoc)
template<typename C>
auto map_to_curve_sswu (const typename C::FieldElement &u) -> typename C::AffinePoint
secure_vector< uint8_t > mceliece_decrypt (secure_vector< gf2m > &error_pos, const uint8_t *ciphertext, size_t ciphertext_len, const McEliece_PrivateKeyInternal &key)
void mceliece_decrypt (secure_vector< uint8_t > &plaintext, secure_vector< uint8_t > &error_mask, const uint8_t ciphertext[], size_t ciphertext_len, const McEliece_PrivateKeyInternal &key)
void mceliece_decrypt (secure_vector< uint8_t > &plaintext_out, secure_vector< uint8_t > &error_mask_out, const secure_vector< uint8_t > &ciphertext, const McEliece_PrivateKeyInternal &key)
void mceliece_encrypt (secure_vector< uint8_t > &ciphertext_out, secure_vector< uint8_t > &error_mask_out, const secure_vector< uint8_t > &plaintext, const McEliece_PublicKeyInternal &key, RandomNumberGenerator &rng)
McEliece_Params mceliece_validate_key_params (size_t code_length, size_t t)
McEliece_Params mceliece_validate_keygen_params (size_t code_length, size_t t)
size_t mceliece_work_factor (size_t n, size_t t)
template<typename F>
uint64_t measure_cost (uint64_t trial_msec, F func)
void mgf1_mask (HashFunction &hash, std::span< const uint8_t > input, std::span< uint8_t > output)
size_t miller_rabin_test_iterations (size_t n_bits, size_t prob, bool random)
std::vector< word > BOTAN_TEST_API mod_small_primes (const BigInt &n, size_t num_primes)
std::vector< word > BOTAN_TEST_API mod_small_primes (uint64_t x, size_t num_primes)
template<std::integral T, std::integral T2 = next_longer_int_t<T>>
consteval T modular_inverse (T q, T2 m=T2(1)<< sizeof(T) *8)
template<std::integral T>
consteval T montgomery_R (T q)
template<std::integral T>
consteval T montgomery_R2 (T q)
Montgomery_Int monty_execute (const Montgomery_Exponentiation_State &precomputed_state, const BigInt &k, size_t max_k_bits)
Montgomery_Int monty_execute_vartime (const Montgomery_Exponentiation_State &precomputed_state, const BigInt &k)
Montgomery_Int monty_exp (const Montgomery_Params &params_p, const BigInt &g, const BigInt &k, size_t max_k_bits)
Montgomery_Int monty_exp_vartime (const Montgomery_Params &params_p, const BigInt &g, const BigInt &k)
template<WordType W>
constexpr auto monty_inverse (W a) -> W
Montgomery_Int monty_multi_exp (const Montgomery_Params &params_p, const BigInt &x_bn, const BigInt &z1, const BigInt &y_bn, const BigInt &z2)
std::shared_ptr< const Montgomery_Exponentiation_State > monty_precompute (const Montgomery_Int &g, size_t window_bits)
std::shared_ptr< const Montgomery_Exponentiation_State > monty_precompute (const Montgomery_Params &params, const BigInt &g, size_t window_bits)
template<WordType W, size_t N>
constexpr auto monty_redc (const std::array< W, 2 *N > &z, const std::array< W, N > &p, W p_dash) -> std::array< W, N >
template<WordType W, size_t N>
constexpr auto monty_redc_pdash1 (const std::array< W, 2 *N > &z, const std::array< W, N > &p) -> std::array< W, N >
template<WordType W, size_t N>
consteval std::array< W, N > montygomery_r (const std::array< W, N > &p)
template<typename C, size_t WindowBits, typename BlindedScalar, typename Blinding>
C::ProjectivePoint mul2_exec (const SharedZPointTable< C > &table, const BlindedScalar &x, const BlindedScalar &y, const Blinding &blinding)
template<typename C, size_t WindowBits>
std::vector< typename C::ProjectivePoint > mul2_setup (const typename C::AffinePoint &p, const typename C::AffinePoint &q)
constexpr void mul64x64_128 (uint64_t a, uint64_t b, uint64_t *lo, uint64_t *hi)
Gf448Elem mul_a24 (const Gf448Elem &a)
 Multiply a field element by the Curve448 constant a24 = 39081.
template<WordType W, size_t N>
consteval std::array< W, N > mul_mod (const std::array< W, N > &x, const std::array< W, N > &y, const std::array< W, N > &p)
template<std::unsigned_integral T>
constexpr T mul_or_throw (T a, T b, std::string_view msg)
EC_Point multi_exponentiate (const EC_Point &p1, const BigInt &z1, const EC_Point &p2, const BigInt &z2)
BOTAN_FORCE_INLINE SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 mulx_polyval (const SIMD_4x32 &h)
uint32_t next_utf8_codepoint (std::string_view utf8, size_t &pos)
constexpr char nibble_to_hex (uint8_t b)
secure_vector< uint8_t > nist_key_unwrap (const uint8_t input[], size_t input_len, const BlockCipher &bc)
secure_vector< uint8_t > nist_key_unwrap (std::span< const uint8_t > input, const BlockCipher &bc)
secure_vector< uint8_t > nist_key_unwrap_padded (const uint8_t input[], size_t input_len, const BlockCipher &bc)
secure_vector< uint8_t > nist_key_unwrap_padded (std::span< const uint8_t > input, const BlockCipher &bc)
std::vector< uint8_t > nist_key_wrap (const uint8_t input[], size_t input_len, const BlockCipher &bc)
std::vector< uint8_t > nist_key_wrap (std::span< const uint8_t > input, const BlockCipher &bc)
std::vector< uint8_t > nist_key_wrap_padded (const uint8_t input[], size_t input_len, const BlockCipher &bc)
std::vector< uint8_t > nist_key_wrap_padded (std::span< const uint8_t > input, const BlockCipher &bc)
CT::Option< size_t > oaep_find_delim (std::span< const uint8_t > input, std::span< const uint8_t > phash)
template<typename C, size_t W>
std::vector< typename C::AffinePoint > odd_multiples_setup_vartime (const typename C::AffinePoint &p)
bool operator!= (const AlgorithmIdentifier &x, const AlgorithmIdentifier &y)
bool operator!= (const ASN1_Time &t1, const ASN1_Time &t2)
bool operator!= (const BigInt &a, const BigInt &b)
bool operator!= (const BigInt &a, word b)
bool operator!= (const CRL_Entry &a1, const CRL_Entry &a2)
bool operator!= (const EC_Group &lhs, const EC_Group &rhs)
bool operator!= (const OctetString &s1, const OctetString &s2)
bool operator!= (const OID &a, const OID &b)
template<typename T, typename U>
bool operator!= (const secure_allocator< T > &, const secure_allocator< U > &)
bool operator!= (const X509_Certificate &cert1, const X509_Certificate &cert2)
bool operator!= (const X509_DN &dn1, const X509_DN &dn2)
BigInt operator% (const BigInt &n, const BigInt &mod)
word operator% (const BigInt &n, word mod)
template<bitvectorish T1, bitvectorish T2>
auto operator& (const T1 &lhs, const T2 &rhs)
ECIES_Flags operator& (ECIES_Flags a, ECIES_Flags b)
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator& (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator& (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator& (T1 a, Strong< T2, Tags... > b)
template<std::integral T, typename... Tags>
constexpr auto operator&= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator&= (Strong< T1, Tags... > &a, T2 b)
EC_Point operator* (const BigInt &scalar, const EC_Point &point)
BigInt operator* (const BigInt &x, const BigInt &y)
BigInt operator* (const BigInt &x, word y)
template<std::integral T>
constexpr donna128 operator* (const donna128 &x, T y)
EC_Point operator* (const EC_Point &point, const BigInt &scalar)
constexpr Ed25519_FieldElement operator* (const Ed25519_FieldElement &x, const Ed25519_FieldElement &y)
Ed448Point operator* (const Scalar448 &lhs, const Ed448Point &rhs)
 Syntax sugar for scalar multiplication.
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator* (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator* (Strong< T1, Tags... > a, T2 b)
template<std::integral T>
constexpr donna128 operator* (T y, const donna128 &x)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator* (T1 a, Strong< T2, Tags... > b)
BigInt operator* (word x, const BigInt &y)
template<std::integral T, typename... Tags>
constexpr auto operator*= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator*= (Strong< T1, Tags... > &a, T2 b)
BigInt operator+ (const BigInt &x, const BigInt &y)
BigInt operator+ (const BigInt &x, word y)
constexpr donna128 operator+ (const donna128 &x, const donna128 &y)
constexpr donna128 operator+ (const donna128 &x, uint64_t y)
EC_Point operator+ (const EC_Point &lhs, const EC_Point &rhs)
constexpr Ed25519_FieldElement operator+ (const Ed25519_FieldElement &x, const Ed25519_FieldElement &y)
OctetString operator+ (const OctetString &k1, const OctetString &k2)
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator+ (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator+ (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator+ (T1 a, Strong< T2, Tags... > b)
BigInt operator+ (word x, const BigInt &y)
template<std::integral T, typename... Tags>
constexpr auto operator++ (Strong< T, Tags... > &a)
template<std::integral T, typename... Tags>
constexpr auto operator++ (Strong< T, Tags... > &a, int)
template<typename T, typename Alloc, typename L>
std::vector< T, Alloc > & operator+= (std::vector< T, Alloc > &out, const std::pair< const T *, L > &in)
template<typename T, typename Alloc, typename L>
std::vector< T, Alloc > & operator+= (std::vector< T, Alloc > &out, const std::pair< T *, L > &in)
template<typename T, typename Alloc, typename Alloc2>
std::vector< T, Alloc > & operator+= (std::vector< T, Alloc > &out, const std::vector< T, Alloc2 > &in)
template<typename T, typename Alloc>
std::vector< T, Alloc > & operator+= (std::vector< T, Alloc > &out, std::span< const T > in)
template<typename T, typename Alloc>
std::vector< T, Alloc > & operator+= (std::vector< T, Alloc > &out, T in)
template<std::integral T, typename... Tags>
constexpr auto operator+= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator+= (Strong< T1, Tags... > &a, T2 b)
BigInt operator- (const BigInt &x, const BigInt &y)
BigInt operator- (const BigInt &x, word y)
EC_Point operator- (const EC_Point &lhs)
EC_Point operator- (const EC_Point &lhs, const EC_Point &rhs)
constexpr Ed25519_FieldElement operator- (const Ed25519_FieldElement &x)
constexpr Ed25519_FieldElement operator- (const Ed25519_FieldElement &x, const Ed25519_FieldElement &y)
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator- (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator- (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator- (T1 a, Strong< T2, Tags... > b)
template<std::integral T, typename... Tags>
constexpr auto operator-- (Strong< T, Tags... > &a)
template<std::integral T, typename... Tags>
constexpr auto operator-- (Strong< T, Tags... > &a, int)
template<std::integral T, typename... Tags>
constexpr auto operator-= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator-= (Strong< T1, Tags... > &a, T2 b)
BigInt operator/ (const BigInt &x, const BigInt &y)
BigInt operator/ (const BigInt &x, word y)
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator/ (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator/ (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator/ (T1 a, Strong< T2, Tags... > b)
template<std::integral T, typename... Tags>
constexpr auto operator/= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator/= (Strong< T1, Tags... > &a, T2 b)
bool operator< (const ASN1_Time &t1, const ASN1_Time &t2)
bool operator< (const BigInt &a, const BigInt &b)
bool operator< (const BigInt &a, word b)
bool operator< (const OID &a, const OID &b)
bool operator< (const X509_DN &dn1, const X509_DN &dn2)
BigInt operator<< (const BigInt &x, size_t shift)
int operator<< (int fd, Pipe &pipe)
std::ostream & operator<< (std::ostream &os, const GeneralName &gn)
std::ostream & operator<< (std::ostream &os, const GeneralSubtree &gs)
template<typename T, typename... Tags>
decltype(auto) operator<< (std::ostream &os, const Strong< T, Tags... > &v)
std::ostream & operator<< (std::ostream &out, const OID &oid)
std::ostream & operator<< (std::ostream &out, const X509_DN &dn)
std::ostream & operator<< (std::ostream &out, Pipe &pipe)
std::ostream & operator<< (std::ostream &stream, const BigInt &n)
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator<< (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator<< (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator<< (T1 a, Strong< T2, Tags... > b)
template<std::integral T, typename... Tags>
constexpr auto operator<<= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator<<= (Strong< T1, Tags... > &a, T2 b)
bool operator<= (const ASN1_Time &t1, const ASN1_Time &t2)
bool operator<= (const BigInt &a, const BigInt &b)
bool operator<= (const BigInt &a, word b)
template<typename T, typename... Tags>
auto operator<=> (const Strong< T, Tags... > &lhs, const Strong< T, Tags... > &rhs)
template<std::integral T1, std::integral T2, typename... Tags>
auto operator<=> (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
auto operator<=> (T1 a, Strong< T2, Tags... > b)
bool operator== (const AlgorithmIdentifier &x, const AlgorithmIdentifier &y)
bool operator== (const ASN1_Time &t1, const ASN1_Time &t2)
bool operator== (const BigInt &a, const BigInt &b)
bool operator== (const BigInt &a, word b)
bool operator== (const Classic_McEliece_Polynomial_Ring::Big_F_Coefficient &lhs, const Classic_McEliece_Polynomial_Ring::Big_F_Coefficient &rhs)
bool operator== (const CRL_Entry &a1, const CRL_Entry &a2)
bool operator== (const OctetString &s1, const OctetString &s2)
template<typename T, typename U>
bool operator== (const secure_allocator< T > &, const secure_allocator< U > &)
template<typename T, typename... Tags>
bool operator== (const Strong< T, Tags... > &lhs, const Strong< T, Tags... > &rhs)
template<bitvectorish T1, bitvectorish T2>
bool operator== (const T1 &lhs, const T2 &rhs)
bool operator== (const X509_DN &dn1, const X509_DN &dn2)
template<std::integral T1, std::integral T2, typename... Tags>
auto operator== (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
auto operator== (T1 a, Strong< T2, Tags... > b)
bool operator> (const ASN1_Time &t1, const ASN1_Time &t2)
bool operator> (const BigInt &a, const BigInt &b)
bool operator> (const BigInt &a, word b)
bool operator>= (const ASN1_Time &t1, const ASN1_Time &t2)
bool operator>= (const BigInt &a, const BigInt &b)
bool operator>= (const BigInt &a, word b)
BigInt operator>> (const BigInt &x, size_t shift)
int operator>> (int fd, Pipe &pipe)
std::istream & operator>> (std::istream &in, Pipe &pipe)
std::istream & operator>> (std::istream &in, X509_DN &dn)
std::istream & operator>> (std::istream &stream, BigInt &n)
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator>> (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator>> (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator>> (T1 a, Strong< T2, Tags... > b)
template<std::integral T, typename... Tags>
constexpr auto operator>>= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator>>= (Strong< T1, Tags... > &a, T2 b)
OctetString operator^ (const OctetString &k1, const OctetString &k2)
template<bitvectorish T1, bitvectorish T2>
auto operator^ (const T1 &lhs, const T2 &rhs)
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator^ (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator^ (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator^ (T1 a, Strong< T2, Tags... > b)
template<typename Alloc, typename Alloc2>
std::vector< uint8_t, Alloc > & operator^= (std::vector< uint8_t, Alloc > &out, const std::vector< uint8_t, Alloc2 > &in)
template<std::integral T, typename... Tags>
constexpr auto operator^= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator^= (Strong< T1, Tags... > &a, T2 b)
ASN1_Class operator| (ASN1_Class x, ASN1_Class y)
uint32_t operator| (ASN1_Class x, ASN1_Type y)
uint32_t operator| (ASN1_Type x, ASN1_Class y)
ASN1_Type operator| (ASN1_Type x, ASN1_Type y)
constexpr donna128 operator| (const donna128 &x, const donna128 &y)
constexpr donna128 operator| (const donna128 &x, uint64_t y)
template<bitvectorish T1, bitvectorish T2>
auto operator| (const T1 &lhs, const T2 &rhs)
ECIES_Flags operator| (ECIES_Flags a, ECIES_Flags b)
ReasonFlags operator| (ReasonFlags::Bits a, ReasonFlags::Bits b)
template<std::integral T, typename... Tags>
constexpr decltype(auto) operator| (Strong< T, Tags... > a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator| (Strong< T1, Tags... > a, T2 b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr decltype(auto) operator| (T1 a, Strong< T2, Tags... > b)
template<std::integral T, typename... Tags>
constexpr auto operator|= (Strong< T, Tags... > &a, Strong< T, Tags... > b)
template<std::integral T1, std::integral T2, typename... Tags>
constexpr auto operator|= (Strong< T1, Tags... > &a, T2 b)
EC_Point OS2ECP (const uint8_t data[], size_t data_len, const CurveGFp &curve)
std::pair< BigInt, BigInt > OS2ECP (const uint8_t pt[], size_t pt_len, const BigInt &p, const BigInt &a, const BigInt &b)
EC_Point OS2ECP (std::span< const uint8_t > data, const CurveGFp &curve)
template<typename T>
constexpr auto out_ptr (T &outptr) noexcept
template<class... Ts>
 overloaded (Ts...) -> overloaded< Ts... >
uint32_t P0 (uint32_t X)
uint32_t P1 (uint32_t X)
template<WordType W, size_t N>
consteval std::array< W, N > p_div_2_plus_1 (const std::array< W, N > &p)
template<uint8_t X, WordType W, size_t N>
consteval std::array< W, N > p_minus (const std::array< W, N > &p)
template<WordType W, size_t N>
consteval std::array< W, N > p_minus_1_over_2 (const std::array< W, N > &p)
template<WordType W, size_t N>
consteval std::array< W, N > p_plus_1_over_4 (const std::array< W, N > &p)
PK_Encryption_Options parse_legacy_enc_options (const Public_Key &key, std::string_view params)
PK_Key_Agreement_Options parse_legacy_ka_options (std::string_view params)
PK_KEM_Options parse_legacy_kem_options (std::string_view params)
PK_Signature_Options parse_legacy_sig_options (const Public_Key &key, std::string_view params)
std::optional< size_t > parse_sz (std::string_view input, bool require_canonical)
std::optional< uint16_t > parse_u16 (std::string_view input, bool require_canonical)
std::optional< uint32_t > parse_u32 (std::string_view input, bool require_canonical)
std::optional< uint64_t > parse_u64 (std::string_view input, bool require_canonical)
secure_vector< uint8_t > pbes2_decrypt (std::span< const uint8_t > key_bits, std::string_view passphrase, const std::vector< uint8_t > &params)
std::pair< AlgorithmIdentifier, std::vector< uint8_t > > pbes2_encrypt (std::span< const uint8_t > key_bits, std::string_view passphrase, std::chrono::milliseconds msec, std::string_view cipher, std::string_view digest, RandomNumberGenerator &rng)
std::pair< AlgorithmIdentifier, std::vector< uint8_t > > pbes2_encrypt_iter (std::span< const uint8_t > key_bits, std::string_view passphrase, size_t pbkdf_iter, std::string_view cipher, std::string_view digest, RandomNumberGenerator &rng)
std::pair< AlgorithmIdentifier, std::vector< uint8_t > > pbes2_encrypt_msec (std::span< const uint8_t > key_bits, std::string_view passphrase, std::chrono::milliseconds msec, size_t *out_iterations_if_nonnull, std::string_view cipher, std::string_view digest, RandomNumberGenerator &rng)
void pbkdf2 (MessageAuthenticationCode &prf, uint8_t out[], size_t out_len, const uint8_t salt[], size_t salt_len, size_t iterations)
size_t pbkdf2 (MessageAuthenticationCode &prf, uint8_t out[], size_t out_len, std::string_view password, const uint8_t salt[], size_t salt_len, size_t iterations, std::chrono::milliseconds msec)
void pkcs12_kdf (std::span< uint8_t > out, std::span< const uint8_t > pwd_bytes, std::span< const uint8_t > salt, size_t iterations, uint8_t id, HashFunction &hash)
secure_vector< uint8_t > pkcs12_pbe_decrypt (std::span< const uint8_t > ciphertext, std::string_view password, const AlgorithmIdentifier &pbe_algo, bool openssl_empty_pwd_compat)
std::pair< AlgorithmIdentifier, std::vector< uint8_t > > pkcs12_pbe_encrypt (std::span< const uint8_t > plaintext, std::string_view password, std::string_view algo, size_t iterations, RandomNumberGenerator &rng)
std::vector< uint8_t > pkcs_hash_id (std::string_view name)
template<typename ProjectivePoint, typename FieldElement>
constexpr ProjectivePoint point_add (const ProjectivePoint &a, const ProjectivePoint &b)
template<typename ProjectivePoint, typename AffinePoint, typename FieldElement>
constexpr ProjectivePoint point_add_mixed (const ProjectivePoint &a, const AffinePoint &b, const FieldElement &one, const FieldElement &curve_a)
template<typename ProjectivePoint, typename AffinePoint, typename FieldElement>
constexpr std::pair< ProjectivePoint, FieldElement > point_add_mixed_h (const ProjectivePoint &a, const AffinePoint &b, const FieldElement &one, const FieldElement &curve_a)
template<typename ProjectivePoint, typename AffinePoint, typename FieldElement>
constexpr ProjectivePoint point_add_or_sub_mixed (const ProjectivePoint &a, const AffinePoint &b, CT::Choice sub, const FieldElement &one, const FieldElement &curve_a)
void poly_double_n (uint8_t buf[], size_t n)
void poly_double_n (uint8_t out[], const uint8_t in[], size_t n)
void poly_double_n_le (uint8_t out[], const uint8_t in[], size_t n)
bool poly_double_supported_size (size_t n)
template<uint8_t POLY, std::unsigned_integral T>
constexpr T poly_mul (T x, uint8_t y)
BOTAN_FORCE_INLINE SIMD_4x32 BOTAN_FN_ISA_CLMUL polyval_multiply (const SIMD_4x32 &H, const SIMD_4x32 &x)
BOTAN_FORCE_INLINE SIMD_4x32 BOTAN_FN_ISA_CLMUL polyval_reduce (const SIMD_4x32 &hi, const SIMD_4x32 &lo)
BigInt power_mod (const BigInt &base, const BigInt &exp, const BigInt &mod)
uint64_t prefetch_array_raw (size_t bytes, const void *arrayv) noexcept
template<std::unsigned_integral T, size_t... Ns>
T prefetch_arrays (T(&... arr)[Ns]) noexcept
std::vector< std::string > probe_provider_private_key (std::string_view alg_name, const std::vector< std::string > &possible)
template<typename T>
std::vector< std::string > probe_providers_of (std::string_view algo_spec, const std::vector< std::string > &possible={"base"})
template<detail::SpongeLikeWithTrivialPermute SpongeT>
void process_bytes_in_sponge (SpongeT &sponge, size_t bytes_to_process, const detail::ModifierFn< SpongeT > auto &modifier_fn)
template<detail::SpongeLike SpongeT>
BOTAN_FORCE_INLINE void process_bytes_in_sponge (SpongeT &sponge, size_t bytes_to_process, const detail::PermutationFn auto &permutation_fn, const detail::ModifierFn< SpongeT > auto &modifier_fn)
void R1 (uint32_t A, uint32_t &B, uint32_t C, uint32_t &D, uint32_t E, uint32_t &F, uint32_t G, uint32_t &H, uint32_t TJ, uint32_t Wi, uint32_t Wj)
void R2 (uint32_t A, uint32_t &B, uint32_t C, uint32_t &D, uint32_t E, uint32_t &F, uint32_t G, uint32_t &H, uint32_t TJ, uint32_t Wi, uint32_t Wj)
gf2m random_code_element (uint16_t code_length, RandomNumberGenerator &rng)
gf2m random_gf2m (RandomNumberGenerator &rng)
BigInt random_prime (RandomNumberGenerator &rng, size_t bits, const BigInt &coprime, size_t equiv, size_t modulo, size_t prob)
BigInt random_safe_prime (RandomNumberGenerator &rng, size_t bits)
std::map< std::string, std::string > read_cfg (std::istream &is)
BOTAN_TEST_API std::map< std::string, std::string > read_kv (std::string_view kv)
template<size_t WindowBits, typename W, size_t N>
constexpr size_t read_window_bits (std::span< const W, N > words, size_t offset)
template<WordType W>
constexpr W reciprocal_word (W D)
template<WordType W>
constexpr W reciprocal_word_ct (W D)
template<WordType W, size_t N, W C>
constexpr std::array< W, N > redc_crandall (std::span< const W, 2 *N > z)
template<typename RetT, typename KeyT, typename ReducerT>
requires std::invocable<ReducerT&, RetT, const KeyT&> && std::convertible_to<std::invoke_result_t<ReducerT&, RetT, const KeyT&>, RetT>
RetT reduce (const std::vector< KeyT > &keys, RetT acc, ReducerT reducer)
template<WordType W, size_t N, size_t XN>
consteval std::array< W, N > reduce_mod (const std::array< W, XN > &x, const std::array< W, N > &p)
template<typename OptionsT>
void require_hardware_provider (const OptionsT &options, std::string_view algo_name, std::string_view provider_name)
template<typename OptionsT>
void require_software_provider (const OptionsT &options, std::string_view algo_name)
template<std::unsigned_integral T>
constexpr T reverse_bytes (T x)
secure_vector< uint8_t > rfc3394_keyunwrap (const secure_vector< uint8_t > &key, const SymmetricKey &kek)
secure_vector< uint8_t > rfc3394_keywrap (const secure_vector< uint8_t > &key, const SymmetricKey &kek)
size_t RFC4880_decode_count (uint8_t iter)
uint8_t RFC4880_encode_count (size_t desired_iterations)
size_t RFC4880_round_iterations (size_t iterations)
template<size_t R1, size_t R2, size_t R3, std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T rho (T x)
Gf448Elem root (const Gf448Elem &elem)
 Compute the root of elem in the field.
template<size_t R>
SIMD_16x32 BOTAN_FN_ISA_AVX512 rotl (SIMD_16x32 input)
template<size_t R>
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 rotl (SIMD_4x32 input)
template<size_t R>
SIMD_8x32 BOTAN_FN_ISA_SIMD_8X32 rotl (SIMD_8x32 input)
template<size_t ROT, std::unsigned_integral T>
requires (ROT > 0 && ROT < 8 * sizeof(T))
BOTAN_FORCE_INLINE constexpr T rotl (T input)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T rotl_var (T input, size_t rot)
template<size_t R>
SIMD_16x32 BOTAN_FN_ISA_AVX512 rotr (SIMD_16x32 input)
template<size_t R>
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 rotr (SIMD_4x32 input)
template<size_t R>
SIMD_8x32 BOTAN_FN_ISA_SIMD_8X32 rotr (SIMD_8x32 input)
template<size_t ROT, std::unsigned_integral T>
requires (ROT > 0 && ROT < 8 * sizeof(T))
BOTAN_FORCE_INLINE constexpr T rotr (T input)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T rotr_var (T input, size_t rot)
std::string runtime_version_check (uint32_t major, uint32_t minor, uint32_t patch)
template<typename T>
bool same_mem (const T *p1, const T *p2, size_t n)
constexpr size_t scalar_blinding_bits (size_t scalar_bits)
void scrypt (uint8_t output[], size_t output_len, const char *password, size_t password_len, const uint8_t salt[], size_t salt_len, size_t N, size_t r, size_t p)
void scrypt (uint8_t output[], size_t output_len, std::string_view password, const uint8_t salt[], size_t salt_len, size_t N, size_t r, size_t p)
void secure_scrub_memory (ranges::contiguous_output_range auto &&data)
void secure_scrub_memory (void *ptr, size_t n)
void secure_zeroize_buffer (void *ptr, size_t n)
constexpr void set_mem (uint8_t *ptr, size_t n, uint8_t val)
BOTAN_FORCE_INLINE void SHA2_32_F (uint32_t A, uint32_t B, uint32_t C, uint32_t &D, uint32_t E, uint32_t F, uint32_t G, uint32_t &H, uint32_t &M1, uint32_t M2, uint32_t M3, uint32_t M4, uint32_t magic)
BOTAN_FORCE_INLINE void SHA2_32_F (uint32_t A, uint32_t B, uint32_t C, uint32_t &D, uint32_t E, uint32_t F, uint32_t G, uint32_t &H, uint32_t M)
BOTAN_FN_ISA_AVX512 void sha2_32_mb_compress_x16 (uint8_t *states, const uint8_t *const *blocks, size_t nblocks)
BOTAN_FN_ISA_AVX2 void sha2_32_mb_compress_x8 (uint8_t *states, const uint8_t *const *blocks, size_t nblocks)
BOTAN_FN_ISA_AVX512 void sha2_32_mb_extract_x16 (const uint8_t *states, uint8_t *digests)
BOTAN_FN_ISA_AVX2 void sha2_32_mb_extract_x8 (const uint8_t *states, uint8_t *digests)
BOTAN_FORCE_INLINE void SHA2_64_F (uint64_t A, uint64_t B, uint64_t C, uint64_t &D, uint64_t E, uint64_t F, uint64_t G, uint64_t &H, uint64_t &M1, uint64_t M2, uint64_t M3, uint64_t M4, uint64_t magic)
BOTAN_FORCE_INLINE void SHA2_64_F (uint64_t A, uint64_t B, uint64_t C, uint64_t &D, uint64_t E, uint64_t F, uint64_t G, uint64_t &H, uint64_t M)
BOTAN_FN_ISA_SIMD_4X64 void sha2_64_mb_compress_x4 (uint8_t *states, const uint8_t *const *blocks, size_t nblocks)
BOTAN_FN_ISA_SIMD_8X64 void sha2_64_mb_compress_x8 (uint8_t *states, const uint8_t *const *blocks, size_t nblocks)
BOTAN_FN_ISA_SIMD_4X64 void sha2_64_mb_extract_x4 (const uint8_t *states, uint8_t *digests)
BOTAN_FN_ISA_SIMD_8X64 void sha2_64_mb_extract_x8 (const uint8_t *states, uint8_t *digests)
template<WordType W, size_t N>
consteval std::pair< size_t, std::array< W, N > > shanks_tonelli_c1c2 (const std::array< W, N > &p)
template<WordType W, size_t N>
consteval std::array< W, N > shanks_tonelli_c3 (const std::array< W, N > &c2)
template<typename Z, WordType W, size_t N>
consteval auto shanks_tonelli_c4 (const std::array< W, N > &p_minus_1_over_2) -> Z
template<size_t S, WordType W, size_t N>
constexpr W shift_left (std::array< W, N > &x)
template<size_t S, WordType W, size_t N>
constexpr W shift_right (std::array< W, N > &x)
template<size_t S>
SIMD_16x32 BOTAN_FN_ISA_AVX512 shl (SIMD_16x32 input)
template<size_t S>
SIMD_4x32 shl (SIMD_4x32 input)
template<size_t S>
SIMD_8x32 BOTAN_FN_ISA_SIMD_8X32 shl (SIMD_8x32 input)
const char * short_version_cstr ()
std::string short_version_string ()
template<size_t R1, size_t R2, size_t S, std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T sigma (T x)
std::array< uint8_t, 2 *ED448_LEN > sign_message (std::span< const uint8_t, ED448_LEN > sk, std::span< const uint8_t, ED448_LEN > pk, bool f, std::span< const uint8_t > context, std::span< const uint8_t > msg)
 Sign a message using a keypair (RFC 8032 5.2.6).
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr size_t significant_bytes (T n)
std::vector< uint8_t > sm2_compute_za (HashFunction &hash, std::string_view user_id, const EC_Group &group, const EC_AffinePoint &pubkey)
uint32_t SM3_E (uint32_t W0, uint32_t W7, uint32_t W13, uint32_t W3, uint32_t W10)
template<size_t N, WordType W>
constexpr void solinas_correct_redc (std::array< W, N > &r, const std::array< W, N > &P, const std::array< W, N > &C)
template<typename SpecificVariantT, typename GeneralVariantT>
constexpr std::optional< SpecificVariantT > specialize_to (GeneralVariantT &&v)
 Converts a given variant into another variant whose type states are a subset of the given variant.
std::vector< std::string > split_on (std::string_view str, char delim)
template<typename C>
constexpr CT::Option< typename C::FieldElement > sqrt_field_element (const typename C::FieldElement &fe)
BigInt sqrt_modulo_prime (const BigInt &a, const BigInt &p)
BigInt square (const BigInt &x)
Gf448Elem square (const Gf448Elem &elem)
 Computes elem^2. Faster than operator*.
void squeeze_from_sponge (detail::SpongeLikeWithTrivialPermute auto &sponge, std::span< uint8_t > output)
template<detail::SpongeLike SpongeT>
void squeeze_from_sponge (SpongeT &sponge, std::span< uint8_t > output, const detail::PermutationFn auto &permutation_fn)
std::pair< BigInt, SymmetricKey > srp6_client_agree (std::string_view identifier, std::string_view password, const DL_Group &group, std::string_view hash_id, const std::vector< uint8_t > &salt, const BigInt &B, const size_t a_bits, RandomNumberGenerator &rng)
std::pair< BigInt, SymmetricKey > srp6_client_agree (std::string_view identifier, std::string_view password, std::string_view group_id, std::string_view hash_id, const std::vector< uint8_t > &salt, const BigInt &B, RandomNumberGenerator &rng)
BigInt srp6_generate_verifier (std::string_view identifier, std::string_view password, const std::vector< uint8_t > &salt, const DL_Group &group, std::string_view hash_id)
BigInt srp6_generate_verifier (std::string_view identifier, std::string_view password, const std::vector< uint8_t > &salt, std::string_view group_id, std::string_view hash_id)
std::string srp6_group_identifier (const BigInt &N, const BigInt &g)
template<typename C>
requires C::ValidForSswuHash
const auto & SSWU_C1 ()
template<typename C>
requires C::ValidForSswuHash
const auto & SSWU_C2 ()
template<typename ModifierT = detail::AutoDetect, typename... ParamTs>
constexpr auto store_be (ParamTs &&... params)
template<bool BSWAP>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_SIMD_4X32 void store_block (const SIMD_4x32 &b, uint8_t out[])
template<typename ModifierT = detail::AutoDetect, typename... ParamTs>
constexpr auto store_le (ParamTs &&... params)
std::string string_join (const std::vector< std::string > &strs, char delim)
template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr void swap_bits (T &x, T &y, T mask, size_t shift)
template<std::unsigned_integral T>
constexpr T swar_in_range (T v, T lower, T upper)
template<std::unsigned_integral T>
constexpr T swar_lt (T a, T b)
std::vector< polyn_gf2m > syndrome_init (const polyn_gf2m &generator, const std::vector< gf2m > &support, int n)
RandomNumberGenerator & system_rng ()
void throw_invalid_argument (const char *message, const char *func, const char *file)
void throw_invalid_state (const char *expr, const char *func, const char *file)
template<typename C>
constexpr auto to_affine (const typename C::ProjectivePoint &pt)
template<typename C, bool VariableTime = false>
auto to_affine_batch (std::span< const typename C::ProjectivePoint > projective)
template<typename C>
auto to_affine_x (const typename C::ProjectivePoint &pt)
const char * to_string (Certificate_Status_Code code)
std::string to_string (ErrorType type)
 Convert an ErrorType to string.
uint32_t to_u32bit (std::string_view input)
template<typename T>
auto to_underlying (T e) noexcept
std::string tolower_string (std::string_view str)
void treehash (StrongSpan< SphincsTreeNode > out_root, StrongSpan< SphincsAuthenticationPath > out_auth_path, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes, std::optional< TreeNodeIndex > leaf_idx, uint32_t idx_offset, uint32_t total_tree_height, const GenerateLeavesFunction &gen_leaves, Sphincs_Address &tree_address)
template<concepts::contiguous_strong_type TreeNode, concepts::strong_span AuthPathSS, concepts::tree_node_index TreeNodeIndex, concepts::tree_layer_index TreeLayerIndex, typename Address>
void treehash (StrongSpan< TreeNode > out_root, std::optional< AuthPathSS > out_auth_path, std::optional< TreeNodeIndex > leaf_idx, size_t node_size, TreeLayerIndex total_tree_height, uint32_t idx_offset, concepts::tree_hash_node_pair< TreeNodeIndex, TreeLayerIndex, Address, StrongSpan< TreeNode > > auto node_pair_hash, concepts::tree_gen_leaves< TreeNodeIndex > auto gen_leaves, Address &tree_address)
 Treehash logic to build up a merkle hash tree.
template<typename ToT, ranges::contiguous_range FromR>
constexpr ToT typecast_copy (const FromR &src)
template<typename To>
constexpr To typecast_copy (const uint8_t src[]) noexcept
template<typename T>
constexpr void typecast_copy (T &out, const uint8_t in[])
template<typename T>
requires std::is_trivial_v<T>
constexpr void typecast_copy (T out[], const uint8_t in[], size_t N)
template<ranges::contiguous_output_range ToR, ranges::contiguous_range FromR>
constexpr void typecast_copy (ToR &&out, const FromR &in)
template<ranges::contiguous_output_range ToR, typename FromT>
constexpr void typecast_copy (ToR &&out, const FromT &in)
template<typename ToT, ranges::contiguous_range FromR>
constexpr void typecast_copy (ToT &out, const FromR &in)
template<typename T>
constexpr void typecast_copy (uint8_t out[], const T &in)
template<typename T>
requires std::is_trivially_copyable_v<T>
constexpr void typecast_copy (uint8_t out[], T in[], size_t N)
std::string ucs2_to_utf8 (std::span< const uint8_t > ucs2)
std::string ucs4_to_utf8 (std::span< const uint8_t > ucs4)
template<std::unsigned_integral T>
void unchecked_copy_memory (T *out, const T *in, size_t n)
template<typename T>
std::vector< T > unlock (const secure_vector< T > &in)
template<size_t K, WordType W>
void unpoison_asm_output (const W *ptr)
bool unsafe_for_production_build ()
template<typename T>
constexpr decltype(auto) unwrap_strong_type (T &&t)
 Generically unwraps a strong type to its underlying type.
bool use_mulx_monty (size_t p_size)
std::vector< uint8_t > utf8_to_ucs2 (std::string_view utf8)
std::vector< uint8_t > utf8_to_ucs4 (std::string_view utf8)
void validate_for_hash_based_signature (const PK_Signature_Options_Reader &options, std::string_view algo_name, std::string_view hash_fn)
template<typename T, typename V>
bool value_exists (const std::vector< T > &vec, const V &val)
BOTAN_FORCE_INLINE constexpr size_t var_ctz64 (uint64_t n)
template<typename C, size_t WindowBits, typename BlindedScalar, typename Blinding>
C::ProjectivePoint varpoint_exec (const SharedZPointTable< C > &table, const BlindedScalar &scalar, const Blinding &blinding)
template<typename C, size_t W>
C::ProjectivePoint varpoint_mul (const typename C::AffinePoint &p, const typename C::Scalar &s, RandomNumberGenerator &rng)
template<typename C, size_t W>
C::ProjectivePoint varpoint_mul2 (const typename C::AffinePoint &p, const typename C::Scalar &x, const typename C::AffinePoint &q, const typename C::Scalar &y, RandomNumberGenerator &rng)
bool verify_signature (std::span< const uint8_t, ED448_LEN > pk, bool phflag, std::span< const uint8_t > context, std::span< const uint8_t > sig, std::span< const uint8_t > msg)
 Verify a signature(RFC 8032 5.2.7).
const char * version_cstr ()
uint32_t version_datestamp ()
std::optional< std::string > version_distribution_info ()
uint32_t version_major ()
uint32_t version_minor ()
uint32_t version_patch ()
std::string version_string ()
std::optional< std::string > version_vc_revision ()
template<bool LittleEndian = false>
consteval std::array< uint64_t, 10 > whirlpool_rc () noexcept
template<size_t N = 256>
consteval std::array< uint8_t, N > whirlpool_sbox () noexcept
bool wildcard_intersects_excluded_dns_subtree (std::string_view pattern, std::string_view constraint)
template<WordType W>
constexpr auto word8_add2 (W x[8], const W y[8], W carry) -> W
template<WordType W>
constexpr auto word8_add3 (W z[8], const W x[8], const W y[8], W carry) -> W
template<WordType W>
constexpr auto word8_linmul3 (W z[8], const W x[8], W y, W carry) -> W
template<WordType W>
constexpr auto word8_madd3 (W z[8], const W x[8], W y, W carry) -> W
template<WordType W>
constexpr auto word8_sub2 (W x[8], const W y[8], W carry) -> W
template<WordType W>
constexpr auto word8_sub3 (W z[8], const W x[8], const W y[8], W carry) -> W
template<WordType W>
constexpr auto word_add (W x, W y, W *carry) -> W
template<WordType W>
constexpr auto word_madd2 (W a, W b, W *c) -> W
template<WordType W>
constexpr auto word_madd3 (W a, W b, W c, W *d) -> W
template<WordType W>
constexpr auto word_sub (W x, W y, W *carry) -> W
constexpr size_t words_for_bits (size_t x)
WotsPublicKey wots_public_key_from_signature (const SphincsTreeNode &hashed_message, StrongSpan< const WotsSignature > signature, const Sphincs_Address &address, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
 FIPS 205, Algorithm 8: wots_pkFromSig.
void wots_sign_and_pkgen (StrongSpan< WotsSignature > sig_out, std::span< uint8_t > leaves_out, const SphincsSecretSeed &secret_seed, TreeNodeIndex first_leaf_idx, size_t leaf_count, std::optional< TreeNodeIndex > sign_leaf_idx, const std::vector< WotsHashIndex > &wots_steps, Sphincs_Address &leaf_addr, Sphincs_Address &pk_addr, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
 FIPS 205, Algorithm 6 and 7: wots_pkGen and wots_sign.
template<typename T, typename ParamT>
constexpr decltype(auto) wrap_strong_type (ParamT &&t)
 Wraps a value into a caller-defined (strong) type.
void x25519_basepoint (std::span< uint8_t, 32 > out, std::span< const uint8_t, 32 > scalar)
BOTAN_FORCE_INLINE void x25519_ladder (std::span< uint8_t, 32 > out, std::span< const uint8_t, 32 > k, std::span< const uint8_t, 32 > u)
void x25519_scalarmult (std::span< uint8_t, 32 > out, std::span< const uint8_t, 32 > scalar, std::span< const uint8_t, 32 > u)
Point448 x448 (const ScalarX448 &k, const Point448 &u)
 Multiply a scalar k with a point u.
Point448 x448_basepoint (const ScalarX448 &k)
 Multiply a scalar with the base group element (5).
bool x509_dn_subtree_match (const X509_DN &name, const X509_DN &constraint)
Path_Validation_Result x509_path_validate (const std::vector< X509_Certificate > &end_certs, const Path_Validation_Restrictions &restrictions, const Certificate_Store &store, std::string_view hostname, Usage_Type usage, std::chrono::system_clock::time_point when, std::chrono::milliseconds ocsp_timeout, const std::vector< std::optional< OCSP::Response > > &ocsp_resp)
Path_Validation_Result x509_path_validate (const std::vector< X509_Certificate > &end_certs, const Path_Validation_Restrictions &restrictions, const std::vector< Certificate_Store * > &trusted_roots, std::string_view hostname, Usage_Type usage, std::chrono::system_clock::time_point ref_time, std::chrono::milliseconds ocsp_timeout, const std::vector< std::optional< OCSP::Response > > &ocsp_resp)
Path_Validation_Result x509_path_validate (const X509_Certificate &end_cert, const Path_Validation_Restrictions &restrictions, const Certificate_Store &store, std::string_view hostname, Usage_Type usage, std::chrono::system_clock::time_point when, std::chrono::milliseconds ocsp_timeout, const std::vector< std::optional< OCSP::Response > > &ocsp_resp)
Path_Validation_Result x509_path_validate (const X509_Certificate &end_cert, const Path_Validation_Restrictions &restrictions, const std::vector< Certificate_Store * > &trusted_roots, std::string_view hostname, Usage_Type usage, std::chrono::system_clock::time_point when, std::chrono::milliseconds ocsp_timeout, const std::vector< std::optional< OCSP::Response > > &ocsp_resp)
template<std::unsigned_integral T>
void xmss_concat (secure_vector< uint8_t > &target, const T &src)
template<std::unsigned_integral T>
void xmss_concat (secure_vector< uint8_t > &target, const T &src, size_t len)
SphincsTreeNode xmss_gen_root (const Sphincs_Parameters &params, const SphincsSecretSeed &secret_seed, Sphincs_Hash_Functions &hashes)
SphincsTreeNode xmss_sign_and_pkgen (StrongSpan< SphincsXmssSignature > out_sig, const SphincsTreeNode &message, const SphincsSecretSeed &secret_seed, const Sphincs_Address &wots_addr, Sphincs_Address &tree_addr, std::optional< TreeNodeIndex > idx_leaf, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
 FIPS 205, Algorithm 10: xmss_sign.
void xmss_wots_chains (const XMSS_WOTS_Parameters &params, std::span< uint8_t > nodes, std::span< const uint8_t > from, std::span< const uint8_t > to, std::span< XMSS_Address > addrs, std::span< const uint8_t > seed, XMSS_Hash &hash)
constexpr void xor_buf (ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
constexpr void xor_buf (ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in1, ranges::contiguous_range< uint8_t > auto &&in2)
void xor_buf (std::span< uint8_t > out, std::span< const uint8_t > in, size_t n)
template<typename Alloc, typename Alloc2>
void xor_buf (std::vector< uint8_t, Alloc > &out, const uint8_t *in, const std::vector< uint8_t, Alloc2 > &in2, size_t n)
template<typename Alloc>
void xor_buf (std::vector< uint8_t, Alloc > &out, const uint8_t *in, size_t n)
void xor_buf (uint8_t out[], const uint8_t in[], const uint8_t in2[], size_t length)
void xor_buf (uint8_t out[], const uint8_t in[], size_t length)
void xts_compute_tweak_block (uint8_t tweak[], size_t BS, size_t blocks_in_tweak)
template<typename T, typename Alloc>
void zap (std::vector< T, Alloc > &vec)
template<typename T, typename Alloc>
void zeroise (std::vector< T, Alloc > &vec)
template<std::unsigned_integral T>
void zeroize_buffer (T buf[], size_t n)

Variables

constexpr size_t BLAKE2B_BLOCKBYTES = 128
constexpr size_t BYTES_448 = ceil_tobytes<size_t>(448)
constexpr size_t DefaultBufferSize = 4096
constexpr size_t ED448_LEN = 57
const size_t HEX_CODEC_BUFFER_SIZE = 256
constexpr bool HwAesKeyFirst = false
template<typename T>
constexpr bool is_strong_span_v = is_strong_span<T>::value
template<typename... Ts>
constexpr bool is_strong_type_v = is_strong_type<std::remove_const_t<Ts>...>::value
constexpr size_t KECCAK_MB_ABSORB_BLOCKS = 8
constexpr uint64_t KECCAK_RC [24]
constexpr size_t LMS_IDENTIFIER_LEN = 16
 The length in bytes of the LMS identifier (I).
const size_t MAX_EXT_DEG = 15
constexpr size_t MulxMontyMinWords = 9
constexpr size_t PKCS12_MAX_ITERATIONS = 100'000'000
const size_t PRIME_TABLE_SIZE = 6541
const uint16_t PRIMES []
constexpr uint32_t SHA256_K [64]
constexpr uint64_t SHA512_K [80]
constexpr uint64_t STREEBOG_C [12][8]
constexpr uint64_t STREEBOG_L [8]
const constexpr uint8_t STREEBOG_S [256]
constexpr size_t WORDS_448 = 7
constexpr size_t X448_LEN = 56

Detailed Description

Wrapper for truncated hashes (C) 2023 Jack Lloyd 2023 René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

(C) 2019 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

(C) 2018,2019,2021 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

(C) 2018,2019,2022 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

(C) 2018,2019 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

(C) 2026 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

(C) 2023 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

(C) 2022 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

(C) 2018 Jack Lloyd (C) 2018 Ribose Inc

Botan is released under the Simplified BSD License (see license.txt)

Symmetric primitives for dilithium

(C) 2022-2023 Jack Lloyd (C) 2022-2023 Michael Boric, René Meusel - Rohde & Schwarz Cybersecurity (C) 2022 Manuel Glaser - Rohde & Schwarz Cybersecurity (C) 2024 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

HSS - Hierarchical Signatures System (RFC 8554) (C) 2023,2026 Jack Lloyd 2023 Fabian Albert, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH

Botan is released under the Simplified BSD License (see license.txt)

HSS - Hierarchical Signatures System (RFC 8554) (C) 2023 Jack Lloyd 2023 Fabian Albert, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH

Botan is released under the Simplified BSD License (see license.txt)

HSS-LMS (C) 2023 Jack Lloyd 2023 Fabian Albert, René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

Utils for HSS/LMS (C) 2023 Jack Lloyd 2023 Fabian Albert, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH

Botan is released under the Simplified BSD License (see license.txt)

LM-OTS - Leighton-Micali One-Time Signatures (C) 2023 Jack Lloyd 2023 Fabian Albert, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH

Botan is released under the Simplified BSD License (see license.txt)

LM-OTS - Leighton-Micali One-Time Signatures (RFC 8554 Section 4) (C) 2023 Jack Lloyd 2023 Fabian Albert, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH

Botan is released under the Simplified BSD License (see license.txt)

LMS - Leighton-Micali Hash-Based Signatures (RFC 8554) (C) 2023 Jack Lloyd 2023 Fabian Albert, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH

Botan is released under the Simplified BSD License (see license.txt)

Abstraction for a combined KEM public and private key.

(C) 2024 Jack Lloyd 2024 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

Abstraction for a combined KEM encryptors and decryptors.

(C) 2024 Jack Lloyd 2024 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

Adapter that allows using a KEX key as a KEM, using an ephemeral key in the KEM encapsulation.

(C) 2023 Jack Lloyd 2023,2024 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

Ordinary applications should never need to include or use this header. It is exposed only for specialized applications which want to implement new versions of public key crypto without merging them as changes to the library. One actual example of such usage is an application which creates RSA signatures using a custom TPM library. Unless you're doing something like that, you don't need anything here. Instead use pubkey.h which wraps these types safely and provides a stable application-oriented API.

Note: This header was accidentally pulled from the public API between Botan 3.0.0 and 3.2.0, and then restored in 3.3.0. If you are maintaining an application which used this header in Botan 2.x, you should make sure to use Botan 3.3.0 or later when migrating.

Read access to the public key operation options

Applications never interact with the types in this header; they build a PK_Signature_Options (or the encryption, KEM, or key agreement equivalent) and hand it to the wrapper in pubkey.h. The library then creates a reader object and passes it to the key's _create_xxx_op, so these types are only relevant for out-of-tree implementations of public key schemes.

These types are unstable API and may change between releases.

Hybrid Session Manager emitting both Tickets and storing sessions in Memory (C) 2023 Jack Lloyd (C) 2023 René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

TLS Session Manager in Memory (C) 2011 Jack Lloyd (C) 2023 René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

TLS Stateless Session Manager for stateless servers (C) 2023 Jack Lloyd 2023 René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

Useful concepts that are available throughout the library (C) 2023 Jack Lloyd 2023 René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

(C) 2025 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

(C) 2025 Jack Lloyd (C) 2025 polarnis

Botan is released under the Simplified BSD License (see license.txt)

A wrapper class to implement strong types (C) 2022 Jack Lloyd 2022 René Meusel - Rohde & Schwarz Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

A bunch of helpers to allow considering the Botan-internal strong types in public APIs without depending on the de-facto internal strong_type.h header.

Users of the library should not depend on any of the facilities provided in this header. This is meant to be a bridge to the internal Strong<> template.

(C) 2022,2026 Jack Lloyd 2022 René Meusel - Rohde & Schwarz Cybersecurity 2026 René Meusel - Rohde & Schwarz Networks & Cybersecurity

Botan is released under the Simplified BSD License (see license.txt)

(C) 2024 Jack Lloyd

Botan is released under the Simplified BSD License (see license.txt)

Treehash logic used for hash-based signatures (C) 2023 Jack Lloyd 2023 Fabian Albert, René Meusel, Amos Treiber, Philippe Lieser - Rohde & Schwarz Cybersecurity GmbH

Parts of this file have been adapted from https://github.com/sphincs/sphincsplus

Botan is released under the Simplified BSD License (see license.txt)

Typedef Documentation

◆ bitvector

using Botan::bitvector = bitvector_base<std::allocator>

Definition at line 1419 of file bitvector.h.

◆ Bounded_XOF

template<size_t bound>
using Botan::Bounded_XOF = detail::Bounded_XOF<XOF&, bound>

Definition at line 224 of file pqcrystals_helpers.h.

◆ byte

using Botan::byte = std::uint8_t

Unsigned 8 bit integer; retained for compatibility with older versions.

Definition at line 112 of file types.h.

◆ CCCryptorStatus

typedef int32_t Botan::CCCryptorStatus

Definition at line 24 of file commoncrypto.h.

◆ CertificatePathStatusCodes

This type represents the validation status of an entire certificate path. There is one set of status codes for each certificate in the path.

Definition at line 29 of file x509path.h.

◆ CmceCodeWord

using Botan::CmceCodeWord = Strong<secure_bitvector, struct CmceCodeWord_>

Represents C of decapsulation.

Definition at line 52 of file cmce_types.h.

◆ CmceColumnSelection

using Botan::CmceColumnSelection = Strong<secure_bitvector, struct CmceColumnSelection_>

Represents c of private key.

Definition at line 46 of file cmce_types.h.

◆ CmceErrorVector

using Botan::CmceErrorVector = Strong<secure_bitvector, struct CmceErrorVector_>

Represents e of encapsulation.

Definition at line 49 of file cmce_types.h.

◆ CmceGfElem

using Botan::CmceGfElem = Strong<uint16_t, struct CmceGfElem_>

Represents a GF(q) element.

Definition at line 19 of file cmce_types.h.

◆ CmceGfMod

using Botan::CmceGfMod = Strong<uint16_t, struct CmceGfMod_>

Represents a GF(q) modulus.

Definition at line 22 of file cmce_types.h.

◆ CmceInitialSeed

using Botan::CmceInitialSeed = Strong<secure_vector<uint8_t>, struct CmceInitialSeed_>

Represents initial delta of keygen.

Definition at line 31 of file cmce_types.h.

◆ CmceIrreducibleBits

using Botan::CmceIrreducibleBits = Strong<secure_vector<uint8_t>, struct CmceIrreducibleBits_>

Definition at line 40 of file cmce_types.h.

◆ CmceKeyGenSeed

using Botan::CmceKeyGenSeed = Strong<secure_vector<uint8_t>, struct CmceKeyGenSeed_>

Represents a delta (can be altered; final value stored in private key).

Definition at line 34 of file cmce_types.h.

◆ CmceOrderingBits

using Botan::CmceOrderingBits = Strong<secure_vector<uint8_t>, struct CmceOrderingBits_>

Definition at line 37 of file cmce_types.h.

◆ CmcePermutation

using Botan::CmcePermutation = Strong<secure_vector<uint16_t>, struct CmcePermutation_>

Represents a permutation (pi in spec). Used in field ordering creation.

Definition at line 28 of file cmce_types.h.

◆ CmcePermutationElement

using Botan::CmcePermutationElement = Strong<uint16_t, struct CmcePermutationElement_>

Represents an element of a permutation (pi in spec). Used in field ordering creation.

Definition at line 25 of file cmce_types.h.

◆ CmceRejectionSeed

using Botan::CmceRejectionSeed = Strong<secure_vector<uint8_t>, struct CmceRejectionSeed_>

Represents s of private key.

Definition at line 43 of file cmce_types.h.

◆ Curve25519_PrivateKey

Definition at line 18 of file curve25519.h.

◆ Curve25519_PublicKey

Definition at line 17 of file curve25519.h.

◆ DilithiumCommitmentHash

using Botan::DilithiumCommitmentHash = Strong<std::vector<uint8_t>, struct DilithiumCommitmentHash_>

Hash of the message representative and the signer's commitment.

Definition at line 64 of file dilithium_types.h.

◆ DilithiumHashedPublicKey

using Botan::DilithiumHashedPublicKey = Strong<std::vector<uint8_t>, struct DilithiumHashedPublicKey_>

Hash value of the serialized public key data (result of H(BytesToBits(pkEncode(pk)), also referred to as 'tr')

Definition at line 52 of file dilithium_types.h.

◆ DilithiumInternalKeypair

Initial value:
std::pair<std::shared_ptr<const Dilithium_PublicKeyInternal>, std::shared_ptr<const Dilithium_PrivateKeyInternal>>

Internal representation of a Dilithium key pair.

Definition at line 67 of file dilithium_types.h.

◆ DilithiumMessageRepresentative

using Botan::DilithiumMessageRepresentative = Strong<std::vector<uint8_t>, struct DilithiumMessageRepresentative_>

Representation of the message to be signed.

Definition at line 55 of file dilithium_types.h.

◆ DilithiumOptionalRandomness

using Botan::DilithiumOptionalRandomness = Strong<secure_vector<uint8_t>, struct DilithiumOptionalRandomness_>

Optional randomness 'rnd' used for rho prime computation in ML-DSA.

Definition at line 39 of file dilithium_types.h.

◆ DilithiumPoly

◆ DilithiumPolyMatNTT

◆ DilithiumPolyNTT

◆ DilithiumPolyVec

◆ DilithiumPolyVecNTT

◆ DilithiumSeedRandomness

using Botan::DilithiumSeedRandomness = Strong<secure_vector<uint8_t>, struct DilithiumSeedRandomness_>

Principal seed used to generate Dilithium key pairs.

Definition at line 30 of file dilithium_types.h.

◆ DilithiumSeedRho

using Botan::DilithiumSeedRho = Strong<std::vector<uint8_t>, struct DilithiumPublicSeed_>

Public seed to sample the polynomial matrix A from.

Definition at line 33 of file dilithium_types.h.

◆ DilithiumSeedRhoPrime

using Botan::DilithiumSeedRhoPrime = Strong<secure_vector<uint8_t>, struct DilithiumSeedRhoPrime_>

Private seed to sample the polynomial vectors s1 and s2 from.

Definition at line 36 of file dilithium_types.h.

◆ DilithiumSerializedCommitment

using Botan::DilithiumSerializedCommitment = Strong<std::vector<uint8_t>, struct DilithiumSerializedCommitment_>

Serialized representation of a commitment w1.

Definition at line 61 of file dilithium_types.h.

◆ DilithiumSerializedPrivateKey

using Botan::DilithiumSerializedPrivateKey = Strong<secure_vector<uint8_t>, struct DilithiumSerializedPrivateKey_>

Serialized private key data.

Definition at line 45 of file dilithium_types.h.

◆ DilithiumSerializedPublicKey

using Botan::DilithiumSerializedPublicKey = Strong<std::vector<uint8_t>, struct DilithiumSerializedPublicKey_>

Serialized public key data (result of pkEncode(pk)).

Definition at line 48 of file dilithium_types.h.

◆ DilithiumSerializedSignature

using Botan::DilithiumSerializedSignature = Strong<std::vector<uint8_t>, struct DilithiumSerializedSignature_>

Serialized signature data.

Definition at line 58 of file dilithium_types.h.

◆ DilithiumSigningSeedK

using Botan::DilithiumSigningSeedK = Strong<secure_vector<uint8_t>, struct DilithiumSeedK_>

Private seed K used during signing.

Definition at line 42 of file dilithium_types.h.

◆ ForsLeafSecret

using Botan::ForsLeafSecret = Strong<secure_vector<uint8_t>, struct ForsLeafSecret_>

Definition at line 71 of file sp_types.h.

◆ ForsSignature

using Botan::ForsSignature = Strong<std::vector<uint8_t>, struct ForsSignature_>

Definition at line 72 of file sp_types.h.

◆ FrodoDomainSeparator

using Botan::FrodoDomainSeparator = Strong<std::array<uint8_t, 1>, struct FrodoDomainSeparator_>

Definition at line 47 of file frodo_types.h.

◆ FrodoIntermediateSharedSecret

using Botan::FrodoIntermediateSharedSecret = Strong<secure_vector<uint8_t>, struct FrodoIntermediateSharedSecret_>

Definition at line 56 of file frodo_types.h.

◆ FrodoPackedMatrix

using Botan::FrodoPackedMatrix = Strong<std::vector<uint8_t>, struct FrodoPackedMatrix_>

Definition at line 41 of file frodo_types.h.

◆ FrodoPlaintext

using Botan::FrodoPlaintext = Strong<secure_vector<uint8_t>, struct FrodoPlaintext_>

Definition at line 50 of file frodo_types.h.

◆ FrodoPublicKeyHash

using Botan::FrodoPublicKeyHash = Strong<std::vector<uint8_t>, struct FrodoPublicKeyHash_>

Definition at line 38 of file frodo_types.h.

◆ FrodoSalt

using Botan::FrodoSalt = Strong<std::vector<uint8_t>, struct FrodoSalt_>

Definition at line 53 of file frodo_types.h.

◆ FrodoSampleR

using Botan::FrodoSampleR = Strong<secure_vector<uint8_t>, struct FrodoSampleR_>

Definition at line 35 of file frodo_types.h.

◆ FrodoSeedA

using Botan::FrodoSeedA = Strong<std::vector<uint8_t>, struct FrodoSeedA_>

Definition at line 23 of file frodo_types.h.

◆ FrodoSeedS

using Botan::FrodoSeedS = Strong<secure_vector<uint8_t>, struct FrodoSeedS_>

Definition at line 26 of file frodo_types.h.

◆ FrodoSeedSE

using Botan::FrodoSeedSE = Strong<secure_vector<uint8_t>, struct FrodoSeedSE_>

Definition at line 29 of file frodo_types.h.

◆ FrodoSeedZ

using Botan::FrodoSeedZ = Strong<std::vector<uint8_t>, struct FrodoSeedZ_>

Definition at line 32 of file frodo_types.h.

◆ FrodoSerializedMatrix

using Botan::FrodoSerializedMatrix = Strong<secure_vector<uint8_t>, struct FrodoSerializedMatrix_>

Definition at line 44 of file frodo_types.h.

◆ GenerateLeavesFunction

Initial value:
std::function<void(std::span<uint8_t> , TreeNodeIndex , uint32_t )>
Strong< uint32_t, struct TreeNodeIndex_, EnableArithmeticWithPlainNumber > TreeNodeIndex
Index of an individual node inside an XMSS or FORS tree.
Definition sp_types.h:92

Creates the nodes of count consecutive leaves, starting at the leaf with address index first, into the output buffer. Implementations must fully specify the hash addresses used for the leaves.

Definition at line 30 of file sp_treehash.h.

◆ gf2m

typedef uint16_t Botan::gf2m

Definition at line 20 of file gf2m_small_m.h.

◆ HSS_Level

using Botan::HSS_Level = Strong<uint32_t, struct HSS_Level_, EnableArithmeticWithPlainNumber>

The HSS layer in the HSS multi tree starting at 0 from the root.

Definition at line 35 of file hss.h.

◆ HSS_Sig_Idx

using Botan::HSS_Sig_Idx = Strong<uint64_t, struct HSS_Sig_Idx_, EnableArithmeticWithPlainNumber>

The index of a node within a specific LMS tree layer.

Definition at line 30 of file hss.h.

◆ HypertreeLayerIndex

using Botan::HypertreeLayerIndex = Strong<uint32_t, struct HypertreeLayerIndex_>

Index of a layer in the XMSS hyper-tree.

Definition at line 86 of file sp_types.h.

◆ InitializationVector

Alternate name for octet string showing intent to use as an IV

Definition at line 158 of file symkey.h.

◆ Integrity_Failure

For compatibility with older versions

Definition at line 406 of file exceptn.h.

◆ KyberCompressedCiphertext

using Botan::KyberCompressedCiphertext = Strong<std::vector<uint8_t>, struct KyberCompressedCiphertext_>

Compressed and serialized ciphertext value.

Definition at line 63 of file kyber_types.h.

◆ KyberEncryptionRandomness

using Botan::KyberEncryptionRandomness = Strong<secure_vector<uint8_t>, struct KyberEncryptionRandomness_>

Random value used to generate the Kyber ciphertext.

Definition at line 48 of file kyber_types.h.

◆ KyberHashedCiphertext

using Botan::KyberHashedCiphertext = Strong<std::vector<uint8_t>, struct KyberHashedCiphertext_>

Hash of the compressed and serialized ciphertext value TODO: Remove this once Kyber-R3 is removed

Definition at line 67 of file kyber_types.h.

◆ KyberHashedPublicKey

using Botan::KyberHashedPublicKey = Strong<std::vector<uint8_t>, struct KyberHashedPublicKey_>

Hash value of the serialized public key.

Definition at line 60 of file kyber_types.h.

◆ KyberImplicitRejectionValue

using Botan::KyberImplicitRejectionValue = Strong<secure_vector<uint8_t>, struct KyberImplicitRejectionValue_>

Secret random value (called Z in the spec), used for implicit rejection in the decapsulation.

Definition at line 42 of file kyber_types.h.

◆ KyberInternalKeypair

Initial value:
std::pair<std::shared_ptr<const Kyber_PublicKeyInternal>, std::shared_ptr<const Kyber_PrivateKeyInternal>>

Definition at line 73 of file kyber_types.h.

◆ KyberMessage

using Botan::KyberMessage = Strong<secure_vector<uint8_t>, struct KyberMessage_>

Random message value to be encrypted by the CPA-secure Kyber encryption scheme.

Definition at line 45 of file kyber_types.h.

◆ KyberPoly

◆ KyberPolyMat

◆ KyberPolyNTT

◆ KyberPolyVec

◆ KyberPolyVecNTT

◆ KyberSamplingRandomness

using Botan::KyberSamplingRandomness = Strong<secure_vector<uint8_t>, struct KyberSamplingRandomness_>

PRF value used for sampling of error polynomials.

Definition at line 51 of file kyber_types.h.

◆ KyberSeedRandomness

using Botan::KyberSeedRandomness = Strong<secure_vector<uint8_t>, struct KyberSeedRandomness_>

Principal seed used to generate Kyber key pairs.

Definition at line 33 of file kyber_types.h.

◆ KyberSeedRho

using Botan::KyberSeedRho = Strong<std::vector<uint8_t>, struct KyberSeedRho_>

Public seed value to generate the Kyber matrix A.

Definition at line 36 of file kyber_types.h.

◆ KyberSeedSigma

using Botan::KyberSeedSigma = Strong<secure_vector<uint8_t>, struct KyberSeedSigma_>

Private seed used to generate polynomial vectors s and e during key generation.

Definition at line 39 of file kyber_types.h.

◆ KyberSerializedPublicKey

using Botan::KyberSerializedPublicKey = Strong<std::vector<uint8_t>, struct KyberSerializedPublicKey_>

Public key in serialized form (t || rho).

Definition at line 57 of file kyber_types.h.

◆ KyberSharedSecret

using Botan::KyberSharedSecret = Strong<secure_vector<uint8_t>, struct KyberSharedSecret_>

Shared secret value generated during encapsulation and recovered during decapsulation.

Definition at line 54 of file kyber_types.h.

◆ KyberSigmaOrEncryptionRandomness

Initial value:
std::variant<StrongSpan<const KyberSeedSigma>, StrongSpan<const KyberEncryptionRandomness>>

Variant value of either a KyberSeedSigma or a KyberEncryptionRandomness.

Definition at line 70 of file kyber_types.h.

◆ LMOTS_K

using Botan::LMOTS_K = Strong<std::vector<uint8_t>, struct LMOTS_K_>

The K value from the LM-OTS public key.

Definition at line 39 of file lm_ots.h.

◆ LMOTS_Node

using Botan::LMOTS_Node = Strong<secure_vector<uint8_t>, struct LMOTS_Node_>

One node within one LM-OTS hash chain.

Definition at line 34 of file lm_ots.h.

◆ LMOTS_Signature_Bytes

using Botan::LMOTS_Signature_Bytes = Strong<std::vector<uint8_t>, struct LMOTS_Signature_Bytes_>

Byte vector of an LM-OTS signature.

Definition at line 44 of file lm_ots.h.

◆ LMS_AuthenticationPath

using Botan::LMS_AuthenticationPath = Strong<std::vector<uint8_t>, struct LMS_AuthenticationPath_>

The authentication path of an LMS signature.

Definition at line 74 of file lms.h.

◆ LMS_Identifier

using Botan::LMS_Identifier = Strong<std::vector<uint8_t>, struct LMS_Identifier_>

The identifier of an LMS tree (I in RFC 8554).

Definition at line 54 of file lm_ots.h.

◆ LMS_Message

using Botan::LMS_Message = Strong<std::vector<uint8_t>, struct LMS_Message_>

A message that is signed with an LMS tree.

Definition at line 59 of file lm_ots.h.

◆ LMS_Seed

using Botan::LMS_Seed = Strong<secure_vector<uint8_t>, struct LMS_SEED_>

Seed of the LMS tree, used to generate the LM-OTS private keys.

Definition at line 29 of file lm_ots.h.

◆ LMS_Signature_Bytes

using Botan::LMS_Signature_Bytes = Strong<std::vector<uint8_t>, struct LMS_Signature_Bytes_>

Raw bytes of an LMS signature.

Definition at line 84 of file lms.h.

◆ LMS_Tree_Node

using Botan::LMS_Tree_Node = Strong<std::vector<uint8_t>, struct LMS_Tree_Node_>

A node with the LMS tree.

Definition at line 79 of file lms.h.

◆ LMS_Tree_Node_Idx

using Botan::LMS_Tree_Node_Idx = Strong<uint32_t, struct LMS_Tree_Node_Idx_, EnableArithmeticWithPlainNumber>

The index of a node within a specific LMS tree layer.

Definition at line 49 of file lm_ots.h.

◆ lock_guard_type

template<typename T>
using Botan::lock_guard_type = lock_guard<T>

Definition at line 58 of file mutex.h.

◆ MAC

A shorter alias for MessageAuthenticationCode

Definition at line 139 of file mac.h.

◆ ML_DSA_Mode

Definition at line 21 of file ml_dsa.h.

◆ ML_DSA_PrivateKey

Definition at line 23 of file ml_dsa.h.

◆ ML_DSA_PublicKey

Definition at line 22 of file ml_dsa.h.

◆ ML_KEM_Mode

Definition at line 21 of file ml_kem.h.

◆ ML_KEM_PrivateKey

Definition at line 23 of file ml_kem.h.

◆ ML_KEM_PublicKey

Definition at line 22 of file ml_kem.h.

◆ mutex_type

Definition at line 40 of file mutex.h.

◆ next_longer_int_t

template<std::signed_integral T>
using Botan::next_longer_int_t
Initial value:
std::conditional_t<sizeof(T) == 1, int16_t,
std::conditional_t<sizeof(T) == 2, int32_t,
std::conditional_t<sizeof(T) == 4, int64_t, void>>>

Definition at line 35 of file pqcrystals_helpers.h.

◆ next_longer_uint_t

template<std::unsigned_integral T>
using Botan::next_longer_uint_t
Initial value:
std::conditional_t<sizeof(T) == 1, uint16_t,
std::conditional_t<sizeof(T) == 2, uint32_t,
std::conditional_t<sizeof(T) == 4, uint64_t, void>>>

Definition at line 28 of file pqcrystals_helpers.h.

◆ Point448

using Botan::Point448 = Strong<std::array<uint8_t, X448_LEN>, struct Point448_>

Definition at line 18 of file x448_internal.h.

◆ PointGFp

The name used for the EC_Point type in older versions

Definition at line 489 of file ec_point.h.

◆ recursive_mutex_type

Definition at line 41 of file mutex.h.

◆ RNG

Convenience typedef

Definition at line 397 of file rng.h.

◆ S2K

typedef PBKDF Botan::S2K

Compatibility typedef for PBKDF

Definition at line 240 of file pbkdf.h.

◆ s32bit

using Botan::s32bit = std::int32_t

Signed 32 bit integer; retained for compatibility with older versions.

Definition at line 124 of file types.h.

◆ ScalarX448

using Botan::ScalarX448 = Strong<std::array<uint8_t, X448_LEN>, struct ScalarX448_>

Definition at line 24 of file x448_internal.h.

◆ secure_bitvector

◆ secure_deque

template<typename T>
using Botan::secure_deque = std::deque<T, secure_allocator<T>>

Definition at line 132 of file secmem.h.

◆ secure_vector

template<typename T>
using Botan::secure_vector = std::vector<T, secure_allocator<T>>

Definition at line 128 of file secmem.h.

◆ SecureVector

template<typename T>
using Botan::SecureVector = secure_vector<T>

Definition at line 137 of file secmem.h.

◆ SM2_Encryption_PrivateKey

Definition at line 160 of file sm2.h.

◆ SM2_Encryption_PublicKey

Definition at line 157 of file sm2.h.

◆ SM2_Signature_PrivateKey

Definition at line 159 of file sm2.h.

◆ SM2_Signature_PublicKey

Definition at line 156 of file sm2.h.

◆ SphincsAuthenticationPath

using Botan::SphincsAuthenticationPath = Strong<std::vector<uint8_t>, struct SphincsAuthenticationPath_>

Definition at line 67 of file sp_types.h.

◆ SphincsContext

using Botan::SphincsContext = Strong<std::vector<uint8_t>, struct SphincsContext_>

Definition at line 57 of file sp_types.h.

◆ SphincsHashedMessage

using Botan::SphincsHashedMessage = Strong<std::vector<uint8_t>, struct SphincsHashedMessage_>

Definition at line 59 of file sp_types.h.

◆ SphincsHypertreeSignature

using Botan::SphincsHypertreeSignature = Strong<std::vector<uint8_t>, struct SphincsXmssSignature_>

Definition at line 66 of file sp_types.h.

◆ SphincsInputMessage

using Botan::SphincsInputMessage = Strong<std::vector<uint8_t>, struct SphincsInputMessage_>

Definition at line 49 of file sp_types.h.

◆ SphincsMessagePrefix

using Botan::SphincsMessagePrefix = Strong<std::vector<uint8_t>, struct SphincsMessagePrefix_>

The prefix appended to the message in [hash_]slh_sign and slh_verify. E.g. for SLH-DSA (pure): 0x00 || |ctx| || ctx. Empty for SPHINCS+.

Definition at line 47 of file sp_types.h.

◆ SphincsMessageRandomness

using Botan::SphincsMessageRandomness = Strong<secure_vector<uint8_t>, struct SphincsMessageRandomness_>

Definition at line 64 of file sp_types.h.

◆ SphincsOptionalRandomness

using Botan::SphincsOptionalRandomness = Strong<secure_vector<uint8_t>, struct SphincsOptionalRandomness_>

Definition at line 63 of file sp_types.h.

◆ SphincsPublicSeed

using Botan::SphincsPublicSeed = Strong<std::vector<uint8_t>, struct SphincsPublicSeed_>

Definition at line 60 of file sp_types.h.

◆ SphincsSecretPRF

using Botan::SphincsSecretPRF = Strong<secure_vector<uint8_t>, struct SphincsSecretPRF_>

Definition at line 62 of file sp_types.h.

◆ SphincsSecretSeed

using Botan::SphincsSecretSeed = Strong<secure_vector<uint8_t>, struct SphincsSecretSeed_>

Definition at line 61 of file sp_types.h.

◆ SphincsTreeNode

using Botan::SphincsTreeNode = Strong<std::vector<uint8_t>, struct SphincsTreeNode_>

Either an XMSS or FORS tree node or leaf.

Definition at line 70 of file sp_types.h.

◆ SphincsXmssSignature

using Botan::SphincsXmssSignature = Strong<std::vector<uint8_t>, struct SphincsXmssSignature_>

Definition at line 65 of file sp_types.h.

◆ strong_type_wrapped_type

template<typename T>
using Botan::strong_type_wrapped_type = typename detail::wrapped_type_helper<std::remove_cvref_t<T>>::type

Extracts the wrapped type from a strong type.

If the provided type is not a strong type, it is returned as is.

Note
This is meant as a helper for generic code that needs to deal with both wrapped strong types and bare objects. Use the ordinary ::wrapped_type declaration if you know that you are dealing with a strong type.

Definition at line 104 of file strong_type_helpers.h.

◆ SymmetricKey

Alternate name for octet string showing intent to use as a key

Definition at line 153 of file symkey.h.

◆ TreeLayerIndex

using Botan::TreeLayerIndex = Strong<uint32_t, struct TreeLayerIndex_, EnableArithmeticWithPlainNumber>

Index of the layer within a FORS/XMSS tree.

Definition at line 83 of file sp_types.h.

◆ TreeNodeIndex

using Botan::TreeNodeIndex = Strong<uint32_t, struct TreeNodeIndex_, EnableArithmeticWithPlainNumber>

Index of an individual node inside an XMSS or FORS tree.

Definition at line 92 of file sp_types.h.

◆ u16bit

using Botan::u16bit = std::uint16_t

Unsigned 16 bit integer; retained for compatibility with older versions.

Definition at line 115 of file types.h.

◆ u32bit

using Botan::u32bit = std::uint32_t

Unsigned 32 bit integer; retained for compatibility with older versions.

Definition at line 118 of file types.h.

◆ u64bit

using Botan::u64bit = std::uint64_t

Unsigned 64 bit integer; retained for compatibility with older versions.

Definition at line 121 of file types.h.

◆ uint128_t

Definition at line 37 of file x25519_fe.h.

◆ variant_append_t

template<typename Variant, typename T>
using Botan::variant_append_t = typename variant_append<Variant, T>::type

Converts a given variant into another variant with all its alternative types and an additional alternative type T.

Definition at line 143 of file stl_util.h.

◆ word

using Botan::word = std::conditional_t<HasNative64BitRegisters, std::uint64_t, uint32_t>

The native machine word, used as the limb type for multiprecision integers.

Definition at line 131 of file types.h.

◆ wots_keysig_t

typedef std::vector< secure_vector< uint8_t > > Botan::wots_keysig_t

Definition at line 21 of file xmss_common_ops.h.

◆ WotsChainIndex

using Botan::WotsChainIndex = Strong<uint32_t, struct WotsChainIndex_>

Index of a WOTS chain within a single usage of WOTS.

Definition at line 95 of file sp_types.h.

◆ WotsHashIndex

using Botan::WotsHashIndex = Strong<uint8_t, struct WotsHashIndex_, EnableArithmeticWithPlainNumber>

Index of a hash application inside a single WOTS chain (integers in "base_w").

Definition at line 98 of file sp_types.h.

◆ WotsNode

using Botan::WotsNode = Strong<secure_vector<uint8_t>, struct WotsNode_>

Start (or intermediate) node of a WOTS+ chain.

Definition at line 79 of file sp_types.h.

◆ WotsPublicKey

using Botan::WotsPublicKey = Strong<std::vector<uint8_t>, struct WotsPublicKey_>

Definition at line 73 of file sp_types.h.

◆ WotsPublicKeyNode

using Botan::WotsPublicKeyNode = Strong<std::vector<uint8_t>, struct WotsPublicKeyNode_>

End node of a WOTS+ chain (part of the WOTS+ public key).

Definition at line 76 of file sp_types.h.

◆ WotsSignature

using Botan::WotsSignature = Strong<secure_vector<uint8_t>, struct WotsSignature_>

Definition at line 80 of file sp_types.h.

◆ X509_Time

Alias for ASN1_Time, reflecting the name used by the X.509 ASN.1 modules

Definition at line 27 of file asn1_obj.h.

◆ XmssTreeIndexInLayer

using Botan::XmssTreeIndexInLayer = Strong<uint64_t, struct XmssTreeIndexInLayer_, EnableArithmeticWithPlainNumber>

Index of an XMSS tree (unique for just the local hyper-tree layer).

Definition at line 89 of file sp_types.h.

Enumeration Type Documentation

◆ AlignmentBufferFinalBlock

enum class Botan::AlignmentBufferFinalBlock : uint8_t
strong

Defines the strategy for handling the final block of input data in the handle_unaligned_data() method of the AlignmentBuffer<>.

  • is_not_special: the final block is treated like any other block
  • must_be_deferred: the final block is not emitted while bulk processing (typically add_data()) but is deferred until manually consumed (typically final_result())

The AlignmentBuffer<> assumes data to be "the final block" if no further input data is available in the BufferSlicer<>. This might result in some performance overhead when using the must_be_deferred strategy.

Enumerator
is_not_special 
must_be_deferred 

Definition at line 33 of file alignment_buffer.h.

◆ ASN1_Class

enum class Botan::ASN1_Class : uint32_t
strong

ASN.1 Class Tags

Enumerator
Universal 
Application 
ContextSpecific 
Private 
Constructed 
ExplicitContextSpecific 
NoObject 

Definition at line 32 of file asn1_obj.h.

32 : uint32_t /* NOLINT(performance-enum-size) */ {
33 Universal = 0b0000'0000,
34 Application = 0b0100'0000,
35 ContextSpecific = 0b1000'0000,
36 Private = 0b1100'0000,
37
38 Constructed = 0b0010'0000,
40
41 NoObject = 0xFF00
42};

◆ ASN1_Type

enum class Botan::ASN1_Type : uint32_t
strong

ASN.1 Type Tags

Enumerator
Eoc 
Boolean 
Integer 
BitString 
OctetString 
Null 
ObjectId 
Enumerated 
Sequence 
Set 
Utf8String 
NumericString 
PrintableString 
TeletexString 
Ia5String 
VisibleString 
UniversalString 
BmpString 
UtcTime 
GeneralizedTime 
NoObject 

Definition at line 47 of file asn1_obj.h.

47 : uint32_t /* NOLINT(performance-enum-size) */ {
48 Eoc = 0x00,
49 Boolean = 0x01,
50 Integer = 0x02,
51 BitString = 0x03,
52 OctetString = 0x04,
53 Null = 0x05,
54 ObjectId = 0x06,
55 Enumerated = 0x0A,
56 Sequence = 0x10,
57 Set = 0x11,
58
59 Utf8String = 0x0C,
60 NumericString = 0x12,
61 PrintableString = 0x13,
62 TeletexString = 0x14,
63 Ia5String = 0x16,
64 VisibleString = 0x1A,
65 UniversalString = 0x1C,
66 BmpString = 0x1E,
67
68 UtcTime = 0x17,
69 GeneralizedTime = 0x18,
70
71 NoObject = 0xFF00,
72};

◆ Certificate_Status_Code

enum class Botan::Certificate_Status_Code : uint16_t
strong

Certificate validation status code

Enumerator
OK 
VERIFIED 
OCSP_RESPONSE_GOOD 
OCSP_SIGNATURE_OK 
VALID_CRL_CHECKED 
FIRST_WARNING_STATUS 
CERT_SERIAL_NEGATIVE 
DN_TOO_LONG 
OCSP_NO_REVOCATION_URL 
OCSP_SERVER_NOT_AVAILABLE 
TRUSTED_CERT_HAS_EXPIRED 
TRUSTED_CERT_NOT_YET_VALID 
OCSP_NO_HTTP 
FIRST_ERROR_STATUS 
SIGNATURE_METHOD_TOO_WEAK 
UNTRUSTED_HASH 
NO_REVOCATION_DATA 
NO_MATCHING_CRLDP 
OCSP_ISSUER_NOT_TRUSTED 
CERT_NOT_YET_VALID 
CERT_HAS_EXPIRED 
OCSP_NOT_YET_VALID 
OCSP_HAS_EXPIRED 
CRL_NOT_YET_VALID 
CRL_HAS_EXPIRED 
OCSP_IS_TOO_OLD 
FIRST_ERROR_STATUS_TO_SKIP_REVOCATION 
CERT_ISSUER_NOT_FOUND 
CANNOT_ESTABLISH_TRUST 
CERT_CHAIN_LOOP 
CHAIN_LACKS_TRUST_ROOT 
CHAIN_NAME_MISMATCH 
POLICY_ERROR 
INVALID_USAGE 
CERT_CHAIN_TOO_LONG 
CA_CERT_NOT_FOR_CERT_ISSUER 
NAME_CONSTRAINT_ERROR 
CA_CERT_NOT_FOR_CRL_ISSUER 
OCSP_CERT_NOT_LISTED 
OCSP_BAD_STATUS 
CERT_NAME_NOMATCH 
UNKNOWN_CRITICAL_EXTENSION 
DUPLICATE_CERT_EXTENSION 
IPADDR_BLOCKS_ERROR 
AS_BLOCKS_ERROR 
NO_REV_AVAIL_INVALID_USE 
INVALID_OCSP_NOCHECK 
CRL_HAS_UNKNOWN_CRITICAL_EXTENSION 
TN_AUTH_LIST_ERROR 
OCSP_SIGNATURE_ERROR 
OCSP_ISSUER_NOT_FOUND 
OCSP_RESPONSE_MISSING_KEYUSAGE 
OCSP_RESPONSE_INVALID 
EXT_IN_V1_V2_CERT 
DUPLICATE_CERT_POLICY 
V2_IDENTIFIERS_IN_V1_CERT 
EXTENSION_ENCODING_ERROR 
CERT_IS_REVOKED 
CRL_BAD_SIGNATURE 
SIGNATURE_ERROR 
CERT_PUBKEY_INVALID 
SIGNATURE_ALGO_UNKNOWN 
SIGNATURE_ALGO_BAD_PARAMS 
EXCEEDED_SEARCH_LIMITS 

Definition at line 21 of file pkix_enums.h.

21 : uint16_t {
22 // TODO(Botan4) renumber this, e.g. Validation Errors -> IP_ADDR_BLOCKS_ERROR
23 // TODO(Botan4) rename variants to CamelCase
24 OK = 0,
25 VERIFIED = 0,
26
27 // Revocation status
31
32 // Warnings
35 DN_TOO_LONG = 501,
40 OCSP_NO_HTTP = 506,
41
42 // Errors
43 FIRST_ERROR_STATUS = 1000,
44
46 UNTRUSTED_HASH = 1001,
47 NO_REVOCATION_DATA = 1002,
48 NO_MATCHING_CRLDP = 1003,
50
51 // Time problems
52 CERT_NOT_YET_VALID = 2000,
53 CERT_HAS_EXPIRED = 2001,
54 OCSP_NOT_YET_VALID = 2002,
55 OCSP_HAS_EXPIRED = 2003,
56 CRL_NOT_YET_VALID = 2004,
57 CRL_HAS_EXPIRED = 2005,
58 OCSP_IS_TOO_OLD = 2006,
59
60 // Revocation checks are skipped for chains which have an error more
61 // serious than this because they are anyway invalid
63
64 // Chain generation problems
67 CERT_CHAIN_LOOP = 3002,
70
71 // Validation errors
72 POLICY_ERROR = 4000,
73 INVALID_USAGE = 4001,
77
78 // Revocation errors
81 OCSP_BAD_STATUS = 4007,
82
83 // Other problems
84 CERT_NAME_NOMATCH = 4008,
85
86 // Errors in extensions
88 // TODO(Botan4) remove this code, this is now rejected at parse time
91 AS_BLOCKS_ERROR = 4012,
95 TN_AUTH_LIST_ERROR = 4016,
96
97 // OCSP errors
102 EXT_IN_V1_V2_CERT = 4505,
106
107 // Hard failures
108 CERT_IS_REVOKED = 5000,
109 CRL_BAD_SIGNATURE = 5001,
110 SIGNATURE_ERROR = 5002,
111 CERT_PUBKEY_INVALID = 5003,
115};

◆ Cipher_Dir

enum class Botan::Cipher_Dir : uint8_t
strong

The two possible directions a Cipher_Mode can operate in

Enumerator
Encryption 
Decryption 
ENCRYPTION 
DECRYPTION 

Definition at line 25 of file cipher_mode.h.

25 : uint8_t {
26 Encryption = 0,
27 Decryption = 1,
28
29 ENCRYPTION BOTAN_DEPRECATED("Use Cipher_Dir::Encryption") = Encryption,
30 DECRYPTION BOTAN_DEPRECATED("Use Cipher_Dir::Decryption") = Decryption,
31};
#define BOTAN_DEPRECATED(msg)
Definition api.h:73

◆ CRL_Code

enum class Botan::CRL_Code : uint8_t
strong

X.509v2 CRL Reason Code.

Enumerator
Unspecified 
KeyCompromise 
CaCompromise 
AffiliationChanged 
Superseded 
CessationOfOperation 
CertificateHold 
RemoveFromCrl 
PrivilegeWithdrawn 
AaCompromise 

Definition at line 276 of file pkix_enums.h.

◆ Decoder_Checking

enum Botan::Decoder_Checking : uint8_t

The type of checking to be performed by decoders: NONE - no checks, IGNORE_WS - perform checks, but ignore whitespaces, FULL_CHECK - perform checks, also complain about white spaces.

Enumerator
NONE 
IGNORE_WS 
FULL_CHECK 

Definition at line 193 of file filter.h.

193: uint8_t /* NOLINT(*-use-enum-class) */ { NONE, IGNORE_WS, FULL_CHECK };
@ FULL_CHECK
Definition filter.h:193
@ NONE
Definition filter.h:193
@ IGNORE_WS
Definition filter.h:193

◆ DL_Group_Format

enum class Botan::DL_Group_Format : uint8_t
strong

The DL group encoding format variants.

Enumerator
ANSI_X9_42 
ANSI_X9_57 
PKCS_3 
DSA_PARAMETERS 
DH_PARAMETERS 
ANSI_X9_42_DH_PARAMETERS 
PKCS3_DH_PARAMETERS 

Definition at line 30 of file dl_group.h.

◆ DL_Group_Source

enum class Botan::DL_Group_Source : uint8_t
strong
Enumerator
Builtin 
RandomlyGenerated 
ExternalSource 

Definition at line 21 of file dl_group.h.

◆ EC_Group_Encoding

enum class Botan::EC_Group_Encoding : uint8_t
strong

This enum indicates the method used to encode the EC parameters

Warning
All support for explicit or implicit domain encodings will be removed in Botan4. Only named curves will be supported.

TODO(Botan4) remove this enum

Enumerator
Explicit 
ImplicitCA 
NamedCurve 
EC_DOMPAR_ENC_EXPLICIT 
EC_DOMPAR_ENC_IMPLICITCA 
EC_DOMPAR_ENC_OID 

Definition at line 29 of file ec_point_format.h.

◆ EC_Group_Engine

enum class Botan::EC_Group_Engine : uint8_t
strong

Enum indicating the way the group in question is implemented

This is returned by EC_Group::engine

Enumerator
Optimized 

Using per curve implementation; fastest available.

Generic 

A generic implementation that handles many curves in one implementation.

Legacy 

The old implementation, used as a fallback if none of the other implementations can be used TODO(Botan4) remove this

Definition at line 48 of file ec_group.h.

48 : uint8_t {
49 /// Using per curve implementation; fastest available
51 /// A generic implementation that handles many curves in one implementation
52 Generic,
53 /// The old implementation, used as a fallback if none of the other
54 /// implementations can be used
55 /// TODO(Botan4) remove this
56 Legacy,
57};
@ Optimized
Using per curve implementation; fastest available.
Definition ec_group.h:50
@ Generic
A generic implementation that handles many curves in one implementation.
Definition ec_group.h:52

◆ EC_Group_Source

enum class Botan::EC_Group_Source : uint8_t
strong

This enum indicates the source of the elliptic curve parameters in use.

Builtin means the curve is a known standard one which was compiled in the library.

ExternalSource means the curve parameters came from either an explicit curve encoding or an application defined curve.

Enumerator
Builtin 
ExternalSource 

Definition at line 38 of file ec_group.h.

38 : uint8_t {
39 Builtin,
41};

◆ EC_Point_Format

enum class Botan::EC_Point_Format : uint8_t
strong

This enum indicates the format used to encode an elliptic curve point as an octet string, as specified in SEC1 section 2.3.3

Enumerator
Uncompressed 
Compressed 
UNCOMPRESSED 
COMPRESSED 
Hybrid 
HYBRID 

Definition at line 43 of file ec_point_format.h.

43 : uint8_t {
44 Uncompressed = 0,
45 Compressed = 1,
46
47 UNCOMPRESSED BOTAN_DEPRECATED("Use EC_Point_Format::Uncompressed") = Uncompressed,
48 COMPRESSED BOTAN_DEPRECATED("Use EC_Point_Format::Compressed") = Compressed,
49
50 Hybrid BOTAN_DEPRECATED("Hybrid point encoding is deprecated") = 2,
51 HYBRID BOTAN_DEPRECATED("Hybrid point encoding is deprecated") = 2
52};

◆ ECIES_Flags

enum class Botan::ECIES_Flags : uint8_t
strong

Flags controlling ECIES operation

Two of the flags are related to how cofactors are handled. Support for cofactors is deprecated and will be removed in Botan4.

The CheckMode flag is completely ignored; we always check that the point is valid.

TODO(Botan4) remove this enum

Enumerator
None 
SingleHashMode 

if set: do NOT prefix the input of the (ecdh) key agreement with the encoded (ephemeral) public key

CofactorMode 

(decryption only) if set: use cofactor multiplication during (ecdh) key agreement This only matters if the curve has a cofactor

OldCofactorMode 

if set: use ecdhc instead of ecdh. This only matters if the curve has a cofactor

CheckMode 

(decryption only) if set: test if the (ephemeral) public key is on the curve Note that we actually ignore this flag and always check the key

NONE 
SINGLE_HASH_MODE 
COFACTOR_MODE 
OLD_COFACTOR_MODE 
CHECK_MODE 

Definition at line 44 of file ecies.h.

44 : uint8_t {
45 None = 0,
46 /// if set: do NOT prefix the input of the (ecdh) key agreement with the encoded (ephemeral) public key
48 /// (decryption only) if set: use cofactor multiplication during (ecdh) key agreement
49 /// This only matters if the curve has a cofactor
50 CofactorMode = 2,
51 /// if set: use ecdhc instead of ecdh.
52 /// This only matters if the curve has a cofactor
54 /// (decryption only) if set: test if the (ephemeral) public key is on the curve
55 /// Note that we actually ignore this flag and always check the key
56 CheckMode = 8,
57
58 NONE BOTAN_DEPRECATED("Use None") = None,
59 SINGLE_HASH_MODE BOTAN_DEPRECATED("Use SingleHashMode") = SingleHashMode,
60 COFACTOR_MODE BOTAN_DEPRECATED("Use CofactorMode") = CofactorMode,
61 OLD_COFACTOR_MODE BOTAN_DEPRECATED("Use OldCofactorMode") = OldCofactorMode,
62 CHECK_MODE BOTAN_DEPRECATED("Use CheckMode") = CheckMode,
63};
@ SingleHashMode
if set: do NOT prefix the input of the (ecdh) key agreement with the encoded (ephemeral) public key
Definition ecies.h:47

◆ ErrorType

enum class Botan::ErrorType : uint16_t
strong

Different types of errors that might occur

Enumerator
Unknown 

Some unknown error

SystemError 

An error while calling a system interface

NotImplemented 

An operation seems valid, but not supported by the current version

OutOfMemory 

Memory allocation failure

InternalError 

An internal error occurred

IoError 

An I/O error occurred

InvalidObjectState 

Invalid object state

KeyNotSet 

A key was not set on an object when this is required

InvalidArgument 

The application provided an argument which is invalid

InvalidKeyLength 

A key with invalid length was provided

InvalidNonceLength 

A nonce with invalid length was provided

LookupError 

An object type was requested but cannot be found

EncodingFailure 

Encoding a message or datum failed

DecodingFailure 

Decoding a message or datum failed

TLSError 

A TLS error (error_code will be the alert type)

HttpError 

An error during an HTTP operation

InvalidTag 

A message with an invalid authentication tag was detected

RoughtimeError 

An error during Roughtime validation

CommonCryptoError 

An error when interacting with CommonCrypto API

Pkcs11Error 

An error when interacting with a PKCS11 device

TPMError 

An error when interacting with a TPM device

DatabaseError 

An error when interacting with a database

ZlibError 

An error when interacting with zlib

Bzip2Error 

An error when interacting with bzip2

LzmaError 

An error when interacting with lzma

Definition at line 21 of file exceptn.h.

21 : uint16_t {
22 /** Some unknown error */
23 Unknown = 1,
24 /** An error while calling a system interface */
25 SystemError = 2,
26 /** An operation seems valid, but not supported by the current version */
28 /** Memory allocation failure */
29 OutOfMemory = 4,
30 /** An internal error occurred */
31 InternalError = 5,
32 /** An I/O error occurred */
33 IoError = 6,
34
35 /** Invalid object state */
37 /** A key was not set on an object when this is required */
38 KeyNotSet = 101,
39 /** The application provided an argument which is invalid */
40 InvalidArgument = 102,
41 /** A key with invalid length was provided */
42 InvalidKeyLength = 103,
43 /** A nonce with invalid length was provided */
45 /** An object type was requested but cannot be found */
46 LookupError = 105,
47 /** Encoding a message or datum failed */
48 EncodingFailure = 106,
49 /** Decoding a message or datum failed */
50 DecodingFailure = 107,
51 /** A TLS error (error_code will be the alert type) */
52 TLSError = 108,
53 /** An error during an HTTP operation */
54 HttpError = 109,
55 /** A message with an invalid authentication tag was detected */
56 InvalidTag = 110,
57 /** An error during Roughtime validation */
58 RoughtimeError = 111,
59
60 /** An error when interacting with CommonCrypto API */
62 /** An error when interacting with a PKCS11 device */
63 Pkcs11Error = 202,
64 /** An error when interacting with a TPM device */
65 TPMError = 203,
66 /** An error when interacting with a database */
67 DatabaseError = 204,
68
69 /** An error when interacting with zlib */
70 ZlibError = 300,
71 /** An error when interacting with bzip2 */
72 Bzip2Error = 301,
73 /** An error when interacting with lzma */
74 LzmaError = 302,
75
76};

◆ Extension_Context

enum class Botan::Extension_Context : uint8_t
strong
Enumerator
Certificate 
CRL 
CRL_Entry 
OCSP_Request 
OCSP_Response 

Definition at line 795 of file pkix_types.h.

◆ LMOTS_Algorithm_Type

enum class Botan::LMOTS_Algorithm_Type : uint32_t
strong

Enum of available LM-OTS algorithm types.

The supported parameter sets are defined in RFC 8554 Section 4.1. and draft-fluhrer-lms-more-parm-sets-11 Section 4. HSS/LMS typecodes are introduced in RFC 8554 Section 3.2. and their format specified in Section 3.3.

Enumerator
RESERVED 
SHA256_N32_W1 
SHA256_N32_W2 
SHA256_N32_W4 
SHA256_N32_W8 
SHA256_N24_W1 
SHA256_N24_W2 
SHA256_N24_W4 
SHA256_N24_W8 
SHAKE_N32_W1 
SHAKE_N32_W2 
SHAKE_N32_W4 
SHAKE_N32_W8 
SHAKE_N24_W1 
SHAKE_N24_W2 
SHAKE_N24_W4 
SHAKE_N24_W8 

Definition at line 69 of file lm_ots.h.

69 : uint32_t /* NOLINT(*-enum-size) */ {
70 // --- RFC 8554 ---
71 RESERVED = 0x00,
72
73 // SHA-256 based
74 SHA256_N32_W1 = 0x01,
75 SHA256_N32_W2 = 0x02,
76 SHA256_N32_W4 = 0x03,
77 SHA256_N32_W8 = 0x04,
78
79 // --- draft-fluhrer-lms-more-parm-sets-11 ---
80 // SHA-256/192 based
81 SHA256_N24_W1 = 0x05,
82 SHA256_N24_W2 = 0x06,
83 SHA256_N24_W4 = 0x07,
84 SHA256_N24_W8 = 0x08,
85
86 // SHAKE-256/256 based
87 SHAKE_N32_W1 = 0x09,
88 SHAKE_N32_W2 = 0x0a,
89 SHAKE_N32_W4 = 0x0b,
90 SHAKE_N32_W8 = 0x0c,
91
92 // SHAKE-256/192 based
93 SHAKE_N24_W1 = 0x0d,
94 SHAKE_N24_W2 = 0x0e,
95 SHAKE_N24_W4 = 0x0f,
96 SHAKE_N24_W8 = 0x10,
97};

◆ LMS_Algorithm_Type

enum class Botan::LMS_Algorithm_Type : uint32_t
strong

Enum of available LMS algorithm types.

The supported parameter sets are defined in RFC 8554 Section 5.1. and draft-fluhrer-lms-more-parm-sets-11 Section 5. HSS/LMS typecodes are introduced in RFC 8554 Section 3.2. and their format specified in Section 3.3.

Enumerator
RESERVED 
SHA256_M32_H5 
SHA256_M32_H10 
SHA256_M32_H15 
SHA256_M32_H20 
SHA256_M32_H25 
SHA256_M24_H5 
SHA256_M24_H10 
SHA256_M24_H15 
SHA256_M24_H20 
SHA256_M24_H25 
SHAKE_M32_H5 
SHAKE_M32_H10 
SHAKE_M32_H15 
SHAKE_M32_H20 
SHAKE_M32_H25 
SHAKE_M24_H5 
SHAKE_M24_H10 
SHAKE_M24_H15 
SHAKE_M24_H20 
SHAKE_M24_H25 

Definition at line 32 of file lms.h.

32 : uint32_t /* NOLINT(*-enum-size) */ {
33 // --- RFC 8554 ---
34 RESERVED = 0x00,
35
36 // SHA-256 based
37 SHA256_M32_H5 = 0x05,
38 SHA256_M32_H10 = 0x06,
39 SHA256_M32_H15 = 0x07,
40 SHA256_M32_H20 = 0x08,
41 SHA256_M32_H25 = 0x09,
42
43 // --- draft-fluhrer-lms-more-parm-sets-11 ---
44 // SHA-256/192 based
45 SHA256_M24_H5 = 0x0a,
46 SHA256_M24_H10 = 0x0b,
47 SHA256_M24_H15 = 0x0c,
48 SHA256_M24_H20 = 0x0d,
49 SHA256_M24_H25 = 0x0e,
50
51 // SHAKE-256/256 based
52 SHAKE_M32_H5 = 0x0f,
53 SHAKE_M32_H10 = 0x10,
54 SHAKE_M32_H15 = 0x11,
55 SHAKE_M32_H20 = 0x12,
56 SHAKE_M32_H25 = 0x13,
57
58 // SHAKE-256/192 based
59 SHAKE_M24_H5 = 0x14,
60 SHAKE_M24_H10 = 0x15,
61 SHAKE_M24_H15 = 0x16,
62 SHAKE_M24_H20 = 0x17,
63 SHAKE_M24_H25 = 0x18
64};

◆ MD_Endian

enum class Botan::MD_Endian : uint8_t
strong
Enumerator
Little 
Big 

Definition at line 20 of file mdx_hash.h.

20 : uint8_t {
21 Little,
22 Big,
23};

◆ MlPrivateKeyFormat

enum class Botan::MlPrivateKeyFormat : uint8_t
strong

Encoding format of an ML-KEM or ML-DSA private key

Enumerator
Seed 

Only the private random seed from which the key pair is expanded.

  • ML-KEM: the 64-byte seed d || z (FIPS 203)
  • ML-DSA: the 32-byte seed xi (FIPS 204)

As content of the PKCS#8 privateKey field this is the "seed" CHOICE alternative ([0] IMPLICIT OCTET STRING) of RFC 9935 (ML-KEM) or RFC 9881 (ML-DSA). This is the format of newly generated ML-KEM and ML-DSA keys.

Not available for the pre-standard Kyber and Dilithium round 3 variants.

Expanded 

The expanded private key as specified in FIPS 203 (ML-KEM) or FIPS 204 (ML-DSA). As content of the PKCS#8 privateKey field this is the "expandedKey" CHOICE alternative (OCTET STRING) of RFC 9935 (ML-KEM) or RFC 9881 (ML-DSA).

This is the only format supported by the pre-standard Kyber and Dilithium round 3 variants.

Both 

Seed and expanded key together. As content of the PKCS#8 privateKey field this is the "both" CHOICE alternative (SEQUENCE { seed OCTET STRING, expandedKey OCTET STRING }) of RFC 9935 (ML-KEM) or RFC 9881 (ML-DSA).

There is no raw (non-ASN.1) encoding of this format.

Definition at line 20 of file module_lattice_keys.h.

20 : uint8_t {
21 /**
22 * Only the private random seed from which the key pair is expanded.
23 *
24 * - ML-KEM: the 64-byte seed d || z (FIPS 203)
25 * - ML-DSA: the 32-byte seed xi (FIPS 204)
26 *
27 * As content of the PKCS#8 privateKey field this is the "seed" CHOICE
28 * alternative ([0] IMPLICIT OCTET STRING) of RFC 9935 (ML-KEM) or
29 * RFC 9881 (ML-DSA). This is the format of newly generated ML-KEM and
30 * ML-DSA keys.
31 *
32 * Not available for the pre-standard Kyber and Dilithium round 3 variants.
33 */
34 Seed,
35 /**
36 * The expanded private key as specified in FIPS 203 (ML-KEM) or FIPS 204
37 * (ML-DSA). As content of the PKCS#8 privateKey field this is the
38 * "expandedKey" CHOICE alternative (OCTET STRING) of RFC 9935 (ML-KEM) or
39 * RFC 9881 (ML-DSA).
40 *
41 * This is the only format supported by the pre-standard Kyber and
42 * Dilithium round 3 variants.
43 */
45 /**
46 * Seed and expanded key together. As content of the PKCS#8 privateKey
47 * field this is the "both" CHOICE alternative
48 * (SEQUENCE { seed OCTET STRING, expandedKey OCTET STRING }) of RFC 9935
49 * (ML-KEM) or RFC 9881 (ML-DSA).
50 *
51 * There is no raw (non-ASN.1) encoding of this format.
52 */
53 Both,
54};

◆ PublicKeyOperation

enum class Botan::PublicKeyOperation : uint8_t
strong

Enumeration of possible operations a public key could be used for.

It is possible to query if a key supports a particular operation type using Asymmetric_Key::supports_operation()

Enumerator
Encryption 
Signature 
KeyEncapsulation 
KeyAgreement 

Definition at line 50 of file pk_keys.h.

◆ Signature_Format

enum class Botan::Signature_Format : uint8_t
strong

Enumeration specifying the signature format.

This is mostly used for requesting DER encoding of ECDSA signatures; most other algorithms only support "standard".

Enumerator
Standard 
DerSequence 
IEEE_1363 
DER_SEQUENCE 

Definition at line 36 of file pk_keys.h.

36 : uint8_t {
37 Standard = 0,
38 DerSequence = 1,
39
40 IEEE_1363 BOTAN_DEPRECATED("Use Standard") = Standard,
41 DER_SEQUENCE BOTAN_DEPRECATED("Use DerSequence") = DerSequence,
42};

◆ Sphincs_Address_Type

enum class Botan::Sphincs_Address_Type : uint32_t
strong
Enumerator
WotsHash 
WotsPublicKeyCompression 
HashTree 
ForsTree 
ForsTreeRootsCompression 
WotsKeyGeneration 
ForsKeyGeneration 

Definition at line 18 of file sp_address.h.

◆ Sphincs_Hash_Type

enum class Botan::Sphincs_Hash_Type : uint8_t
strong
Enumerator
Shake256 
Sha256 
Haraka 

Haraka is currently not supported.

Definition at line 18 of file sp_parameters.h.

18 : uint8_t {
20 Sha256,
21 Haraka BOTAN_DEPRECATED("Haraka is not and will not be supported"), ///< Haraka is currently not supported
22};
@ Haraka
Haraka is currently not supported.

◆ Sphincs_Parameter_Set

enum class Botan::Sphincs_Parameter_Set : uint8_t
strong
Enumerator
Sphincs128Small 
Sphincs128Fast 
Sphincs192Small 
Sphincs192Fast 
Sphincs256Small 
Sphincs256Fast 
SLHDSA128Small 
SLHDSA128Fast 
SLHDSA192Small 
SLHDSA192Fast 
SLHDSA256Small 
SLHDSA256Fast 

Definition at line 24 of file sp_parameters.h.

◆ TPM_Storage_Type

enum class Botan::TPM_Storage_Type
strong
Enumerator
User 
System 

Definition at line 102 of file tpm.h.

◆ Usage_Type

enum class Botan::Usage_Type : uint8_t
strong
Enumerator
UNSPECIFIED 
TLS_SERVER_AUTH 
TLS_CLIENT_AUTH 
CERTIFICATE_AUTHORITY 
OCSP_RESPONDER 
ENCRYPTION 

Definition at line 289 of file pkix_enums.h.

◆ WOTS_Derivation_Method

enum class Botan::WOTS_Derivation_Method : uint8_t
strong

Determines how WOTS+ private keys are derived from the XMSS private key

Enumerator
Botan2x 

This roughly followed the suggestions in RFC 8391 but is vulnerable to a multi-target attack. For new private keys, we recommend using the derivation as suggested in NIST SP.800-208. Private keys generated with Botan 2.x will need to stay with this mode, otherwise they won't be able to generate valid signatures any longer.

NIST_SP800_208 

Derivation as specified in NIST SP.800-208 to avoid a multi-target attack on the WOTS+ key derivation suggested in RFC 8391. New private keys should use this mode.

Definition at line 151 of file xmss.h.

151 : uint8_t {
152 /// This roughly followed the suggestions in RFC 8391 but is vulnerable
153 /// to a multi-target attack. For new private keys, we recommend using
154 /// the derivation as suggested in NIST SP.800-208.
155 /// Private keys generated with Botan 2.x will need to stay with this mode,
156 /// otherwise they won't be able to generate valid signatures any longer.
157 Botan2x = 1,
158
159 /// Derivation as specified in NIST SP.800-208 to avoid a multi-target attack
160 /// on the WOTS+ key derivation suggested in RFC 8391. New private keys
161 /// should use this mode.
162 NIST_SP800_208 = 2,
163};

Function Documentation

◆ abs()

BigInt Botan::abs ( const BigInt & n)
inline

Return the absolute value

Parameters
nan integer
Returns
absolute value of n

Definition at line 22 of file numthry.h.

22 {
23 return n.abs();
24}
BigInt abs() const
Definition bigint.cpp:387

References Botan::BigInt::abs().

Referenced by Botan::EC_Group::EC_Group(), gcd(), Botan::EC_Group::register_custom_group(), and Botan::EC_Group::verify_group().

◆ absorb_into_sponge() [1/2]

void Botan::absorb_into_sponge ( detail::SpongeLikeWithTrivialPermute auto & sponge,
std::span< const uint8_t > input )
inline

Definition at line 232 of file sponge_processing.h.

232 {
233 absorb_into_sponge(sponge, input, [&sponge] { sponge.permute(); });
234}
void absorb_into_sponge(SpongeT &sponge, std::span< const uint8_t > input, const detail::PermutationFn auto &permutation_fn)

References absorb_into_sponge().

◆ absorb_into_sponge() [2/2]

template<detail::SpongeLike SpongeT>
void Botan::absorb_into_sponge ( SpongeT & sponge,
std::span< const uint8_t > input,
const detail::PermutationFn auto & permutation_fn )
inline

Absorbs input data into the sponge state.

Parameters
Sponge HelperThe sponge state to absorb data into.
inputThe input data to absorb.
permutation_fnThe function to call for the sponge's permutation.

Definition at line 220 of file sponge_processing.h.

222 {
223 using word_t = typename SpongeT::word_t;
224
225 BufferSlicer input_slicer(input);
226 process_bytes_in_sponge(sponge, input.size(), permutation_fn, [&](word_t state_word, auto bounds) {
227 return state_word ^ bounds.read_from(input_slicer);
228 });
229 BOTAN_ASSERT_NOMSG(input_slicer.empty());
230}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
BOTAN_FORCE_INLINE void process_bytes_in_sponge(SpongeT &sponge, size_t bytes_to_process, const detail::PermutationFn auto &permutation_fn, const detail::ModifierFn< SpongeT > auto &modifier_fn)

References BOTAN_ASSERT_NOMSG, Botan::BufferSlicer::empty(), and process_bytes_in_sponge().

Referenced by Botan::Ascon_p::absorb(), Botan::Keccak_Permutation::absorb(), and absorb_into_sponge().

◆ acknowledge_always_deterministic()

◆ add_or_throw()

template<std::unsigned_integral T>
T Botan::add_or_throw ( T a,
T b,
std::string_view msg )
constexpr

◆ allocate_memory()

void * Botan::allocate_memory ( size_t elems,
size_t elem_size )

Allocate a memory buffer by some method. This should only be used for primitive types (uint8_t, uint32_t, etc).

Parameters
elemsthe number of elements
elem_sizethe size of each element
Returns
pointer to allocated and zeroed memory, or throw std::bad_alloc on failure

Definition at line 21 of file allocator.cpp.

21 {
22 if(elems == 0 || elem_size == 0) {
23 return nullptr;
24 }
25
26 // Some calloc implementations do not check for overflow (?!?)
27 if(!checked_mul(elems, elem_size).has_value()) {
28 throw std::bad_alloc();
29 }
30
31#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
32 // NOLINTNEXTLINE(*-const-correctness) bug in clang-tidy
33 if(void* p = mlock_allocator::instance().allocate(elems, elem_size)) {
34 return p;
35 }
36#endif
37
38#if defined(BOTAN_TARGET_OS_HAS_ALLOC_CONCEAL)
39 void* ptr = ::calloc_conceal(elems, elem_size);
40#else
41 // NOLINTNEXTLINE(*-const-correctness) bug in clang-tidy
42 void* ptr = std::calloc(elems, elem_size); // NOLINT(*-no-malloc,*-owning-memory)
43#endif
44 if(ptr == nullptr) {
45 [[unlikely]] throw std::bad_alloc();
46 }
47 return ptr;
48}
static mlock_allocator & instance() noexcept
constexpr std::optional< T > checked_mul(T a, T b)
Definition int_utils.h:46

References BOTAN_MALLOC_FN, checked_mul(), and Botan::mlock_allocator::instance().

Referenced by Botan::secure_allocator< T >::allocate().

◆ any_null_pointers()

template<typename... Ptrs>
bool Botan::any_null_pointers ( Ptrs... ptr)

Return true if any of the provided arguments are null

Definition at line 54 of file mem_utils.h.

54 {
55 static_assert((... && std::is_pointer_v<Ptrs>), "All arguments must be pointers");
56 return (... || (ptr == nullptr));
57}

Referenced by botan_ec_group_from_ber(), botan_ec_group_from_name(), botan_ec_group_from_pem(), botan_ec_group_supports_named_group(), botan_ec_point_add(), botan_ec_point_from_bytes(), botan_ec_point_from_xy(), botan_ec_point_generator(), botan_ec_point_get_group(), botan_ec_point_identity(), botan_ec_point_mul(), botan_ec_point_negate(), botan_ec_point_to_mp_xy(), botan_ec_privkey_get_group(), botan_ec_privkey_get_private_key(), botan_ec_pubkey_get_group(), botan_ec_scalar_from_mp(), botan_ec_scalar_get_group(), botan_ec_scalar_random(), botan_ec_scalar_to_mp(), botan_pk_op_decrypt_create(), botan_pk_op_encrypt_create(), botan_pk_op_kem_decrypt_create(), botan_pk_op_kem_decrypt_shared_key(), botan_pk_op_kem_encrypt_create(), botan_pk_op_key_agreement_create(), botan_pk_op_sign_create(), botan_pk_op_verify_create(), botan_privkey_create_dsa(), botan_privkey_create_ecdh(), botan_privkey_create_elgamal(), botan_privkey_load_classic_mceliece(), botan_privkey_load_ecdh(), botan_privkey_load_ecdsa(), botan_privkey_load_frodokem(), botan_privkey_load_kyber(), botan_privkey_load_ml_dsa(), botan_privkey_load_ml_kem(), botan_privkey_load_rsa_pkcs1(), botan_privkey_load_slh_dsa(), botan_privkey_load_sm2(), botan_pubkey_load_classic_mceliece(), botan_pubkey_load_ecdh(), botan_pubkey_load_ecdh_sec1(), botan_pubkey_load_ecdsa(), botan_pubkey_load_ecdsa_sec1(), botan_pubkey_load_frodokem(), botan_pubkey_load_kyber(), botan_pubkey_load_ml_dsa(), botan_pubkey_load_ml_kem(), botan_pubkey_load_rsa_pkcs1(), botan_pubkey_load_slh_dsa(), botan_pubkey_load_sm2(), botan_pubkey_load_sm2_sec1(), botan_pubkey_sm2_compute_za(), botan_x509_cert_allowed_extended_usage_str(), botan_x509_cert_excluded_name_constraints(), botan_x509_cert_excluded_name_constraints_count(), botan_x509_cert_get_issuer_dn_count(), botan_x509_cert_get_path_length_constraint(), botan_x509_cert_get_subject_dn_count(), botan_x509_cert_issuer_alternative_names(), botan_x509_cert_issuer_alternative_names_count(), botan_x509_cert_load(), botan_x509_cert_load_file(), botan_x509_cert_permitted_name_constraints(), botan_x509_cert_permitted_name_constraints_count(), botan_x509_cert_serial_number(), botan_x509_cert_subject_alternative_names(), botan_x509_cert_subject_alternative_names_count(), botan_x509_crl_create(), botan_x509_crl_entries(), botan_x509_crl_entries_count(), botan_x509_crl_entry_create(), botan_x509_crl_entry_reason(), botan_x509_crl_entry_revocation_date(), botan_x509_crl_entry_serial_number(), botan_x509_crl_load(), botan_x509_crl_load_file(), botan_x509_crl_next_update(), botan_x509_crl_this_update(), botan_x509_crl_update(), botan_x509_crl_view_issuer_dn(), botan_x509_crl_view_issuer_dn_count(), botan_x509_ext_as_blocks_get_entry_at(), botan_x509_ext_as_blocks_get_info(), botan_x509_ext_ip_addr_blocks_get_address(), botan_x509_ext_ip_addr_blocks_get_counts(), botan_x509_ext_ip_addr_blocks_get_family(), botan_x509_general_name_get_type(), botan_xof_block_size(), botan_xof_init(), botan_xof_name(), botan_xof_output(), botan_xof_update(), botan_zfec_decode(), and botan_zfec_encode().

◆ append()

template<typename T, typename Alloc>
void Botan::append ( std::vector< T, Alloc > & out,
std::type_identity_t< std::span< const T > > in )

Append in to the end of out

For a vector with a non-standard allocator (eg secure_vector), insert() falls back to an element-wise copy loop in libstdc++; this uses memcpy.

Definition at line 132 of file concat_util.h.

132 {
133 const size_t offset = out.size();
134 out.resize(offset + in.size());
135 copy_mem(std::span{out}.subspan(offset), in);
136}
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144

References copy_mem().

Referenced by Botan::DER_Encoder::DER_Encoder(), Botan::OID::encode_into(), Botan::AlignmentBuffer< T, BLOCK_SIZE, FINAL_BLOCK_STRATEGY >::handle_unaligned_data(), and Botan::TLS::TLS_Record_Layer::prepare_record().

◆ argon2()

void Botan::argon2 ( uint8_t output[],
size_t output_len,
const char * password,
size_t password_len,
const uint8_t salt[],
size_t salt_len,
const uint8_t key[],
size_t key_len,
const uint8_t ad[],
size_t ad_len,
uint8_t y,
size_t p,
size_t M,
size_t t )
inline

Argon2 key derivation function

Parameters
outputthe output will be placed here
output_lenlength of output
passwordthe user password
password_lenthe length of password
saltthe salt
salt_lenlength of salt
keyan optional secret key
key_lenthe length of key
adan optional additional input
ad_lenthe length of ad
ythe Argon2 variant (0 = Argon2d, 1 = Argon2i, 2 = Argon2id)
pthe parallelization parameter
Mthe amount of memory to use in Kb
tthe number of iterations to use

Definition at line 143 of file argon2.h.

156 {
157 auto pwdhash_fam = PasswordHashFamily::create_or_throw([y] {
158 switch(y) {
159 case 0:
160 return "Argon2d";
161 case 1:
162 return "Argon2i";
163 case 2:
164 return "Argon2id";
165 default:
166 throw Not_Implemented("Unknown Argon2 family type");
167 }
168 }());
169 auto pwdhash = pwdhash_fam->from_params(M, t, p);
170 pwdhash->derive_key(output, output_len, password, password_len, salt, salt_len, ad, ad_len, key, key_len);
171}
static std::unique_ptr< PasswordHashFamily > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition pwdhash.cpp:125

References argon2(), and Botan::PasswordHashFamily::create_or_throw().

Referenced by argon2().

◆ argon2_check_pwhash()

bool Botan::argon2_check_pwhash ( const char * password,
size_t password_len,
std::string_view hash )

Check a previously created password hash

Verify an Argon2 password hash against the provided password. Returns false if the input hash seems malformed or if the computed hash does not match.

Parameters
passwordthe password to check against
password_lenthe length of password
Hashesthe stored hash to check against

Definition at line 77 of file argon2fmt.cpp.

77 {
78 try {
79 const std::vector<std::string> parts = split_on(input_hash, '$');
80
81 if(parts.size() != 5) {
82 return false;
83 }
84
85 uint8_t family = 0;
86
87 if(parts[0] == "argon2d") {
88 family = 0;
89 } else if(parts[0] == "argon2i") {
90 family = 1;
91 } else if(parts[0] == "argon2id") {
92 family = 2;
93 } else {
94 return false;
95 }
96
97 if(parts[1] != "v=19") {
98 return false;
99 }
100
101 const std::vector<std::string> params = split_on(parts[2], ',');
102
103 if(params.size() != 3) {
104 return false;
105 }
106
107 size_t M = 0;
108 size_t t = 0;
109 size_t p = 0;
110
111 for(const auto& param_str : params) {
112 const std::vector<std::string> param = split_on(param_str, '=');
113
114 if(param.size() != 2) {
115 return false;
116 }
117
118 const std::string_view key = param[0];
119 const size_t val = to_u32bit(param[1]);
120 if(key == "m") {
121 M = val;
122 } else if(key == "t") {
123 t = val;
124 } else if(key == "p") {
125 p = val;
126 } else {
127 return false;
128 }
129 }
130
131 std::vector<uint8_t> salt(base64_decode_max_output(parts[3].size()));
132 salt.resize(base64_decode(salt.data(), parts[3], false));
133
134 std::vector<uint8_t> hash(base64_decode_max_output(parts[4].size()));
135 hash.resize(base64_decode(hash.data(), parts[4], false));
136
137 if(hash.size() < 4) {
138 return false;
139 }
140
141 std::vector<uint8_t> generated(hash.size());
142 auto pwdhash_fam = PasswordHashFamily::create_or_throw(argon2_family(family));
143 auto pwdhash = pwdhash_fam->from_params(M, t, p);
144
145 pwdhash->derive_key(generated.data(), generated.size(), password, password_len, salt.data(), salt.size());
146
147 return CT::is_equal(generated.data(), hash.data(), generated.size()).as_bool();
148 } catch(...) {
149 return false;
150 }
151}
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:803
std::vector< std::string > split_on(std::string_view str, char delim)
Definition parsing.cpp:83
size_t base64_decode(uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Definition base64.cpp:203
size_t base64_decode_max_output(size_t input_length)
Definition base64.cpp:273
uint32_t to_u32bit(std::string_view input)
Definition parsing.cpp:75

References base64_decode(), base64_decode_max_output(), Botan::PasswordHashFamily::create_or_throw(), Botan::CT::is_equal(), split_on(), and to_u32bit().

◆ argon2_generate_pwhash()

std::string Botan::argon2_generate_pwhash ( const char * password,
size_t password_len,
RandomNumberGenerator & rng,
size_t p,
size_t M,
size_t t,
uint8_t y = 2,
size_t salt_len = 16,
size_t output_len = 32 )

Generate an Argon2 hash of the specified password. The y parameter specifies the variant: 0 for Argon2d, 1 for Argon2i, and 2 for Argon2id.

Definition at line 42 of file argon2fmt.cpp.

50 {
51 std::vector<uint8_t> salt(salt_len);
52 rng.randomize(salt.data(), salt.size());
53
54 std::vector<uint8_t> output(output_len);
55
56 auto pwdhash_fam = PasswordHashFamily::create_or_throw(argon2_family(y));
57 auto pwdhash = pwdhash_fam->from_params(M, t, p);
58
59 pwdhash->derive_key(output.data(), output.size(), password, password_len, salt.data(), salt.size());
60
61 const auto enc_salt = strip_padding(base64_encode(salt));
62 const auto enc_output = strip_padding(base64_encode(output));
63
64 const std::string argon2_mode = [&]() -> std::string {
65 if(y == 0) {
66 return "d";
67 } else if(y == 1) {
68 return "i";
69 } else {
70 return "id";
71 }
72 }();
73
74 return fmt("$argon2{}$v=19$m={},t={},p={}${}${}", argon2_mode, M, t, p, enc_salt, enc_output);
75}
void randomize(std::span< uint8_t > output)
Definition rng.h:86
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
size_t base64_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition base64.cpp:167

References base64_encode(), Botan::PasswordHashFamily::create_or_throw(), fmt(), and Botan::RandomNumberGenerator::randomize().

◆ as_span_of_bytes() [1/3]

◆ as_span_of_bytes() [2/3]

std::span< const uint8_t > Botan::as_span_of_bytes ( const std::string & s)
inline

Definition at line 64 of file mem_utils.h.

64 {
65 return as_span_of_bytes(s.data(), s.size());
66}
std::span< const uint8_t > as_span_of_bytes(const char *s, size_t len)
Definition mem_utils.h:59

References as_span_of_bytes().

◆ as_span_of_bytes() [3/3]

std::span< const uint8_t > Botan::as_span_of_bytes ( std::string_view s)
inline

Definition at line 68 of file mem_utils.h.

68 {
69 return as_span_of_bytes(s.data(), s.size());
70}

References as_span_of_bytes().

◆ asn1_class_to_string()

std::string BOTAN_UNSTABLE_API Botan::asn1_class_to_string ( ASN1_Class type)

Return a descriptive string for an ASN.1 class tag

Definition at line 110 of file asn1_obj.cpp.

110 {
111 switch(type) {
113 return "UNIVERSAL";
115 return "CONSTRUCTED";
117 return "CONTEXT_SPECIFIC";
119 return "APPLICATION";
121 return "PRIVATE";
123 return "NO_OBJECT";
124 default:
125 return "CLASS(" + std::to_string(static_cast<size_t>(type)) + ")";
126 }
127}

References Application, Constructed, ContextSpecific, NoObject, Private, and Universal.

Referenced by Botan::BER_Object::assert_is_a().

◆ asn1_tag_to_string()

std::string BOTAN_UNSTABLE_API Botan::asn1_tag_to_string ( ASN1_Type type)

Return a descriptive string for an ASN.1 type tag

Definition at line 129 of file asn1_obj.cpp.

129 {
130 switch(type) {
132 return "SEQUENCE";
133
134 case ASN1_Type::Set:
135 return "SET";
136
138 return "PRINTABLE STRING";
139
141 return "NUMERIC STRING";
142
144 return "IA5 STRING";
145
147 return "T61 STRING";
148
150 return "UTF8 STRING";
151
153 return "VISIBLE STRING";
154
156 return "BMP STRING";
157
159 return "UNIVERSAL STRING";
160
162 return "UTC TIME";
163
165 return "GENERALIZED TIME";
166
168 return "OCTET STRING";
169
171 return "BIT STRING";
172
174 return "ENUMERATED";
175
177 return "INTEGER";
178
179 case ASN1_Type::Null:
180 return "NULL";
181
183 return "OBJECT";
184
186 return "BOOLEAN";
187
189 return "NO_OBJECT";
190
191 default:
192 return "TAG(" + std::to_string(static_cast<uint32_t>(type)) + ")";
193 }
194}

References BitString, BmpString, Boolean, Enumerated, GeneralizedTime, Ia5String, Integer, NoObject, Null, NumericString, ObjectId, OctetString, PrintableString, Sequence, Set, TeletexString, UniversalString, UtcTime, Utf8String, and VisibleString.

Referenced by Botan::ASN1_String::ASN1_String(), Botan::BER_Object::assert_is_a(), and Botan::ASN1_String::decode_from().

◆ assert_unreachable()

void BOTAN_UNSTABLE_API Botan::assert_unreachable ( const char * file,
int line )

Define Botan::assert_unreachable and BOTAN_ASSERT_UNREACHABLE

This is intended to be used in the same situations as std::unreachable(); a codepath that (should not) be reachable but where the compiler cannot tell that it is unreachable.

Unlike std::unreachable(), or equivalent compiler builtins like GCC's __builtin_unreachable, this function is not UB. By default it will throw an exception. If BOTAN_TERMINATE_ON_ASSERTS is defined, it will instead print a message to stderr and abort.

Due to this difference, and the fact that it is not inlined, calling this is significantly more costly than using std::unreachable.

Parameters
filethe source file the call occurred in
linethe source line the call occurred on

Definition at line 61 of file assert.cpp.

61 {
62 const std::string msg = fmt("Codepath that was marked unreachable was reached @{}:{}", file, line);
63
64#if defined(BOTAN_TERMINATE_ON_ASSERTS)
65 std::cerr << msg << '\n';
66 std::abort();
67#else
68 throw Internal_Error(msg);
69#endif
70}

References fmt().

◆ assertion_failure()

void Botan::assertion_failure ( const char * expr_str,
const char * assertion_made,
const char * func,
const char * file,
int line )

Called when an assertion fails Throws an Exception object

Definition at line 36 of file assert.cpp.

36 {
37 std::ostringstream format;
38
39 format << "False assertion ";
40
41 if(assertion_made != nullptr && assertion_made[0] != 0) {
42 format << "'" << assertion_made << "' (expression " << expr_str << ") ";
43 } else {
44 format << expr_str << " ";
45 }
46
47 if(func != nullptr) {
48 format << "in " << func << " ";
49 }
50
51 format << "@" << file << ":" << line;
52
53#if defined(BOTAN_TERMINATE_ON_ASSERTS)
54 std::cerr << format.str() << '\n';
55 std::abort();
56#else
57 throw Internal_Error(format.str());
58#endif
59}

◆ base32_decode() [1/5]

secure_vector< uint8_t > Botan::base32_decode ( const char input[],
size_t input_length,
bool ignore_ws = true )

Perform base32 decoding

Parameters
inputsome base32 input
input_lengththe length of input in bytes
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
decoded base32 output

Definition at line 167 of file base32.cpp.

167 {
168 return base_decode_to_vec<secure_vector<uint8_t>>(Base32(), input, input_length, ignore_ws);
169}
Vector base_decode_to_vec(const Base &base, const char input[], size_t input_length, bool ignore_ws)
Definition codec_base.h:216

References base_decode_to_vec().

◆ base32_decode() [2/5]

secure_vector< uint8_t > Botan::base32_decode ( std::string_view input,
bool ignore_ws = true )

Perform base32 decoding

Parameters
inputsome base32 input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
decoded base32 output

Definition at line 171 of file base32.cpp.

171 {
172 return base32_decode(input.data(), input.size(), ignore_ws);
173}
size_t base32_decode(uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Definition base32.cpp:154

References base32_decode().

◆ base32_decode() [3/5]

size_t Botan::base32_decode ( uint8_t output[],
const char input[],
size_t input_length,
size_t & input_consumed,
bool final_inputs,
bool ignore_ws = true )

Perform base32 decoding

Parameters
outputan array of at least base32_decode_max_output bytes
inputsome base32 input
input_lengthlength of input in bytes
input_consumedis an output parameter which says how many bytes of input were actually consumed. If less than input_length, then the range input[consumed:length] should be passed in later along with more input.
final_inputstrue iff this is the last input, in which case padding is allowed
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 154 of file base32.cpp.

155 {
156 return base_decode(Base32(), out, in, input_length, input_consumed, final_inputs, ignore_ws);
157}
size_t base_decode(const Base &base, uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws=true)
Definition codec_base.h:118

References base_decode().

Referenced by base32_decode(), and base32_decode().

◆ base32_decode() [4/5]

size_t Botan::base32_decode ( uint8_t output[],
const char input[],
size_t input_length,
bool ignore_ws = true )

Perform base32 decoding

Parameters
outputan array of at least base32_decode_max_output bytes
inputsome base32 input
input_lengthlength of input in bytes
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 159 of file base32.cpp.

159 {
160 return base_decode_full(Base32(), output, input, input_length, ignore_ws);
161}
size_t base_decode_full(const Base &base, uint8_t output[], const char input[], size_t input_length, bool ignore_ws)
Definition codec_base.h:204

References base_decode_full().

◆ base32_decode() [5/5]

size_t Botan::base32_decode ( uint8_t output[],
std::string_view input,
bool ignore_ws = true )

Perform base32 decoding

Parameters
outputan array of at least base32_decode_max_output bytes
inputsome base32 input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 163 of file base32.cpp.

163 {
164 return base32_decode(output, input.data(), input.length(), ignore_ws);
165}

References base32_decode().

◆ base32_decode_max_output()

size_t Botan::base32_decode_max_output ( size_t input_length)

Calculate the size of output buffer for base32_decode

Parameters
input_lengththe length of input in bytes
Returns
the size of output buffer in bytes

Definition at line 179 of file base32.cpp.

179 {
180 return Base32::decode_max_output(input_length);
181}

◆ base32_encode() [1/3]

size_t Botan::base32_encode ( char output[],
const uint8_t input[],
size_t input_length,
size_t & input_consumed,
bool final_inputs )

Perform base32 encoding

Parameters
outputan array of at least base32_encode_max_output bytes
inputis some binary data
input_lengthlength of input in bytes
input_consumedis an output parameter which says how many bytes of input were actually consumed. If less than input_length, then the range input[consumed:length] should be passed in later along with more input.
final_inputstrue iff this is the last input, in which case padding chars will be applied if needed
Returns
number of bytes written to output

Definition at line 146 of file base32.cpp.

146 {
147 return base_encode(Base32(), out, in, input_length, input_consumed, final_inputs);
148}
size_t base_encode(const Base &base, char output[], const uint8_t input[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition codec_base.h:35

References base_encode().

Referenced by base32_encode().

◆ base32_encode() [2/3]

std::string Botan::base32_encode ( const uint8_t input[],
size_t input_length )

Perform base32 encoding

Parameters
inputsome input
input_lengthlength of input in bytes
Returns
base32 representation of input

Definition at line 150 of file base32.cpp.

150 {
151 return base_encode_to_string(Base32(), input, input_length);
152}
std::string base_encode_to_string(const Base &base, const uint8_t input[], size_t input_length)
Definition codec_base.h:84

References base_encode_to_string().

◆ base32_encode() [3/3]

std::string Botan::base32_encode ( std::span< const uint8_t > input)
inline

Perform base32 encoding

Parameters
inputsome input
Returns
base32 representation of input

Definition at line 47 of file base32.h.

47 {
48 return base32_encode(input.data(), input.size());
49}
size_t base32_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition base32.cpp:146

References base32_encode().

◆ base32_encode_max_output()

size_t Botan::base32_encode_max_output ( size_t input_length)

Calculate the size of output buffer for base32_encode

Parameters
input_lengththe length of input in bytes
Returns
the size of output buffer in bytes

Definition at line 175 of file base32.cpp.

175 {
176 return Base32::encode_max_output(input_length);
177}

◆ base58_check_decode() [1/2]

std::vector< uint8_t > Botan::base58_check_decode ( const char input[],
size_t input_length )

Perform base58 decoding with checksum

Definition at line 403 of file base58.cpp.

403 {
404 std::vector<uint8_t> dec = base58_decode(input, input_length);
405
406 if(dec.size() < 4) {
407 throw Decoding_Error("Invalid base58 too short for checksum");
408 }
409
410 const uint32_t computed_checksum = sha256_d_checksum(dec.data(), dec.size() - 4);
411 const uint32_t checksum = load_be<uint32_t>(&dec[dec.size() - 4], 0);
412
413 if(checksum != computed_checksum) {
414 throw Decoding_Error("Invalid base58 checksum");
415 }
416
417 dec.resize(dec.size() - 4);
418
419 return dec;
420}
std::vector< uint8_t > base58_decode(const char input[], size_t input_length)
Definition base58.cpp:314
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504

References base58_decode(), and load_be().

Referenced by base58_check_decode().

◆ base58_check_decode() [2/2]

std::vector< uint8_t > Botan::base58_check_decode ( std::string_view s)
inline

Perform base58 decoding with checksum

Parameters
sthe string to decode
Returns
the decoded bytes

Definition at line 83 of file base58.h.

83 {
84 return base58_check_decode(s.data(), s.size());
85}
std::vector< uint8_t > base58_check_decode(const char input[], size_t input_length)
Definition base58.cpp:403

References base58_check_decode().

◆ base58_check_encode() [1/2]

std::string Botan::base58_check_encode ( const uint8_t input[],
size_t input_length )

Perform base58 encoding with checksum

Definition at line 299 of file base58.cpp.

299 {
300 const auto in = std::span{input, input_length};
301 const auto poison_guard = CT::scoped_poison(in);
302
303 const size_t leading_zeros = ct_count_leading_eq(in, 0);
304 CT::unpoison(leading_zeros);
305
306 secure_vector<uint8_t> buf(input_length + 4);
307 copy_mem(buf.data(), input, input_length);
308 store_be(sha256_d_checksum(input, input_length), buf.data() + input_length);
309
310 auto v = to_le_words(buf);
311 return base58_encode(v, leading_zeros);
312}
constexpr auto scoped_poison(const Ts &... xs)
Definition ct_utils.h:222
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:67
std::string base58_encode(const uint8_t input[], size_t input_length)
Definition base58.cpp:288
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

References base58_encode(), copy_mem(), Botan::CT::scoped_poison(), store_be(), and Botan::CT::unpoison().

Referenced by base58_check_encode().

◆ base58_check_encode() [2/2]

std::string Botan::base58_check_encode ( std::span< const uint8_t > vec)
inline

Perform base58 encoding with checksum

Parameters
vecthe bytes to encode
Returns
the base58check encoding of vec

Definition at line 62 of file base58.h.

62 {
63 return base58_check_encode(vec.data(), vec.size());
64}
std::string base58_check_encode(const uint8_t input[], size_t input_length)
Definition base58.cpp:299

References base58_check_encode().

◆ base58_decode() [1/2]

std::vector< uint8_t > Botan::base58_decode ( const char input[],
size_t input_length )

Perform base58 decoding

This is raw base58 encoding, without the checksum

Definition at line 314 of file base58.cpp.

314 {
315 const auto in = as_span_of_bytes(input, input_length);
316
317 const size_t leading_zeros = ct_count_leading_eq(in, static_cast<uint8_t>('1'));
318
319 secure_vector<uint8_t> digits(input_length - leading_zeros);
320 size_t digit_count = 0;
321
322 auto chars = in.subspan(leading_zeros);
323
324 while(!chars.empty()) {
325 if(chars.size() >= 8) {
326 if(auto values = base58_values_of_8(load_le<uint64_t>(chars.first<8>()))) {
327 store_le(std::span{digits}.subspan(digit_count).first<8>(), *values);
328 digit_count += 8;
329 chars = chars.subspan(8);
330 continue;
331 }
332 }
333
334 // Fewer than 8 characters remain, or the block contains whitespace or an invalid character
335 const size_t n = std::min<size_t>(chars.size(), 8);
336 for(size_t i = 0; i != n; ++i) {
337 const char c = static_cast<char>(chars[i]);
338
339 if(c == ' ' || c == '\n') {
340 continue;
341 }
342
343 const uint8_t idx = base58_value_of(c);
344
345 if(idx == 0xFF) {
346 throw Decoding_Error("Invalid base58");
347 }
348
349 digits[digit_count++] = idx;
350 }
351 chars = chars.subspan(n);
352 }
353
354 digits.resize(digit_count);
355
356 // From here on the digit values are secret; only lengths are revealed
357 const auto poison_guard = CT::scoped_poison(digits);
358
359 constexpr size_t radix_digits = base58_conversion_radix_digits();
360
361 // Since 58 < 2^6, any value of digits.size() base58 digits fits in
362 // 6 bits per digit
364
365 // Combine up to radix_digits digits into a single word
366 const auto accum_digits = [](std::span<const uint8_t> chunk) {
367 BOTAN_DEBUG_ASSERT(chunk.size() <= radix_digits);
368 word accum = 0;
369 for(const uint8_t d : chunk) {
370 accum = accum * 58 + d;
371 }
372 return accum;
373 };
374
375 std::span<const uint8_t> remaining{digits};
376
377 // Consume a leading partial chunk so that all remaining chunks are full;
378 // since v is zero at this point no multiplication is needed
379 if(const size_t partial = remaining.size() % radix_digits; partial > 0) {
380 v[0] = accum_digits(remaining.first(partial));
381 remaining = remaining.subspan(partial);
382 }
383
384 while(!remaining.empty()) {
385 ct_mul_add_word(v, base58_conversion_radix(), accum_digits(remaining.first(radix_digits)));
386 remaining = remaining.subspan(radix_digits);
387 }
388
389 secure_vector<uint8_t> vbytes(v.size() * sizeof(word));
390 for(size_t i = 0; i != v.size(); ++i) {
391 store_be(v[v.size() - 1 - i], vbytes.data() + i * sizeof(word));
392 }
393
394 const size_t sig_bytes = vbytes.size() - ct_count_leading_eq(vbytes, 0);
395 CT::unpoison(sig_bytes);
396
397 std::vector<uint8_t> output(leading_zeros + sig_bytes);
398 copy_mem(output.data() + leading_zeros, vbytes.data() + vbytes.size() - sig_bytes, sig_bytes);
399 CT::unpoison(output);
400 return output;
401}
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:136
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:736
constexpr auto load_le(ParamTs &&... params)
Definition loadstor.h:495
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
The native machine word, used as the limb type for multiprecision integers.
Definition types.h:131

References as_span_of_bytes(), BOTAN_DEBUG_ASSERT, copy_mem(), load_le(), Botan::CT::scoped_poison(), store_be(), store_le(), and Botan::CT::unpoison().

Referenced by base58_check_decode(), and base58_decode().

◆ base58_decode() [2/2]

std::vector< uint8_t > Botan::base58_decode ( std::string_view s)
inline

Perform base58 decoding

This is raw base58 decoding, without the checksum

Parameters
sthe string to decode
Returns
the decoded bytes

Definition at line 74 of file base58.h.

74 {
75 return base58_decode(s.data(), s.size());
76}

References base58_decode().

◆ base58_encode() [1/2]

std::string Botan::base58_encode ( const uint8_t input[],
size_t input_length )

Perform base58 encoding

This is raw base58 encoding, without the checksum

Definition at line 288 of file base58.cpp.

288 {
289 const auto in = std::span{input, input_length};
290 const auto poison_guard = CT::scoped_poison(in);
291
292 const size_t leading_zeros = ct_count_leading_eq(in, 0);
293 CT::unpoison(leading_zeros);
294
295 auto v = to_le_words(in);
296 return base58_encode(v, leading_zeros);
297}

References base58_encode(), Botan::CT::scoped_poison(), and Botan::CT::unpoison().

Referenced by base58_check_encode(), base58_encode(), and base58_encode().

◆ base58_encode() [2/2]

std::string Botan::base58_encode ( std::span< const uint8_t > vec)
inline

Perform base58 encoding

This is raw base58 encoding, without the checksum

Parameters
vecthe bytes to encode
Returns
the base58 encoding of vec

Definition at line 53 of file base58.h.

53 {
54 return base58_encode(vec.data(), vec.size());
55}

References base58_encode().

◆ base64_decode() [1/6]

secure_vector< uint8_t > Botan::base64_decode ( const char input[],
size_t input_length,
bool ignore_ws = true )

Perform base64 decoding

Parameters
inputsome base64 input
input_lengththe length of input in bytes
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
decoded base64 output

Definition at line 258 of file base64.cpp.

258 {
259 secure_vector<uint8_t> bin(Base64::decode_max_output(input_length));
260 const size_t written = base64_decode(bin.data(), input, input_length, ignore_ws);
261 bin.resize(written);
262 return bin;
263}

References base64_decode().

◆ base64_decode() [2/6]

size_t Botan::base64_decode ( std::span< uint8_t > output,
std::string_view input,
bool ignore_ws = true )

Perform base64 decoding

Parameters
outputa contiguous byte buffer of at least base64_decode_max_output bytes
inputsome base64 input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 251 of file base64.cpp.

251 {
252 if(output.size() < base64_decode_max_output(input.size())) {
253 throw Invalid_Argument("base64_decode: output buffer is too short");
254 }
255 return base64_decode(output.data(), input.data(), input.length(), ignore_ws);
256}

References base64_decode(), and base64_decode_max_output().

◆ base64_decode() [3/6]

secure_vector< uint8_t > Botan::base64_decode ( std::string_view input,
bool ignore_ws = true )

Perform base64 decoding

Parameters
inputsome base64 input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
decoded base64 output

Definition at line 265 of file base64.cpp.

265 {
266 return base64_decode(input.data(), input.size(), ignore_ws);
267}

References base64_decode().

◆ base64_decode() [4/6]

size_t Botan::base64_decode ( uint8_t output[],
const char input[],
size_t input_length,
size_t & input_consumed,
bool final_inputs,
bool ignore_ws = true )

Perform base64 decoding

Parameters
outputan array of at least base64_decode_max_output bytes
inputsome base64 input
input_lengthlength of input in bytes
input_consumedis an output parameter which says how many bytes of input were actually consumed. If less than input_length, then the range input[consumed:length] should be passed in later along with more input.
final_inputstrue iff this is the last input, in which case padding is allowed
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 203 of file base64.cpp.

204 {
205 return base_decode(Base64(), out, in, input_length, input_consumed, final_inputs, ignore_ws);
206}

References base_decode().

Referenced by argon2_check_pwhash(), base64_decode(), base64_decode(), base64_decode(), base64_decode(), botan_base64_decode(), Botan::Roughtime::Chain::Chain(), check_passhash9(), Botan::PEM_Code::decode(), Botan::Base64_Decoder::end_msg(), Botan::Encrypted_PSK_Database::get(), Botan::Encrypted_PSK_Database::list_names(), Botan::Roughtime::servers_from_str(), and Botan::Base64_Decoder::write().

◆ base64_decode() [5/6]

size_t Botan::base64_decode ( uint8_t output[],
const char input[],
size_t input_length,
bool ignore_ws = true )

Perform base64 decoding

Parameters
outputan array of at least base64_decode_max_output bytes
inputsome base64 input
input_lengthlength of input in bytes
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 208 of file base64.cpp.

208 {
209#if defined(BOTAN_HAS_BASE64_AVX512)
210 if(input_length >= 128 && CPUID::has(CPUID::Feature::AVX512, CPUID::Feature::POPCNT)) {
211 // Decoding directly stops at the first block containing whitespace,
212 // padding, or an invalid character
213 const uint8_t* in8 = as_span_of_bytes(input, input_length).data();
214 const size_t bulk = base64_decode_avx512(output, in8, input_length);
215 size_t written = bulk / 4 * 3;
216
217 const uint8_t* rest = in8 + bulk;
218 size_t rest_len = input_length - bulk;
219
220 // If the stop may have been due to whitespace, compact the remainder
221 // and continue decoding
222 secure_vector<uint8_t> compacted;
223 if(ignore_ws && rest_len > 128) {
224 compacted.resize(rest_len);
225 const size_t clean_len = base64_strip_ws_avx512(compacted.data(), rest, rest_len);
226 rest = compacted.data();
227 rest_len = clean_len;
228
229 const size_t bulk2 = base64_decode_avx512(output + written, rest, rest_len);
230 written += bulk2 / 4 * 3;
231 rest += bulk2;
232 rest_len -= bulk2;
233 }
234
235 // The scalar decoder handles the final blocks, and with them all of
236 // the padding logic and error reporting
237 const size_t tail_written =
238 base_decode_full(Base64(), output + written, cast_uint8_ptr_to_char(rest), rest_len, ignore_ws);
239
240 return written + tail_written;
241 }
242#endif
243
244 return base_decode_full(Base64(), output, input, input_length, ignore_ws);
245}
static bool has(CPUID::Feature feat)
Definition cpuid.h:93
BOTAN_FN_ISA_AVX512_POPCNT size_t base64_strip_ws_avx512(uint8_t out[], const uint8_t in[], size_t length)
const char * cast_uint8_ptr_to_char(const uint8_t *b)
Definition mem_ops.h:323
BOTAN_FN_ISA_AVX512_POPCNT size_t base64_decode_avx512(uint8_t out[], const uint8_t in[], size_t length)

References as_span_of_bytes(), Botan::CPUFeature::AVX512, base64_decode_avx512(), base64_strip_ws_avx512(), base_decode_full(), cast_uint8_ptr_to_char(), Botan::CPUID::has(), and Botan::CPUFeature::POPCNT.

◆ base64_decode() [6/6]

size_t Botan::base64_decode ( uint8_t output[],
std::string_view input,
bool ignore_ws = true )

Perform base64 decoding

Parameters
outputan array of at least base64_decode_max_output bytes
inputsome base64 input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 247 of file base64.cpp.

247 {
248 return base64_decode(output, input.data(), input.length(), ignore_ws);
249}

References base64_decode().

◆ base64_decode_avx512()

size_t Botan::base64_decode_avx512 ( uint8_t out[],
const uint8_t in[],
size_t length )

Decode complete 64 character blocks, stopping early if any block contains a character that is not one of the 64 data characters (including padding and whitespace). Always leaves at least one block for the caller so that padding handling and error reporting stay in the scalar decoder. Returns the number of input characters consumed (a multiple of 64); output written is consumed/4*3 bytes.

Definition at line 86 of file base64_avx512.cpp.

86 {
87 // Maps the low 7 bits of an ASCII character to its base64 value; any
88 // character that is not one of the 64 data characters maps to 0x80
89 alignas(64) constexpr auto B64_DEC_TABLE = []() {
90 std::array<uint8_t, 128> tbl = {};
91 for(auto& b : tbl) {
92 b = 0x80;
93 }
94 for(size_t i = 0; i != 26; ++i) {
95 tbl['A' + i] = static_cast<uint8_t>(i);
96 tbl['a' + i] = static_cast<uint8_t>(26 + i);
97 }
98 for(size_t i = 0; i != 10; ++i) {
99 tbl['0' + i] = static_cast<uint8_t>(52 + i);
100 }
101 tbl['+'] = 62;
102 tbl['/'] = 63;
103 return tbl;
104 }();
105
106 // After the multiply-adds, dword g holds the three decoded bytes of group
107 // g as its bytes [2,1,0]; gather them into 48 contiguous output bytes
108 alignas(64) constexpr auto B64_DEC_PACK = []() {
109 std::array<uint8_t, 64> idx = {};
110 for(size_t g = 0; g != 16; ++g) {
111 idx[3 * g + 0] = static_cast<uint8_t>(4 * g + 2);
112 idx[3 * g + 1] = static_cast<uint8_t>(4 * g + 1);
113 idx[3 * g + 2] = static_cast<uint8_t>(4 * g + 0);
114 }
115 return idx;
116 }();
117
118 constexpr __mmask64 LOW_48 = 0x0000FFFFFFFFFFFF;
119
120 const __m512i lut_lo = _mm512_load_si512(B64_DEC_TABLE.data());
121 const __m512i lut_hi = _mm512_load_si512(&B64_DEC_TABLE[64]);
122 const __m512i pack_shuffle = _mm512_load_si512(B64_DEC_PACK.data());
123
124 // Merge the 6 bit values a,b,c,d of each group first into the pair
125 // (a*64 + b, c*64 + d) and then into a*2^18 + b*2^12 + c*2^6 + d
126 const __m512i pack_mul1 = _mm512_set1_epi16(0x0140);
127 const __m512i pack_mul2 = _mm512_set1_epi32(0x00011000);
128
129 size_t consumed = 0;
130
131 while(length - consumed > 64) {
132 const __m512i x = _mm512_loadu_si512(in + consumed);
133
134 const __m512i values = _mm512_permutex2var_epi8(lut_lo, x, lut_hi);
135
136 // Padding, whitespace, invalid, or non-ASCII input sets a high bit
137 if(_mm512_movepi8_mask(_mm512_or_si512(x, values)) != 0) {
138 break;
139 }
140
141 const __m512i merged16 = _mm512_maddubs_epi16(values, pack_mul1);
142 const __m512i merged32 = _mm512_madd_epi16(merged16, pack_mul2);
143 const __m512i packed = _mm512_permutexvar_epi8(pack_shuffle, merged32);
144
145 _mm512_mask_storeu_epi8(out, LOW_48, packed);
146
147 out += 48;
148 consumed += 64;
149 }
150
151 return consumed;
152}

Referenced by base64_decode().

◆ base64_decode_max_output()

size_t Botan::base64_decode_max_output ( size_t input_length)

Calculate the size of output buffer for base64_decode

Parameters
input_lengththe length of input in bytes
Returns
the size of output buffer in bytes

Definition at line 273 of file base64.cpp.

273 {
274 return Base64::decode_max_output(input_length);
275}

Referenced by argon2_check_pwhash(), base64_decode(), and botan_base64_decode().

◆ base64_encode() [1/3]

size_t Botan::base64_encode ( char output[],
const uint8_t input[],
size_t input_length,
size_t & input_consumed,
bool final_inputs )

Perform base64 encoding

Parameters
outputan array of at least base64_encode_max_output bytes
inputis some binary data
input_lengthlength of input in bytes
input_consumedis an output parameter which says how many bytes of input were actually consumed. If less than input_length, then the range input[consumed:length] should be passed in later along with more input.
final_inputstrue iff this is the last input, in which case padding chars will be applied if needed
Returns
number of bytes written to output

Definition at line 167 of file base64.cpp.

167 {
168 size_t consumed = 0;
169 size_t produced = 0;
170
171#if defined(BOTAN_HAS_BASE64_AVX512)
172 if(input_length >= 48 && CPUID::has(CPUID::Feature::AVX512)) {
173 consumed = base64_encode_avx512(out, in, input_length);
174 produced = consumed / 3 * 4;
175 }
176#endif
177
178 size_t remainder_consumed = 0;
179 produced +=
180 base_encode(Base64(), out + produced, in + consumed, input_length - consumed, remainder_consumed, final_inputs);
181
182 input_consumed = consumed + remainder_consumed;
183 return produced;
184}
BOTAN_FN_ISA_AVX512 size_t base64_encode_avx512(char out[], const uint8_t in[], size_t length)

References Botan::CPUFeature::AVX512, base64_encode_avx512(), base_encode(), and Botan::CPUID::has().

Referenced by argon2_generate_pwhash(), base64_encode(), base64_encode(), Botan::OCSP::Request::base64_encode(), botan_base64_encode(), Botan::PEM_Code::encode(), generate_passhash9(), Botan::Encrypted_PSK_Database::get(), Botan::Encrypted_PSK_Database::remove(), Botan::Encrypted_PSK_Database::set(), and Botan::Roughtime::Chain::to_string().

◆ base64_encode() [2/3]

std::string Botan::base64_encode ( const uint8_t input[],
size_t input_length )

Perform base64 encoding

Parameters
inputsome input
input_lengthlength of input in bytes
Returns
base64adecimal representation of input

Definition at line 186 of file base64.cpp.

186 {
187 const size_t output_length = Base64::encode_max_output(input_length);
188 std::string output(output_length, 0);
189
190 size_t consumed = 0;
191 size_t produced = 0;
192
193 if(output_length > 0) {
194 produced = base64_encode(&output.front(), input, input_length, consumed, true);
195 }
196
197 BOTAN_ASSERT_EQUAL(consumed, input_length, "Consumed the entire input");
198 BOTAN_ASSERT_EQUAL(produced, output.size(), "Produced expected size");
199
200 return output;
201}
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition assert.h:95

References base64_encode(), and BOTAN_ASSERT_EQUAL.

◆ base64_encode() [3/3]

std::string Botan::base64_encode ( std::span< const uint8_t > input)
inline

Perform base64 encoding

Parameters
inputsome input
Returns
base64adecimal representation of input

Definition at line 47 of file base64.h.

47 {
48 return base64_encode(input.data(), input.size());
49}

References base64_encode().

◆ base64_encode_avx512()

size_t Botan::base64_encode_avx512 ( char out[],
const uint8_t in[],
size_t length )

Encode complete 48 byte groups of input, returning the number of input bytes consumed (a multiple of 48)

Definition at line 22 of file base64_avx512.cpp.

22 {
23 // Expands each 3 byte input group g to the 4 bytes [b1,b0,b2,b1], placing
24 // the group in a 32-bit word where vpmultishiftqb can reach each 6-bit field
25 alignas(64) constexpr auto B64_ENC_SHUFFLE = []() {
26 std::array<uint8_t, 64> idx = {};
27 for(size_t g = 0; g != 16; ++g) {
28 idx[4 * g + 0] = static_cast<uint8_t>(3 * g + 1);
29 idx[4 * g + 1] = static_cast<uint8_t>(3 * g + 0);
30 idx[4 * g + 2] = static_cast<uint8_t>(3 * g + 2);
31 idx[4 * g + 3] = static_cast<uint8_t>(3 * g + 1);
32 }
33 return idx;
34 }();
35
36 alignas(64) constexpr char B64_ENC_TABLE[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
37 constexpr __mmask64 LOW_48 = 0x0000FFFFFFFFFFFF;
38
39 const __m512i shuffle = _mm512_load_si512(B64_ENC_SHUFFLE.data());
40 const __m512i lookup = _mm512_load_si512(B64_ENC_TABLE);
41 // Byte i of each output qword takes 8 bits starting at bit multishift[i]
42 const __m512i multishift = _mm512_set1_epi64(0x3036242A1016040A);
43
44 size_t consumed = 0;
45
46 while(length - consumed >= 48) {
47 const __m512i x = _mm512_maskz_loadu_epi8(LOW_48, in + consumed);
48
49 const __m512i expanded = _mm512_permutexvar_epi8(shuffle, x);
50 // The two high junk bits of each extracted byte are ignored by vpermb
51 const __m512i indices = _mm512_multishift_epi64_epi8(multishift, expanded);
52 const __m512i chars = _mm512_permutexvar_epi8(indices, lookup);
53
54 _mm512_storeu_si512(out, chars);
55
56 out += 64;
57 consumed += 48;
58 }
59
60 return consumed;
61}
std::string lookup(const OID &oid)
Definition oids.h:87

Referenced by base64_encode().

◆ base64_encode_max_output()

size_t Botan::base64_encode_max_output ( size_t input_length)

Calculate the size of output buffer for base64_encode

Parameters
input_lengththe length of input in bytes
Returns
the size of output buffer in bytes

Definition at line 269 of file base64.cpp.

269 {
270 return Base64::encode_max_output(input_length);
271}

◆ base64_strip_ws_avx512()

size_t Botan::base64_strip_ws_avx512 ( uint8_t out[],
const uint8_t in[],
size_t length )

Copy in to out, removing any of the whitespace characters that base64 decoding ignores. Returns the number of bytes written.

Definition at line 63 of file base64_avx512.cpp.

63 {
64 size_t written = 0;
65 size_t pos = 0;
66
67 while(pos < length) {
68 const size_t todo = std::min<size_t>(64, length - pos);
69 const __mmask64 valid = (todo == 64) ? ~__mmask64(0) : ((__mmask64(1) << todo) - 1);
70
71 const __m512i x = _mm512_maskz_loadu_epi8(valid, in + pos);
72
73 const __mmask64 ws =
74 _mm512_cmpeq_epi8_mask(x, _mm512_set1_epi8(' ')) | _mm512_cmpeq_epi8_mask(x, _mm512_set1_epi8('\n')) |
75 _mm512_cmpeq_epi8_mask(x, _mm512_set1_epi8('\t')) | _mm512_cmpeq_epi8_mask(x, _mm512_set1_epi8('\r'));
76
77 const __mmask64 keep = valid & ~ws;
78 _mm512_mask_compressstoreu_epi8(out + written, keep, x);
79 written += static_cast<size_t>(_mm_popcnt_u64(keep));
80 pos += todo;
81 }
82
83 return written;
84}

Referenced by base64_decode().

◆ base_decode()

template<typename Base>
size_t Botan::base_decode ( const Base & base,
uint8_t output[],
const char input[],
size_t input_length,
size_t & input_consumed,
bool final_inputs,
bool ignore_ws = true )

Perform decoding using the base provided

Parameters
Base Typesobject giving access to the encodings specifications
outputan array of at least Base::decode_max_output bytes
inputsome base input
input_lengthlength of input in bytes
input_consumedis an output parameter which says how many bytes of input were actually consumed. If less than input_length, then the range input[consumed:length] should be passed in later along with more input.
final_inputstrue iff this is the last input, in which case padding is allowed
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 118 of file codec_base.h.

124 {
125 // TODO(Botan4) Check if we can use just base. or Base:: here instead
126 constexpr size_t decoding_bytes_in = std::remove_reference_t<Base>::decoding_bytes_in();
127 constexpr size_t decoding_bytes_out = std::remove_reference_t<Base>::decoding_bytes_out();
128
129 input_consumed = 0;
130
131 uint8_t* out_ptr = output;
132 std::array<uint8_t, decoding_bytes_in> decode_buf{};
133 size_t decode_buf_pos = 0;
134 size_t final_truncate = 0;
135 bool seen_padding = false;
136
137 clear_mem(output, base.decode_max_output(input_length));
138
139 for(size_t i = 0; i != input_length; ++i) {
140 const uint8_t bin = base.lookup_binary_value(input[i]);
141
142 // This call might throw Invalid_Argument
143 if(base.check_bad_char(bin, input[i], ignore_ws)) {
144 // Padding may only appear at the end, so a data symbol must never
145 // follow one (0x81 marks a padding character)
146 if(seen_padding) {
147 throw Invalid_Argument(base.name() + " decoding failed, data follows padding");
148 }
149 decode_buf[decode_buf_pos] = bin;
150 ++decode_buf_pos;
151 } else if(bin == 0x81) {
152 seen_padding = true;
153 }
154
155 /*
156 * If we're at the end of the input, pad with 0s and truncate
157 */
158 if(final_inputs && (i == input_length - 1)) {
159 if(decode_buf_pos) {
160 const size_t bits_per_symbol = base.bits_consumed();
161 const size_t pad_bits = (decode_buf_pos * bits_per_symbol) % 8;
162
163 // A trailing symbol contributing only pad bits cannot occur in a
164 // valid encoding; RFC 4648 4 and 6 enumerate the reachable cases
165 if(pad_bits >= bits_per_symbol) {
166 throw Invalid_Argument(base.name() + " decoding failed, invalid length");
167 }
168
169 // RFC 4648 3.5: "decoders MAY chose to reject an encoding if the
170 // pad bits have not been set to zero"
171 const uint8_t pad_mask = static_cast<uint8_t>((1U << pad_bits) - 1);
172 if(decode_buf[decode_buf_pos - 1] & pad_mask) {
173 throw Invalid_Argument(base.name() + " decoding failed, nonzero padding bits");
174 }
175
176 for(size_t j = decode_buf_pos; j < decoding_bytes_in; ++j) {
177 decode_buf[j] = 0;
178 }
179
180 final_truncate = decoding_bytes_in - decode_buf_pos;
181 decode_buf_pos = decoding_bytes_in;
182 }
183 }
184
185 if(decode_buf_pos == decoding_bytes_in) {
186 base.decode(out_ptr, decode_buf.data());
187
188 out_ptr += decoding_bytes_out;
189 decode_buf_pos = 0;
190 input_consumed = i + 1;
191 }
192 }
193
194 while(input_consumed < input_length && base.lookup_binary_value(input[input_consumed]) == 0x80) {
195 ++input_consumed;
196 }
197
198 const size_t written = (out_ptr - output) - base.bytes_to_remove(final_truncate);
199
200 return written;
201}
constexpr auto out_ptr(T &outptr) noexcept
Definition stl_util.h:164
constexpr void clear_mem(T *ptr, size_t n)
Definition mem_ops.h:118

References clear_mem(), and out_ptr().

Referenced by base32_decode(), base64_decode(), and base_decode_full().

◆ base_decode_full()

template<typename Base>
size_t Botan::base_decode_full ( const Base & base,
uint8_t output[],
const char input[],
size_t input_length,
bool ignore_ws )

Definition at line 204 of file codec_base.h.

204 {
205 size_t consumed = 0;
206 const size_t written = base_decode(base, output, input, input_length, consumed, true, ignore_ws);
207
208 if(consumed != input_length) {
209 throw Invalid_Argument(base.name() + " decoding failed, input did not have full bytes");
210 }
211
212 return written;
213}

References base_decode().

Referenced by base32_decode(), base64_decode(), and base_decode_to_vec().

◆ base_decode_to_vec()

template<typename Vector, typename Base>
Vector Botan::base_decode_to_vec ( const Base & base,
const char input[],
size_t input_length,
bool ignore_ws )

Definition at line 216 of file codec_base.h.

216 {
217 const size_t output_length = base.decode_max_output(input_length);
218 Vector bin(output_length);
219
220 const size_t written = base_decode_full(base, bin.data(), input, input_length, ignore_ws);
221
222 bin.resize(written);
223 return bin;
224}

References base_decode_full().

Referenced by base32_decode().

◆ base_encode()

template<class Base>
size_t Botan::base_encode ( const Base & base,
char output[],
const uint8_t input[],
size_t input_length,
size_t & input_consumed,
bool final_inputs )

Perform encoding using the base provided

Parameters
Base Typesobject giving access to the encodings specifications
outputan array of at least base.encode_max_output bytes
inputis some binary data
input_lengthlength of input in bytes
input_consumedis an output parameter which says how many bytes of input were actually consumed. If less than input_length, then the range input[consumed:length] should be passed in later along with more input.
final_inputstrue iff this is the last input, in which case padding chars will be applied if needed
Returns
number of bytes written to output

Definition at line 35 of file codec_base.h.

40 {
41 input_consumed = 0;
42
43 // TODO(Botan4) Check if we can use just base. or Base:: here instead
44 constexpr size_t encoding_bytes_in = std::remove_reference_t<Base>::encoding_bytes_in();
45 constexpr size_t encoding_bytes_out = std::remove_reference_t<Base>::encoding_bytes_out();
46
47 size_t input_remaining = input_length;
48 size_t output_produced = 0;
49
50 while(input_remaining >= encoding_bytes_in) {
51 base.encode(output + output_produced, input + input_consumed);
52
53 input_consumed += encoding_bytes_in;
54 output_produced += encoding_bytes_out;
55 input_remaining -= encoding_bytes_in;
56 }
57
58 if(final_inputs && input_remaining) {
59 std::array<uint8_t, encoding_bytes_in> remainder{};
60 for(size_t i = 0; i != input_remaining; ++i) {
61 remainder[i] = input[input_consumed + i];
62 }
63
64 base.encode(output + output_produced, remainder.data());
65
66 const size_t bits_consumed = base.bits_consumed();
67 const size_t remaining_bits_before_padding = base.remaining_bits_before_padding();
68
69 size_t empty_bits = 8 * (encoding_bytes_in - input_remaining);
70 size_t index = output_produced + encoding_bytes_out - 1;
71 while(empty_bits >= remaining_bits_before_padding) {
72 output[index--] = '=';
73 empty_bits -= bits_consumed;
74 }
75
76 input_consumed += input_remaining;
77 output_produced += encoding_bytes_out;
78 }
79
80 return output_produced;
81}

Referenced by base32_encode(), base64_encode(), and base_encode_to_string().

◆ base_encode_to_string()

template<typename Base>
std::string Botan::base_encode_to_string ( const Base & base,
const uint8_t input[],
size_t input_length )

Definition at line 84 of file codec_base.h.

84 {
85 const size_t output_length = base.encode_max_output(input_length);
86 std::string output(output_length, 0);
87
88 size_t consumed = 0;
89 size_t produced = 0;
90
91 if(output_length > 0) {
92 produced = base_encode(base, &output.front(), input, input_length, consumed, true);
93 }
94
95 BOTAN_ASSERT_EQUAL(consumed, input_length, "Consumed the entire input");
96 BOTAN_ASSERT_EQUAL(produced, output.size(), "Produced expected size");
97
98 return output;
99}

References base_encode(), and BOTAN_ASSERT_EQUAL.

Referenced by base32_encode().

◆ basecase_mul()

void Botan::basecase_mul ( word z[],
size_t z_size,
const word x[],
size_t x_size,
const word y[],
size_t y_size )

Basecase O(N^2) multiplication

Definition at line 20 of file mp_karat.cpp.

20 {
21 if(z_size < x_size + y_size) {
22 throw Invalid_Argument("basecase_mul z_size too small");
23 }
24
25 const size_t x_size_8 = x_size - (x_size % 8);
26
27 zeroize_buffer(z, z_size);
28
29 for(size_t i = 0; i != y_size; ++i) {
30 const word y_i = y[i];
31
32 word carry = 0;
33
34 for(size_t j = 0; j != x_size_8; j += 8) {
35 carry = word8_madd3(z + i + j, x + j, y_i, carry);
36 }
37
38 for(size_t j = x_size_8; j != x_size; ++j) {
39 z[i + j] = word_madd3(x[j], y_i, z[i + j], &carry);
40 }
41
42 z[x_size + i] = carry;
43 }
44}
constexpr auto word8_madd3(W z[8], const W x[8], W y, W carry) -> W
Definition mp_asmi.h:467
void zeroize_buffer(T buf[], size_t n)
Definition mem_utils.h:37
constexpr auto word_madd3(W a, W b, W c, W *d) -> W
Definition mp_asmi.h:158

References word8_madd3(), word_madd3(), and zeroize_buffer().

Referenced by bigint_mul().

◆ basecase_sqr()

void Botan::basecase_sqr ( word z[],
size_t z_size,
const word x[],
size_t x_size )

Basecase O(N^2) squaring

Definition at line 46 of file mp_karat.cpp.

46 {
47 if(z_size < 2 * x_size) {
48 throw Invalid_Argument("basecase_sqr z_size too small");
49 }
50
51 const size_t x_size_8 = x_size - (x_size % 8);
52
53 zeroize_buffer(z, z_size);
54
55 for(size_t i = 0; i != x_size; ++i) {
56 const word x_i = x[i];
57
58 word carry = 0;
59
60 for(size_t j = 0; j != x_size_8; j += 8) {
61 carry = word8_madd3(z + i + j, x + j, x_i, carry);
62 }
63
64 for(size_t j = x_size_8; j != x_size; ++j) {
65 z[i + j] = word_madd3(x[j], x_i, z[i + j], &carry);
66 }
67
68 z[x_size + i] = carry;
69 }
70}

References word8_madd3(), word_madd3(), and zeroize_buffer().

Referenced by bigint_sqr().

◆ basemul_booth_exec()

template<typename C, size_t WindowBits, typename BlindedScalar, typename Blinding>
C::ProjectivePoint Botan::basemul_booth_exec ( std::span< const typename C::AffinePoint > table,
const BlindedScalar & scalar,
const Blinding & blinding )

Definition at line 215 of file pcurves_mul.h.

217 {
218 static constexpr size_t WindowElements = 1 << (WindowBits - 1);
219
220 const size_t windows = (scalar.bits() + WindowBits) / WindowBits;
221
222 auto accum = [&]() {
223 // First window: extract W bits, shift left 1 to insert implicit carry in of zero
224 const size_t w_bits = scalar.get_window(0) & ((1 << WindowBits) - 1);
225 const size_t raw = w_bits << 1;
226 const auto [tidx, tneg] = booth_recode<WindowBits>(raw);
227 const auto tbl_0 = table.first(WindowElements);
228
229 auto pt = C::ProjectivePoint::from_affine(C::AffinePoint::ct_select(tbl_0, tidx));
230 pt.conditional_assign(tneg, pt.negate());
231 blinding.randomize_rep(pt, 0);
232 return pt;
233 }();
234
235 for(size_t i = 1; i != windows; ++i) {
236 // Extract W+1 bits overlapping by 1 with the previous window
237 const size_t bit_pos = WindowBits * i - 1;
238 const size_t raw = scalar.get_window(bit_pos);
239 const auto [tidx, tneg] = booth_recode<WindowBits>(raw);
240
241 const auto tbl_i = table.subspan(WindowElements * i, WindowElements);
242
243 accum = C::ProjectivePoint::add_or_sub(accum, C::AffinePoint::ct_select(tbl_i, tidx), tneg);
244
245 // Conditional ok: loop iteration count is public
246 if(i < Blinding::Rerandomizations) {
247 blinding.randomize_rep(accum, i);
248 }
249 }
250
251 return accum;
252}
constexpr std::pair< size_t, CT::Choice > booth_recode(size_t x, size_t window_bits)
Definition mp_core.h:1312

References booth_recode().

Referenced by Botan::PrecomputedBaseMulTable< C, W >::mul().

◆ basemul_booth_exec_vartime()

template<typename C, size_t WindowBits, typename ScalarBits>
C::ProjectivePoint Botan::basemul_booth_exec_vartime ( std::span< const typename C::AffinePoint > table,
const ScalarBits & scalar,
typename C::ProjectivePoint accum )

Definition at line 262 of file pcurves_mul.h.

264 {
265 static constexpr size_t WindowElements = 1 << (WindowBits - 1);
266
267 const size_t windows = (scalar.bits() + WindowBits) / WindowBits;
268 BOTAN_DEBUG_ASSERT(windows * WindowElements <= table.size());
269
270 for(size_t i = 0; i != windows; ++i) {
271 // Extract W+1 bits overlapping by 1 with the previous window; the
272 // first window has an implicit carry in of zero
273 const size_t raw =
274 (i == 0) ? ((scalar.get_window(0) & ((1 << WindowBits) - 1)) << 1) : scalar.get_window(WindowBits * i - 1);
275
276 const auto [tidx, tneg] = booth_recode<WindowBits>(raw);
277
278 // Conditional ok: this function is variable time
279 if(tidx > 0) {
280 accum = C::ProjectivePoint::add_or_sub(accum, table[WindowElements * i + tidx - 1], tneg);
281 }
282 }
283
284 return accum;
285}

References booth_recode(), and BOTAN_DEBUG_ASSERT.

Referenced by Botan::PrecomputedBaseMulTable< C, W >::mul_vartime().

◆ basemul_booth_setup()

template<typename C, size_t WindowBits>
std::vector< typename C::AffinePoint > Botan::basemul_booth_setup ( const typename C::AffinePoint & p,
size_t max_scalar_bits )

Definition at line 178 of file pcurves_mul.h.

178 {
179 static_assert(WindowBits >= 1 && WindowBits <= 8);
180
181 // 2^(W-1) elements per window [1*base .. 2^(W-1)*base]
182 constexpr size_t WindowElements = 1 << (WindowBits - 1);
183
184 const size_t Windows = (max_scalar_bits + WindowBits - 1) / WindowBits;
185
186 const size_t TableSize = Windows * WindowElements;
187
188 std::vector<typename C::ProjectivePoint> table;
189 table.reserve(TableSize);
190
191 auto accum = C::ProjectivePoint::from_affine(p);
192
193 for(size_t i = 0; i != TableSize; i += WindowElements) {
194 table.push_back(accum);
195
196 for(size_t j = 1; j != WindowElements; ++j) {
197 // Conditional ok: loop iteration count is public
198 if(j % 2 == 1) {
199 table.emplace_back(table[i + j / 2].dbl());
200 } else {
201 table.emplace_back(table[i + j - 1] + table[i]);
202 }
203 }
204
205 // Advance to next window's base: 2^W * current_base
206 // The last entry is 2^(W-1) * base, so doubling gives 2^W * base
207 accum = table[i + WindowElements - 1].dbl();
208 }
209
210 // Variable time batch conversion is fine since generator is public
211 return to_affine_batch<C, true>(table);
212}
auto to_affine_batch(std::span< const typename C::ProjectivePoint > projective)

References to_affine_batch().

Referenced by Botan::PrecomputedBaseMulTable< C, W >::PrecomputedBaseMulTable().

◆ basemul_exec()

template<typename C, size_t WindowBits, typename BlindedScalar, typename Blinding>
C::ProjectivePoint Botan::basemul_exec ( std::span< const typename C::AffinePoint > table,
const BlindedScalar & scalar,
const Blinding & blinding )

Definition at line 126 of file pcurves_mul.h.

128 {
129 // 2^W elements, less the identity element
130 static constexpr size_t WindowElements = (1 << WindowBits) - 1;
131
132 // TODO: C++23 - use std::mdspan to access table?
133
134 auto accum = [&]() {
135 const size_t w_0 = scalar.get_window(0);
136 const auto tbl_0 = table.first(WindowElements);
137 auto pt = C::ProjectivePoint::from_affine(C::AffinePoint::ct_select(tbl_0, w_0));
138 blinding.randomize_rep(pt, 0);
139 return pt;
140 }();
141
142 const size_t windows = (scalar.bits() + WindowBits - 1) / WindowBits;
143
144 for(size_t i = 1; i != windows; ++i) {
145 const size_t w_i = scalar.get_window(WindowBits * i);
146 const auto tbl_i = table.subspan(WindowElements * i, WindowElements);
147
148 /*
149 None of these additions can be doublings, because in each iteration, the
150 discrete logarithms of the points we're selecting out of the table are
151 larger than the largest possible dlog of accum.
152 */
153 accum += C::AffinePoint::ct_select(tbl_i, w_i);
154
155 // Conditional ok: loop iteration count is public
156 if(i < Blinding::Rerandomizations) {
157 blinding.randomize_rep(accum, i);
158 }
159 }
160
161 return accum;
162}

◆ basemul_setup()

template<typename C, size_t WindowBits>
std::vector< typename C::AffinePoint > Botan::basemul_setup ( const typename C::AffinePoint & p,
size_t max_scalar_bits )

Definition at line 91 of file pcurves_mul.h.

91 {
92 static_assert(WindowBits >= 1 && WindowBits <= 8);
93
94 // 2^W elements, less the identity element
95 constexpr size_t WindowElements = (1 << WindowBits) - 1;
96
97 const size_t Windows = (max_scalar_bits + WindowBits - 1) / WindowBits;
98
99 const size_t TableSize = Windows * WindowElements;
100
101 std::vector<typename C::ProjectivePoint> table;
102 table.reserve(TableSize);
103
104 auto accum = C::ProjectivePoint::from_affine(p);
105
106 for(size_t i = 0; i != TableSize; i += WindowElements) {
107 table.push_back(accum);
108
109 for(size_t j = 1; j != WindowElements; ++j) {
110 // Conditional ok: loop iteration count is public
111 if(j % 2 == 1) {
112 table.emplace_back(table[i + j / 2].dbl());
113 } else {
114 table.emplace_back(table[i + j - 1] + table[i]);
115 }
116 }
117
118 accum = table[i + (WindowElements / 2)].dbl();
119 }
120
121 // Variable time batch conversion is fine since generator is public
122 return to_affine_batch<C, true>(table);
123}

References to_affine_batch().

◆ bcrypt_pbkdf()

void Botan::bcrypt_pbkdf ( uint8_t output[],
size_t output_len,
const char * password,
size_t password_len,
const uint8_t salt[],
size_t salt_len,
size_t rounds )
inline

Bcrypt PBKDF compatible with OpenBSD bcrypt_pbkdf

Definition at line 71 of file bcrypt_pbkdf.h.

77 {
78 auto pwdhash_fam = PasswordHashFamily::create_or_throw("Bcrypt-PBKDF");
79 auto pwdhash = pwdhash_fam->from_params(rounds);
80 pwdhash->derive_key(output, output_len, password, password_len, salt, salt_len);
81}

References bcrypt_pbkdf(), and Botan::PasswordHashFamily::create_or_throw().

Referenced by bcrypt_pbkdf().

◆ bigint_add2()

template<WordType W>
auto Botan::bigint_add2 ( W x[],
size_t x_size,
const W y[],
size_t y_size ) -> W
inlineconstexpr

Two operand addition with carry out

Definition at line 98 of file mp_core.h.

98 {
99 W carry = 0;
100
101 BOTAN_ASSERT(x_size >= y_size, "Expected sizes");
102
103 const size_t blocks = y_size - (y_size % 8);
104
105 for(size_t i = 0; i != blocks; i += 8) {
106 carry = word8_add2(x + i, y + i, carry);
107 }
108
109 for(size_t i = blocks; i != y_size; ++i) {
110 x[i] = word_add(x[i], y[i], &carry);
111 }
112
113 for(size_t i = y_size; i != x_size; ++i) {
114 x[i] = word_add(x[i], static_cast<W>(0), &carry);
115 }
116
117 return carry;
118}
#define BOTAN_ASSERT(expr, assertion_made)
Definition assert.h:69
constexpr auto word_add(W x, W y, W *carry) -> W
Definition mp_asmi.h:260
constexpr auto word8_add2(W x[8], const W y[8], W carry) -> W
Definition mp_asmi.h:297

References BOTAN_ASSERT, word8_add2(), and word_add().

Referenced by Botan::IntMod< MontgomeryRep< ScalarParams > >::_invert_vartime_div2_helper(), Botan::BigInt::add(), Botan::BlindedScalarBits< C, WindowBits+1 >::BlindedScalarBits(), p_div_2_plus_1(), redc_crandall(), and srp6_client_agree().

◆ bigint_add3()

template<WordType W>
auto Botan::bigint_add3 ( W z[],
const W x[],
size_t x_size,
const W y[],
size_t y_size ) -> W
inlineconstexpr

Three operand addition with carry out

Definition at line 124 of file mp_core.h.

124 {
125 if(x_size < y_size) {
126 return bigint_add3(z, y, y_size, x, x_size);
127 }
128
129 W carry = 0;
130
131 const size_t blocks = y_size - (y_size % 8);
132
133 for(size_t i = 0; i != blocks; i += 8) {
134 carry = word8_add3(z + i, x + i, y + i, carry);
135 }
136
137 for(size_t i = blocks; i != y_size; ++i) {
138 z[i] = word_add(x[i], y[i], &carry);
139 }
140
141 for(size_t i = y_size; i != x_size; ++i) {
142 z[i] = word_add(x[i], static_cast<W>(0), &carry);
143 }
144
145 return carry;
146}
constexpr auto bigint_add3(W z[], const W x[], size_t x_size, const W y[], size_t y_size) -> W
Definition mp_core.h:124
constexpr auto word8_add3(W z[8], const W x[8], const W y[8], W carry) -> W
Definition mp_asmi.h:326

References bigint_add3(), word8_add3(), and word_add().

Referenced by Botan::BigInt::add2(), bigint_add3(), Botan::BigInt::mod_add(), Botan::Montgomery_Int::operator+(), and p_plus_1_over_4().

◆ bigint_cmp()

template<WordType W>
int32_t Botan::bigint_cmp ( const W x[],
size_t x_size,
const W y[],
size_t y_size )
inlineconstexpr

Compare x and y Return -1 if x < y Return 0 if x == y Return 1 if x > y

Definition at line 463 of file mp_core.h.

463 {
464 static_assert(sizeof(W) >= sizeof(uint32_t), "Size assumption");
465
466 const W LT = static_cast<W>(-1);
467 const W EQ = 0;
468 const W GT = 1;
469
470 const size_t common_elems = std::min(x_size, y_size);
471
472 W result = EQ; // until found otherwise
473
474 for(size_t i = 0; i != common_elems; i++) {
475 const auto is_eq = CT::Mask<W>::is_equal(x[i], y[i]);
476 const auto is_lt = CT::Mask<W>::is_lt(x[i], y[i]);
477
478 result = is_eq.select(result, is_lt.select(LT, GT));
479 }
480
481 if(x_size < y_size) {
482 W mask = 0;
483 for(size_t i = x_size; i != y_size; i++) {
484 mask |= y[i];
485 }
486
487 // If any bits were set in high part of y, then x < y
488 result = CT::Mask<W>::is_zero(mask).select(result, LT);
489 } else if(y_size < x_size) {
490 W mask = 0;
491 for(size_t i = y_size; i != x_size; i++) {
492 mask |= x[i];
493 }
494
495 // If any bits were set in high part of x, then x > y
496 result = CT::Mask<W>::is_zero(mask).select(result, GT);
497 }
498
499 CT::unpoison(result);
500 BOTAN_DEBUG_ASSERT(result == LT || result == GT || result == EQ);
501 return static_cast<int32_t>(result);
502}
static constexpr Mask< T > is_equal(T x, T y)
Definition ct_utils.h:447
static constexpr Mask< T > is_lt(T x, T y)
Definition ct_utils.h:455
static constexpr Mask< T > is_zero(T x)
Definition ct_utils.h:442

References BOTAN_DEBUG_ASSERT, Botan::CT::Mask< T >::is_equal(), Botan::CT::Mask< T >::is_lt(), Botan::CT::Mask< T >::is_zero(), and Botan::CT::unpoison().

Referenced by Botan::BigInt::add(), Botan::BigInt::add2(), Botan::BigInt::cmp(), Botan::BigInt::cmp_word(), and gcd().

◆ bigint_cnd_abs()

template<WordType W>
void Botan::bigint_cnd_abs ( W cnd,
W x[],
size_t size )
inlineconstexpr

Definition at line 84 of file mp_core.h.

84 {
85 const auto mask = CT::Mask<W>::expand(cnd);
86
87 W carry = mask.if_set_return(1);
88 for(size_t i = 0; i != size; ++i) {
89 const W z = word_add(~x[i], static_cast<W>(0), &carry);
90 x[i] = mask.select(z, x[i]);
91 }
92}
static constexpr Mask< T > expand(T v)
Definition ct_utils.h:397

References Botan::CT::Mask< T >::expand(), and word_add().

◆ bigint_cnd_add()

template<WordType W>
W Botan::bigint_cnd_add ( W cnd,
W x[],
const W y[],
size_t size )
inlineconstexpr

Definition at line 49 of file mp_core.h.

49 {
50 const auto mask = CT::Mask<W>::expand(cnd).value();
51
52 W carry = 0;
53
54 for(size_t i = 0; i != size; ++i) {
55 x[i] = word_add(x[i], y[i] & mask, &carry);
56 }
57
58 return (mask & carry);
59}

References Botan::CT::Mask< T >::expand(), and word_add().

Referenced by Botan::Montgomery_Int::div2(), Botan::BigInt::mod_sub(), Botan::Montgomery_Int::operator-(), and Botan::Montgomery_Int::operator-=().

◆ bigint_cnd_sub()

template<WordType W>
auto Botan::bigint_cnd_sub ( W cnd,
W x[],
const W y[],
size_t size ) -> W
inlineconstexpr

Definition at line 66 of file mp_core.h.

66 {
67 const auto mask = CT::Mask<W>::expand(cnd).value();
68
69 W carry = 0;
70
71 for(size_t i = 0; i != size; ++i) {
72 x[i] = word_sub(x[i], y[i] & mask, &carry);
73 }
74
75 return (mask & carry);
76}
constexpr auto word_sub(W x, W y, W *carry) -> W
Definition mp_asmi.h:355

References Botan::CT::Mask< T >::expand(), and word_sub().

◆ bigint_cnd_swap()

template<WordType W>
void Botan::bigint_cnd_swap ( W cnd,
W x[],
W y[],
size_t size )
inlineconstexpr

Definition at line 33 of file mp_core.h.

33 {
34 const auto mask = CT::Mask<W>::expand(cnd);
35
36 for(size_t i = 0; i != size; ++i) {
37 const W a = x[i];
38 const W b = y[i];
39 x[i] = mask.select(b, a);
40 y[i] = mask.select(a, b);
41 }
42}

References Botan::CT::Mask< T >::expand().

Referenced by Botan::BigInt::ct_cond_swap().

◆ bigint_comba_mul16()

BOTAN_FUZZER_API void Botan::bigint_comba_mul16 ( word z[32],
const word x[16],
const word y[16] )

Definition at line 848 of file mp_comba.cpp.

848 {
849 word3<word> accum;
850
851 accum.mul(x[0], y[0]);
852 z[0] = accum.extract();
853 accum.mul(x[0], y[1]);
854 accum.mul(x[1], y[0]);
855 z[1] = accum.extract();
856 accum.mul(x[0], y[2]);
857 accum.mul(x[1], y[1]);
858 accum.mul(x[2], y[0]);
859 z[2] = accum.extract();
860 accum.mul(x[0], y[3]);
861 accum.mul(x[1], y[2]);
862 accum.mul(x[2], y[1]);
863 accum.mul(x[3], y[0]);
864 z[3] = accum.extract();
865 accum.mul(x[0], y[4]);
866 accum.mul(x[1], y[3]);
867 accum.mul(x[2], y[2]);
868 accum.mul(x[3], y[1]);
869 accum.mul(x[4], y[0]);
870 z[4] = accum.extract();
871 accum.mul(x[0], y[5]);
872 accum.mul(x[1], y[4]);
873 accum.mul(x[2], y[3]);
874 accum.mul(x[3], y[2]);
875 accum.mul(x[4], y[1]);
876 accum.mul(x[5], y[0]);
877 z[5] = accum.extract();
878 accum.mul(x[0], y[6]);
879 accum.mul(x[1], y[5]);
880 accum.mul(x[2], y[4]);
881 accum.mul(x[3], y[3]);
882 accum.mul(x[4], y[2]);
883 accum.mul(x[5], y[1]);
884 accum.mul(x[6], y[0]);
885 z[6] = accum.extract();
886 accum.mul(x[0], y[7]);
887 accum.mul(x[1], y[6]);
888 accum.mul(x[2], y[5]);
889 accum.mul(x[3], y[4]);
890 accum.mul(x[4], y[3]);
891 accum.mul(x[5], y[2]);
892 accum.mul(x[6], y[1]);
893 accum.mul(x[7], y[0]);
894 z[7] = accum.extract();
895 accum.mul(x[0], y[8]);
896 accum.mul(x[1], y[7]);
897 accum.mul(x[2], y[6]);
898 accum.mul(x[3], y[5]);
899 accum.mul(x[4], y[4]);
900 accum.mul(x[5], y[3]);
901 accum.mul(x[6], y[2]);
902 accum.mul(x[7], y[1]);
903 accum.mul(x[8], y[0]);
904 z[8] = accum.extract();
905 accum.mul(x[0], y[9]);
906 accum.mul(x[1], y[8]);
907 accum.mul(x[2], y[7]);
908 accum.mul(x[3], y[6]);
909 accum.mul(x[4], y[5]);
910 accum.mul(x[5], y[4]);
911 accum.mul(x[6], y[3]);
912 accum.mul(x[7], y[2]);
913 accum.mul(x[8], y[1]);
914 accum.mul(x[9], y[0]);
915 z[9] = accum.extract();
916 accum.mul(x[0], y[10]);
917 accum.mul(x[1], y[9]);
918 accum.mul(x[2], y[8]);
919 accum.mul(x[3], y[7]);
920 accum.mul(x[4], y[6]);
921 accum.mul(x[5], y[5]);
922 accum.mul(x[6], y[4]);
923 accum.mul(x[7], y[3]);
924 accum.mul(x[8], y[2]);
925 accum.mul(x[9], y[1]);
926 accum.mul(x[10], y[0]);
927 z[10] = accum.extract();
928 accum.mul(x[0], y[11]);
929 accum.mul(x[1], y[10]);
930 accum.mul(x[2], y[9]);
931 accum.mul(x[3], y[8]);
932 accum.mul(x[4], y[7]);
933 accum.mul(x[5], y[6]);
934 accum.mul(x[6], y[5]);
935 accum.mul(x[7], y[4]);
936 accum.mul(x[8], y[3]);
937 accum.mul(x[9], y[2]);
938 accum.mul(x[10], y[1]);
939 accum.mul(x[11], y[0]);
940 z[11] = accum.extract();
941 accum.mul(x[0], y[12]);
942 accum.mul(x[1], y[11]);
943 accum.mul(x[2], y[10]);
944 accum.mul(x[3], y[9]);
945 accum.mul(x[4], y[8]);
946 accum.mul(x[5], y[7]);
947 accum.mul(x[6], y[6]);
948 accum.mul(x[7], y[5]);
949 accum.mul(x[8], y[4]);
950 accum.mul(x[9], y[3]);
951 accum.mul(x[10], y[2]);
952 accum.mul(x[11], y[1]);
953 accum.mul(x[12], y[0]);
954 z[12] = accum.extract();
955 accum.mul(x[0], y[13]);
956 accum.mul(x[1], y[12]);
957 accum.mul(x[2], y[11]);
958 accum.mul(x[3], y[10]);
959 accum.mul(x[4], y[9]);
960 accum.mul(x[5], y[8]);
961 accum.mul(x[6], y[7]);
962 accum.mul(x[7], y[6]);
963 accum.mul(x[8], y[5]);
964 accum.mul(x[9], y[4]);
965 accum.mul(x[10], y[3]);
966 accum.mul(x[11], y[2]);
967 accum.mul(x[12], y[1]);
968 accum.mul(x[13], y[0]);
969 z[13] = accum.extract();
970 accum.mul(x[0], y[14]);
971 accum.mul(x[1], y[13]);
972 accum.mul(x[2], y[12]);
973 accum.mul(x[3], y[11]);
974 accum.mul(x[4], y[10]);
975 accum.mul(x[5], y[9]);
976 accum.mul(x[6], y[8]);
977 accum.mul(x[7], y[7]);
978 accum.mul(x[8], y[6]);
979 accum.mul(x[9], y[5]);
980 accum.mul(x[10], y[4]);
981 accum.mul(x[11], y[3]);
982 accum.mul(x[12], y[2]);
983 accum.mul(x[13], y[1]);
984 accum.mul(x[14], y[0]);
985 z[14] = accum.extract();
986 accum.mul(x[0], y[15]);
987 accum.mul(x[1], y[14]);
988 accum.mul(x[2], y[13]);
989 accum.mul(x[3], y[12]);
990 accum.mul(x[4], y[11]);
991 accum.mul(x[5], y[10]);
992 accum.mul(x[6], y[9]);
993 accum.mul(x[7], y[8]);
994 accum.mul(x[8], y[7]);
995 accum.mul(x[9], y[6]);
996 accum.mul(x[10], y[5]);
997 accum.mul(x[11], y[4]);
998 accum.mul(x[12], y[3]);
999 accum.mul(x[13], y[2]);
1000 accum.mul(x[14], y[1]);
1001 accum.mul(x[15], y[0]);
1002 z[15] = accum.extract();
1003 accum.mul(x[1], y[15]);
1004 accum.mul(x[2], y[14]);
1005 accum.mul(x[3], y[13]);
1006 accum.mul(x[4], y[12]);
1007 accum.mul(x[5], y[11]);
1008 accum.mul(x[6], y[10]);
1009 accum.mul(x[7], y[9]);
1010 accum.mul(x[8], y[8]);
1011 accum.mul(x[9], y[7]);
1012 accum.mul(x[10], y[6]);
1013 accum.mul(x[11], y[5]);
1014 accum.mul(x[12], y[4]);
1015 accum.mul(x[13], y[3]);
1016 accum.mul(x[14], y[2]);
1017 accum.mul(x[15], y[1]);
1018 z[16] = accum.extract();
1019 accum.mul(x[2], y[15]);
1020 accum.mul(x[3], y[14]);
1021 accum.mul(x[4], y[13]);
1022 accum.mul(x[5], y[12]);
1023 accum.mul(x[6], y[11]);
1024 accum.mul(x[7], y[10]);
1025 accum.mul(x[8], y[9]);
1026 accum.mul(x[9], y[8]);
1027 accum.mul(x[10], y[7]);
1028 accum.mul(x[11], y[6]);
1029 accum.mul(x[12], y[5]);
1030 accum.mul(x[13], y[4]);
1031 accum.mul(x[14], y[3]);
1032 accum.mul(x[15], y[2]);
1033 z[17] = accum.extract();
1034 accum.mul(x[3], y[15]);
1035 accum.mul(x[4], y[14]);
1036 accum.mul(x[5], y[13]);
1037 accum.mul(x[6], y[12]);
1038 accum.mul(x[7], y[11]);
1039 accum.mul(x[8], y[10]);
1040 accum.mul(x[9], y[9]);
1041 accum.mul(x[10], y[8]);
1042 accum.mul(x[11], y[7]);
1043 accum.mul(x[12], y[6]);
1044 accum.mul(x[13], y[5]);
1045 accum.mul(x[14], y[4]);
1046 accum.mul(x[15], y[3]);
1047 z[18] = accum.extract();
1048 accum.mul(x[4], y[15]);
1049 accum.mul(x[5], y[14]);
1050 accum.mul(x[6], y[13]);
1051 accum.mul(x[7], y[12]);
1052 accum.mul(x[8], y[11]);
1053 accum.mul(x[9], y[10]);
1054 accum.mul(x[10], y[9]);
1055 accum.mul(x[11], y[8]);
1056 accum.mul(x[12], y[7]);
1057 accum.mul(x[13], y[6]);
1058 accum.mul(x[14], y[5]);
1059 accum.mul(x[15], y[4]);
1060 z[19] = accum.extract();
1061 accum.mul(x[5], y[15]);
1062 accum.mul(x[6], y[14]);
1063 accum.mul(x[7], y[13]);
1064 accum.mul(x[8], y[12]);
1065 accum.mul(x[9], y[11]);
1066 accum.mul(x[10], y[10]);
1067 accum.mul(x[11], y[9]);
1068 accum.mul(x[12], y[8]);
1069 accum.mul(x[13], y[7]);
1070 accum.mul(x[14], y[6]);
1071 accum.mul(x[15], y[5]);
1072 z[20] = accum.extract();
1073 accum.mul(x[6], y[15]);
1074 accum.mul(x[7], y[14]);
1075 accum.mul(x[8], y[13]);
1076 accum.mul(x[9], y[12]);
1077 accum.mul(x[10], y[11]);
1078 accum.mul(x[11], y[10]);
1079 accum.mul(x[12], y[9]);
1080 accum.mul(x[13], y[8]);
1081 accum.mul(x[14], y[7]);
1082 accum.mul(x[15], y[6]);
1083 z[21] = accum.extract();
1084 accum.mul(x[7], y[15]);
1085 accum.mul(x[8], y[14]);
1086 accum.mul(x[9], y[13]);
1087 accum.mul(x[10], y[12]);
1088 accum.mul(x[11], y[11]);
1089 accum.mul(x[12], y[10]);
1090 accum.mul(x[13], y[9]);
1091 accum.mul(x[14], y[8]);
1092 accum.mul(x[15], y[7]);
1093 z[22] = accum.extract();
1094 accum.mul(x[8], y[15]);
1095 accum.mul(x[9], y[14]);
1096 accum.mul(x[10], y[13]);
1097 accum.mul(x[11], y[12]);
1098 accum.mul(x[12], y[11]);
1099 accum.mul(x[13], y[10]);
1100 accum.mul(x[14], y[9]);
1101 accum.mul(x[15], y[8]);
1102 z[23] = accum.extract();
1103 accum.mul(x[9], y[15]);
1104 accum.mul(x[10], y[14]);
1105 accum.mul(x[11], y[13]);
1106 accum.mul(x[12], y[12]);
1107 accum.mul(x[13], y[11]);
1108 accum.mul(x[14], y[10]);
1109 accum.mul(x[15], y[9]);
1110 z[24] = accum.extract();
1111 accum.mul(x[10], y[15]);
1112 accum.mul(x[11], y[14]);
1113 accum.mul(x[12], y[13]);
1114 accum.mul(x[13], y[12]);
1115 accum.mul(x[14], y[11]);
1116 accum.mul(x[15], y[10]);
1117 z[25] = accum.extract();
1118 accum.mul(x[11], y[15]);
1119 accum.mul(x[12], y[14]);
1120 accum.mul(x[13], y[13]);
1121 accum.mul(x[14], y[12]);
1122 accum.mul(x[15], y[11]);
1123 z[26] = accum.extract();
1124 accum.mul(x[12], y[15]);
1125 accum.mul(x[13], y[14]);
1126 accum.mul(x[14], y[13]);
1127 accum.mul(x[15], y[12]);
1128 z[27] = accum.extract();
1129 accum.mul(x[13], y[15]);
1130 accum.mul(x[14], y[14]);
1131 accum.mul(x[15], y[13]);
1132 z[28] = accum.extract();
1133 accum.mul(x[14], y[15]);
1134 accum.mul(x[15], y[14]);
1135 z[29] = accum.extract();
1136 accum.mul(x[15], y[15]);
1137 z[30] = accum.extract();
1138 z[31] = accum.extract();
1139}
constexpr W extract()
Definition mp_asmi.h:665
constexpr void mul(W x, W y)
Definition mp_asmi.h:542

References Botan::word3< W >::extract(), and Botan::word3< W >::mul().

Referenced by bigint_mul(), and comba_mul().

◆ bigint_comba_mul24()

BOTAN_FUZZER_API void Botan::bigint_comba_mul24 ( word z[48],
const word x[24],
const word y[24] )

Definition at line 1500 of file mp_comba.cpp.

1500 {
1501 word3<word> accum;
1502
1503 accum.mul(x[0], y[0]);
1504 z[0] = accum.extract();
1505 accum.mul(x[0], y[1]);
1506 accum.mul(x[1], y[0]);
1507 z[1] = accum.extract();
1508 accum.mul(x[0], y[2]);
1509 accum.mul(x[1], y[1]);
1510 accum.mul(x[2], y[0]);
1511 z[2] = accum.extract();
1512 accum.mul(x[0], y[3]);
1513 accum.mul(x[1], y[2]);
1514 accum.mul(x[2], y[1]);
1515 accum.mul(x[3], y[0]);
1516 z[3] = accum.extract();
1517 accum.mul(x[0], y[4]);
1518 accum.mul(x[1], y[3]);
1519 accum.mul(x[2], y[2]);
1520 accum.mul(x[3], y[1]);
1521 accum.mul(x[4], y[0]);
1522 z[4] = accum.extract();
1523 accum.mul(x[0], y[5]);
1524 accum.mul(x[1], y[4]);
1525 accum.mul(x[2], y[3]);
1526 accum.mul(x[3], y[2]);
1527 accum.mul(x[4], y[1]);
1528 accum.mul(x[5], y[0]);
1529 z[5] = accum.extract();
1530 accum.mul(x[0], y[6]);
1531 accum.mul(x[1], y[5]);
1532 accum.mul(x[2], y[4]);
1533 accum.mul(x[3], y[3]);
1534 accum.mul(x[4], y[2]);
1535 accum.mul(x[5], y[1]);
1536 accum.mul(x[6], y[0]);
1537 z[6] = accum.extract();
1538 accum.mul(x[0], y[7]);
1539 accum.mul(x[1], y[6]);
1540 accum.mul(x[2], y[5]);
1541 accum.mul(x[3], y[4]);
1542 accum.mul(x[4], y[3]);
1543 accum.mul(x[5], y[2]);
1544 accum.mul(x[6], y[1]);
1545 accum.mul(x[7], y[0]);
1546 z[7] = accum.extract();
1547 accum.mul(x[0], y[8]);
1548 accum.mul(x[1], y[7]);
1549 accum.mul(x[2], y[6]);
1550 accum.mul(x[3], y[5]);
1551 accum.mul(x[4], y[4]);
1552 accum.mul(x[5], y[3]);
1553 accum.mul(x[6], y[2]);
1554 accum.mul(x[7], y[1]);
1555 accum.mul(x[8], y[0]);
1556 z[8] = accum.extract();
1557 accum.mul(x[0], y[9]);
1558 accum.mul(x[1], y[8]);
1559 accum.mul(x[2], y[7]);
1560 accum.mul(x[3], y[6]);
1561 accum.mul(x[4], y[5]);
1562 accum.mul(x[5], y[4]);
1563 accum.mul(x[6], y[3]);
1564 accum.mul(x[7], y[2]);
1565 accum.mul(x[8], y[1]);
1566 accum.mul(x[9], y[0]);
1567 z[9] = accum.extract();
1568 accum.mul(x[0], y[10]);
1569 accum.mul(x[1], y[9]);
1570 accum.mul(x[2], y[8]);
1571 accum.mul(x[3], y[7]);
1572 accum.mul(x[4], y[6]);
1573 accum.mul(x[5], y[5]);
1574 accum.mul(x[6], y[4]);
1575 accum.mul(x[7], y[3]);
1576 accum.mul(x[8], y[2]);
1577 accum.mul(x[9], y[1]);
1578 accum.mul(x[10], y[0]);
1579 z[10] = accum.extract();
1580 accum.mul(x[0], y[11]);
1581 accum.mul(x[1], y[10]);
1582 accum.mul(x[2], y[9]);
1583 accum.mul(x[3], y[8]);
1584 accum.mul(x[4], y[7]);
1585 accum.mul(x[5], y[6]);
1586 accum.mul(x[6], y[5]);
1587 accum.mul(x[7], y[4]);
1588 accum.mul(x[8], y[3]);
1589 accum.mul(x[9], y[2]);
1590 accum.mul(x[10], y[1]);
1591 accum.mul(x[11], y[0]);
1592 z[11] = accum.extract();
1593 accum.mul(x[0], y[12]);
1594 accum.mul(x[1], y[11]);
1595 accum.mul(x[2], y[10]);
1596 accum.mul(x[3], y[9]);
1597 accum.mul(x[4], y[8]);
1598 accum.mul(x[5], y[7]);
1599 accum.mul(x[6], y[6]);
1600 accum.mul(x[7], y[5]);
1601 accum.mul(x[8], y[4]);
1602 accum.mul(x[9], y[3]);
1603 accum.mul(x[10], y[2]);
1604 accum.mul(x[11], y[1]);
1605 accum.mul(x[12], y[0]);
1606 z[12] = accum.extract();
1607 accum.mul(x[0], y[13]);
1608 accum.mul(x[1], y[12]);
1609 accum.mul(x[2], y[11]);
1610 accum.mul(x[3], y[10]);
1611 accum.mul(x[4], y[9]);
1612 accum.mul(x[5], y[8]);
1613 accum.mul(x[6], y[7]);
1614 accum.mul(x[7], y[6]);
1615 accum.mul(x[8], y[5]);
1616 accum.mul(x[9], y[4]);
1617 accum.mul(x[10], y[3]);
1618 accum.mul(x[11], y[2]);
1619 accum.mul(x[12], y[1]);
1620 accum.mul(x[13], y[0]);
1621 z[13] = accum.extract();
1622 accum.mul(x[0], y[14]);
1623 accum.mul(x[1], y[13]);
1624 accum.mul(x[2], y[12]);
1625 accum.mul(x[3], y[11]);
1626 accum.mul(x[4], y[10]);
1627 accum.mul(x[5], y[9]);
1628 accum.mul(x[6], y[8]);
1629 accum.mul(x[7], y[7]);
1630 accum.mul(x[8], y[6]);
1631 accum.mul(x[9], y[5]);
1632 accum.mul(x[10], y[4]);
1633 accum.mul(x[11], y[3]);
1634 accum.mul(x[12], y[2]);
1635 accum.mul(x[13], y[1]);
1636 accum.mul(x[14], y[0]);
1637 z[14] = accum.extract();
1638 accum.mul(x[0], y[15]);
1639 accum.mul(x[1], y[14]);
1640 accum.mul(x[2], y[13]);
1641 accum.mul(x[3], y[12]);
1642 accum.mul(x[4], y[11]);
1643 accum.mul(x[5], y[10]);
1644 accum.mul(x[6], y[9]);
1645 accum.mul(x[7], y[8]);
1646 accum.mul(x[8], y[7]);
1647 accum.mul(x[9], y[6]);
1648 accum.mul(x[10], y[5]);
1649 accum.mul(x[11], y[4]);
1650 accum.mul(x[12], y[3]);
1651 accum.mul(x[13], y[2]);
1652 accum.mul(x[14], y[1]);
1653 accum.mul(x[15], y[0]);
1654 z[15] = accum.extract();
1655 accum.mul(x[0], y[16]);
1656 accum.mul(x[1], y[15]);
1657 accum.mul(x[2], y[14]);
1658 accum.mul(x[3], y[13]);
1659 accum.mul(x[4], y[12]);
1660 accum.mul(x[5], y[11]);
1661 accum.mul(x[6], y[10]);
1662 accum.mul(x[7], y[9]);
1663 accum.mul(x[8], y[8]);
1664 accum.mul(x[9], y[7]);
1665 accum.mul(x[10], y[6]);
1666 accum.mul(x[11], y[5]);
1667 accum.mul(x[12], y[4]);
1668 accum.mul(x[13], y[3]);
1669 accum.mul(x[14], y[2]);
1670 accum.mul(x[15], y[1]);
1671 accum.mul(x[16], y[0]);
1672 z[16] = accum.extract();
1673 accum.mul(x[0], y[17]);
1674 accum.mul(x[1], y[16]);
1675 accum.mul(x[2], y[15]);
1676 accum.mul(x[3], y[14]);
1677 accum.mul(x[4], y[13]);
1678 accum.mul(x[5], y[12]);
1679 accum.mul(x[6], y[11]);
1680 accum.mul(x[7], y[10]);
1681 accum.mul(x[8], y[9]);
1682 accum.mul(x[9], y[8]);
1683 accum.mul(x[10], y[7]);
1684 accum.mul(x[11], y[6]);
1685 accum.mul(x[12], y[5]);
1686 accum.mul(x[13], y[4]);
1687 accum.mul(x[14], y[3]);
1688 accum.mul(x[15], y[2]);
1689 accum.mul(x[16], y[1]);
1690 accum.mul(x[17], y[0]);
1691 z[17] = accum.extract();
1692 accum.mul(x[0], y[18]);
1693 accum.mul(x[1], y[17]);
1694 accum.mul(x[2], y[16]);
1695 accum.mul(x[3], y[15]);
1696 accum.mul(x[4], y[14]);
1697 accum.mul(x[5], y[13]);
1698 accum.mul(x[6], y[12]);
1699 accum.mul(x[7], y[11]);
1700 accum.mul(x[8], y[10]);
1701 accum.mul(x[9], y[9]);
1702 accum.mul(x[10], y[8]);
1703 accum.mul(x[11], y[7]);
1704 accum.mul(x[12], y[6]);
1705 accum.mul(x[13], y[5]);
1706 accum.mul(x[14], y[4]);
1707 accum.mul(x[15], y[3]);
1708 accum.mul(x[16], y[2]);
1709 accum.mul(x[17], y[1]);
1710 accum.mul(x[18], y[0]);
1711 z[18] = accum.extract();
1712 accum.mul(x[0], y[19]);
1713 accum.mul(x[1], y[18]);
1714 accum.mul(x[2], y[17]);
1715 accum.mul(x[3], y[16]);
1716 accum.mul(x[4], y[15]);
1717 accum.mul(x[5], y[14]);
1718 accum.mul(x[6], y[13]);
1719 accum.mul(x[7], y[12]);
1720 accum.mul(x[8], y[11]);
1721 accum.mul(x[9], y[10]);
1722 accum.mul(x[10], y[9]);
1723 accum.mul(x[11], y[8]);
1724 accum.mul(x[12], y[7]);
1725 accum.mul(x[13], y[6]);
1726 accum.mul(x[14], y[5]);
1727 accum.mul(x[15], y[4]);
1728 accum.mul(x[16], y[3]);
1729 accum.mul(x[17], y[2]);
1730 accum.mul(x[18], y[1]);
1731 accum.mul(x[19], y[0]);
1732 z[19] = accum.extract();
1733 accum.mul(x[0], y[20]);
1734 accum.mul(x[1], y[19]);
1735 accum.mul(x[2], y[18]);
1736 accum.mul(x[3], y[17]);
1737 accum.mul(x[4], y[16]);
1738 accum.mul(x[5], y[15]);
1739 accum.mul(x[6], y[14]);
1740 accum.mul(x[7], y[13]);
1741 accum.mul(x[8], y[12]);
1742 accum.mul(x[9], y[11]);
1743 accum.mul(x[10], y[10]);
1744 accum.mul(x[11], y[9]);
1745 accum.mul(x[12], y[8]);
1746 accum.mul(x[13], y[7]);
1747 accum.mul(x[14], y[6]);
1748 accum.mul(x[15], y[5]);
1749 accum.mul(x[16], y[4]);
1750 accum.mul(x[17], y[3]);
1751 accum.mul(x[18], y[2]);
1752 accum.mul(x[19], y[1]);
1753 accum.mul(x[20], y[0]);
1754 z[20] = accum.extract();
1755 accum.mul(x[0], y[21]);
1756 accum.mul(x[1], y[20]);
1757 accum.mul(x[2], y[19]);
1758 accum.mul(x[3], y[18]);
1759 accum.mul(x[4], y[17]);
1760 accum.mul(x[5], y[16]);
1761 accum.mul(x[6], y[15]);
1762 accum.mul(x[7], y[14]);
1763 accum.mul(x[8], y[13]);
1764 accum.mul(x[9], y[12]);
1765 accum.mul(x[10], y[11]);
1766 accum.mul(x[11], y[10]);
1767 accum.mul(x[12], y[9]);
1768 accum.mul(x[13], y[8]);
1769 accum.mul(x[14], y[7]);
1770 accum.mul(x[15], y[6]);
1771 accum.mul(x[16], y[5]);
1772 accum.mul(x[17], y[4]);
1773 accum.mul(x[18], y[3]);
1774 accum.mul(x[19], y[2]);
1775 accum.mul(x[20], y[1]);
1776 accum.mul(x[21], y[0]);
1777 z[21] = accum.extract();
1778 accum.mul(x[0], y[22]);
1779 accum.mul(x[1], y[21]);
1780 accum.mul(x[2], y[20]);
1781 accum.mul(x[3], y[19]);
1782 accum.mul(x[4], y[18]);
1783 accum.mul(x[5], y[17]);
1784 accum.mul(x[6], y[16]);
1785 accum.mul(x[7], y[15]);
1786 accum.mul(x[8], y[14]);
1787 accum.mul(x[9], y[13]);
1788 accum.mul(x[10], y[12]);
1789 accum.mul(x[11], y[11]);
1790 accum.mul(x[12], y[10]);
1791 accum.mul(x[13], y[9]);
1792 accum.mul(x[14], y[8]);
1793 accum.mul(x[15], y[7]);
1794 accum.mul(x[16], y[6]);
1795 accum.mul(x[17], y[5]);
1796 accum.mul(x[18], y[4]);
1797 accum.mul(x[19], y[3]);
1798 accum.mul(x[20], y[2]);
1799 accum.mul(x[21], y[1]);
1800 accum.mul(x[22], y[0]);
1801 z[22] = accum.extract();
1802 accum.mul(x[0], y[23]);
1803 accum.mul(x[1], y[22]);
1804 accum.mul(x[2], y[21]);
1805 accum.mul(x[3], y[20]);
1806 accum.mul(x[4], y[19]);
1807 accum.mul(x[5], y[18]);
1808 accum.mul(x[6], y[17]);
1809 accum.mul(x[7], y[16]);
1810 accum.mul(x[8], y[15]);
1811 accum.mul(x[9], y[14]);
1812 accum.mul(x[10], y[13]);
1813 accum.mul(x[11], y[12]);
1814 accum.mul(x[12], y[11]);
1815 accum.mul(x[13], y[10]);
1816 accum.mul(x[14], y[9]);
1817 accum.mul(x[15], y[8]);
1818 accum.mul(x[16], y[7]);
1819 accum.mul(x[17], y[6]);
1820 accum.mul(x[18], y[5]);
1821 accum.mul(x[19], y[4]);
1822 accum.mul(x[20], y[3]);
1823 accum.mul(x[21], y[2]);
1824 accum.mul(x[22], y[1]);
1825 accum.mul(x[23], y[0]);
1826 z[23] = accum.extract();
1827 accum.mul(x[1], y[23]);
1828 accum.mul(x[2], y[22]);
1829 accum.mul(x[3], y[21]);
1830 accum.mul(x[4], y[20]);
1831 accum.mul(x[5], y[19]);
1832 accum.mul(x[6], y[18]);
1833 accum.mul(x[7], y[17]);
1834 accum.mul(x[8], y[16]);
1835 accum.mul(x[9], y[15]);
1836 accum.mul(x[10], y[14]);
1837 accum.mul(x[11], y[13]);
1838 accum.mul(x[12], y[12]);
1839 accum.mul(x[13], y[11]);
1840 accum.mul(x[14], y[10]);
1841 accum.mul(x[15], y[9]);
1842 accum.mul(x[16], y[8]);
1843 accum.mul(x[17], y[7]);
1844 accum.mul(x[18], y[6]);
1845 accum.mul(x[19], y[5]);
1846 accum.mul(x[20], y[4]);
1847 accum.mul(x[21], y[3]);
1848 accum.mul(x[22], y[2]);
1849 accum.mul(x[23], y[1]);
1850 z[24] = accum.extract();
1851 accum.mul(x[2], y[23]);
1852 accum.mul(x[3], y[22]);
1853 accum.mul(x[4], y[21]);
1854 accum.mul(x[5], y[20]);
1855 accum.mul(x[6], y[19]);
1856 accum.mul(x[7], y[18]);
1857 accum.mul(x[8], y[17]);
1858 accum.mul(x[9], y[16]);
1859 accum.mul(x[10], y[15]);
1860 accum.mul(x[11], y[14]);
1861 accum.mul(x[12], y[13]);
1862 accum.mul(x[13], y[12]);
1863 accum.mul(x[14], y[11]);
1864 accum.mul(x[15], y[10]);
1865 accum.mul(x[16], y[9]);
1866 accum.mul(x[17], y[8]);
1867 accum.mul(x[18], y[7]);
1868 accum.mul(x[19], y[6]);
1869 accum.mul(x[20], y[5]);
1870 accum.mul(x[21], y[4]);
1871 accum.mul(x[22], y[3]);
1872 accum.mul(x[23], y[2]);
1873 z[25] = accum.extract();
1874 accum.mul(x[3], y[23]);
1875 accum.mul(x[4], y[22]);
1876 accum.mul(x[5], y[21]);
1877 accum.mul(x[6], y[20]);
1878 accum.mul(x[7], y[19]);
1879 accum.mul(x[8], y[18]);
1880 accum.mul(x[9], y[17]);
1881 accum.mul(x[10], y[16]);
1882 accum.mul(x[11], y[15]);
1883 accum.mul(x[12], y[14]);
1884 accum.mul(x[13], y[13]);
1885 accum.mul(x[14], y[12]);
1886 accum.mul(x[15], y[11]);
1887 accum.mul(x[16], y[10]);
1888 accum.mul(x[17], y[9]);
1889 accum.mul(x[18], y[8]);
1890 accum.mul(x[19], y[7]);
1891 accum.mul(x[20], y[6]);
1892 accum.mul(x[21], y[5]);
1893 accum.mul(x[22], y[4]);
1894 accum.mul(x[23], y[3]);
1895 z[26] = accum.extract();
1896 accum.mul(x[4], y[23]);
1897 accum.mul(x[5], y[22]);
1898 accum.mul(x[6], y[21]);
1899 accum.mul(x[7], y[20]);
1900 accum.mul(x[8], y[19]);
1901 accum.mul(x[9], y[18]);
1902 accum.mul(x[10], y[17]);
1903 accum.mul(x[11], y[16]);
1904 accum.mul(x[12], y[15]);
1905 accum.mul(x[13], y[14]);
1906 accum.mul(x[14], y[13]);
1907 accum.mul(x[15], y[12]);
1908 accum.mul(x[16], y[11]);
1909 accum.mul(x[17], y[10]);
1910 accum.mul(x[18], y[9]);
1911 accum.mul(x[19], y[8]);
1912 accum.mul(x[20], y[7]);
1913 accum.mul(x[21], y[6]);
1914 accum.mul(x[22], y[5]);
1915 accum.mul(x[23], y[4]);
1916 z[27] = accum.extract();
1917 accum.mul(x[5], y[23]);
1918 accum.mul(x[6], y[22]);
1919 accum.mul(x[7], y[21]);
1920 accum.mul(x[8], y[20]);
1921 accum.mul(x[9], y[19]);
1922 accum.mul(x[10], y[18]);
1923 accum.mul(x[11], y[17]);
1924 accum.mul(x[12], y[16]);
1925 accum.mul(x[13], y[15]);
1926 accum.mul(x[14], y[14]);
1927 accum.mul(x[15], y[13]);
1928 accum.mul(x[16], y[12]);
1929 accum.mul(x[17], y[11]);
1930 accum.mul(x[18], y[10]);
1931 accum.mul(x[19], y[9]);
1932 accum.mul(x[20], y[8]);
1933 accum.mul(x[21], y[7]);
1934 accum.mul(x[22], y[6]);
1935 accum.mul(x[23], y[5]);
1936 z[28] = accum.extract();
1937 accum.mul(x[6], y[23]);
1938 accum.mul(x[7], y[22]);
1939 accum.mul(x[8], y[21]);
1940 accum.mul(x[9], y[20]);
1941 accum.mul(x[10], y[19]);
1942 accum.mul(x[11], y[18]);
1943 accum.mul(x[12], y[17]);
1944 accum.mul(x[13], y[16]);
1945 accum.mul(x[14], y[15]);
1946 accum.mul(x[15], y[14]);
1947 accum.mul(x[16], y[13]);
1948 accum.mul(x[17], y[12]);
1949 accum.mul(x[18], y[11]);
1950 accum.mul(x[19], y[10]);
1951 accum.mul(x[20], y[9]);
1952 accum.mul(x[21], y[8]);
1953 accum.mul(x[22], y[7]);
1954 accum.mul(x[23], y[6]);
1955 z[29] = accum.extract();
1956 accum.mul(x[7], y[23]);
1957 accum.mul(x[8], y[22]);
1958 accum.mul(x[9], y[21]);
1959 accum.mul(x[10], y[20]);
1960 accum.mul(x[11], y[19]);
1961 accum.mul(x[12], y[18]);
1962 accum.mul(x[13], y[17]);
1963 accum.mul(x[14], y[16]);
1964 accum.mul(x[15], y[15]);
1965 accum.mul(x[16], y[14]);
1966 accum.mul(x[17], y[13]);
1967 accum.mul(x[18], y[12]);
1968 accum.mul(x[19], y[11]);
1969 accum.mul(x[20], y[10]);
1970 accum.mul(x[21], y[9]);
1971 accum.mul(x[22], y[8]);
1972 accum.mul(x[23], y[7]);
1973 z[30] = accum.extract();
1974 accum.mul(x[8], y[23]);
1975 accum.mul(x[9], y[22]);
1976 accum.mul(x[10], y[21]);
1977 accum.mul(x[11], y[20]);
1978 accum.mul(x[12], y[19]);
1979 accum.mul(x[13], y[18]);
1980 accum.mul(x[14], y[17]);
1981 accum.mul(x[15], y[16]);
1982 accum.mul(x[16], y[15]);
1983 accum.mul(x[17], y[14]);
1984 accum.mul(x[18], y[13]);
1985 accum.mul(x[19], y[12]);
1986 accum.mul(x[20], y[11]);
1987 accum.mul(x[21], y[10]);
1988 accum.mul(x[22], y[9]);
1989 accum.mul(x[23], y[8]);
1990 z[31] = accum.extract();
1991 accum.mul(x[9], y[23]);
1992 accum.mul(x[10], y[22]);
1993 accum.mul(x[11], y[21]);
1994 accum.mul(x[12], y[20]);
1995 accum.mul(x[13], y[19]);
1996 accum.mul(x[14], y[18]);
1997 accum.mul(x[15], y[17]);
1998 accum.mul(x[16], y[16]);
1999 accum.mul(x[17], y[15]);
2000 accum.mul(x[18], y[14]);
2001 accum.mul(x[19], y[13]);
2002 accum.mul(x[20], y[12]);
2003 accum.mul(x[21], y[11]);
2004 accum.mul(x[22], y[10]);
2005 accum.mul(x[23], y[9]);
2006 z[32] = accum.extract();
2007 accum.mul(x[10], y[23]);
2008 accum.mul(x[11], y[22]);
2009 accum.mul(x[12], y[21]);
2010 accum.mul(x[13], y[20]);
2011 accum.mul(x[14], y[19]);
2012 accum.mul(x[15], y[18]);
2013 accum.mul(x[16], y[17]);
2014 accum.mul(x[17], y[16]);
2015 accum.mul(x[18], y[15]);
2016 accum.mul(x[19], y[14]);
2017 accum.mul(x[20], y[13]);
2018 accum.mul(x[21], y[12]);
2019 accum.mul(x[22], y[11]);
2020 accum.mul(x[23], y[10]);
2021 z[33] = accum.extract();
2022 accum.mul(x[11], y[23]);
2023 accum.mul(x[12], y[22]);
2024 accum.mul(x[13], y[21]);
2025 accum.mul(x[14], y[20]);
2026 accum.mul(x[15], y[19]);
2027 accum.mul(x[16], y[18]);
2028 accum.mul(x[17], y[17]);
2029 accum.mul(x[18], y[16]);
2030 accum.mul(x[19], y[15]);
2031 accum.mul(x[20], y[14]);
2032 accum.mul(x[21], y[13]);
2033 accum.mul(x[22], y[12]);
2034 accum.mul(x[23], y[11]);
2035 z[34] = accum.extract();
2036 accum.mul(x[12], y[23]);
2037 accum.mul(x[13], y[22]);
2038 accum.mul(x[14], y[21]);
2039 accum.mul(x[15], y[20]);
2040 accum.mul(x[16], y[19]);
2041 accum.mul(x[17], y[18]);
2042 accum.mul(x[18], y[17]);
2043 accum.mul(x[19], y[16]);
2044 accum.mul(x[20], y[15]);
2045 accum.mul(x[21], y[14]);
2046 accum.mul(x[22], y[13]);
2047 accum.mul(x[23], y[12]);
2048 z[35] = accum.extract();
2049 accum.mul(x[13], y[23]);
2050 accum.mul(x[14], y[22]);
2051 accum.mul(x[15], y[21]);
2052 accum.mul(x[16], y[20]);
2053 accum.mul(x[17], y[19]);
2054 accum.mul(x[18], y[18]);
2055 accum.mul(x[19], y[17]);
2056 accum.mul(x[20], y[16]);
2057 accum.mul(x[21], y[15]);
2058 accum.mul(x[22], y[14]);
2059 accum.mul(x[23], y[13]);
2060 z[36] = accum.extract();
2061 accum.mul(x[14], y[23]);
2062 accum.mul(x[15], y[22]);
2063 accum.mul(x[16], y[21]);
2064 accum.mul(x[17], y[20]);
2065 accum.mul(x[18], y[19]);
2066 accum.mul(x[19], y[18]);
2067 accum.mul(x[20], y[17]);
2068 accum.mul(x[21], y[16]);
2069 accum.mul(x[22], y[15]);
2070 accum.mul(x[23], y[14]);
2071 z[37] = accum.extract();
2072 accum.mul(x[15], y[23]);
2073 accum.mul(x[16], y[22]);
2074 accum.mul(x[17], y[21]);
2075 accum.mul(x[18], y[20]);
2076 accum.mul(x[19], y[19]);
2077 accum.mul(x[20], y[18]);
2078 accum.mul(x[21], y[17]);
2079 accum.mul(x[22], y[16]);
2080 accum.mul(x[23], y[15]);
2081 z[38] = accum.extract();
2082 accum.mul(x[16], y[23]);
2083 accum.mul(x[17], y[22]);
2084 accum.mul(x[18], y[21]);
2085 accum.mul(x[19], y[20]);
2086 accum.mul(x[20], y[19]);
2087 accum.mul(x[21], y[18]);
2088 accum.mul(x[22], y[17]);
2089 accum.mul(x[23], y[16]);
2090 z[39] = accum.extract();
2091 accum.mul(x[17], y[23]);
2092 accum.mul(x[18], y[22]);
2093 accum.mul(x[19], y[21]);
2094 accum.mul(x[20], y[20]);
2095 accum.mul(x[21], y[19]);
2096 accum.mul(x[22], y[18]);
2097 accum.mul(x[23], y[17]);
2098 z[40] = accum.extract();
2099 accum.mul(x[18], y[23]);
2100 accum.mul(x[19], y[22]);
2101 accum.mul(x[20], y[21]);
2102 accum.mul(x[21], y[20]);
2103 accum.mul(x[22], y[19]);
2104 accum.mul(x[23], y[18]);
2105 z[41] = accum.extract();
2106 accum.mul(x[19], y[23]);
2107 accum.mul(x[20], y[22]);
2108 accum.mul(x[21], y[21]);
2109 accum.mul(x[22], y[20]);
2110 accum.mul(x[23], y[19]);
2111 z[42] = accum.extract();
2112 accum.mul(x[20], y[23]);
2113 accum.mul(x[21], y[22]);
2114 accum.mul(x[22], y[21]);
2115 accum.mul(x[23], y[20]);
2116 z[43] = accum.extract();
2117 accum.mul(x[21], y[23]);
2118 accum.mul(x[22], y[22]);
2119 accum.mul(x[23], y[21]);
2120 z[44] = accum.extract();
2121 accum.mul(x[22], y[23]);
2122 accum.mul(x[23], y[22]);
2123 z[45] = accum.extract();
2124 accum.mul(x[23], y[23]);
2125 z[46] = accum.extract();
2126 z[47] = accum.extract();
2127}

References Botan::word3< W >::extract(), and Botan::word3< W >::mul().

Referenced by bigint_mul().

◆ bigint_comba_mul4()

BOTAN_FUZZER_API void Botan::bigint_comba_mul4 ( word z[8],
const word x[4],
const word y[4] )

Definition at line 54 of file mp_comba.cpp.

54 {
55#if defined(BOTAN_HAS_MP_MULX)
57 return bigint_mulx_mul4(z, x, y);
58 }
59#endif
60
61 word3<word> accum;
62
63 accum.mul(x[0], y[0]);
64 z[0] = accum.extract();
65 accum.mul(x[0], y[1]);
66 accum.mul(x[1], y[0]);
67 z[1] = accum.extract();
68 accum.mul(x[0], y[2]);
69 accum.mul(x[1], y[1]);
70 accum.mul(x[2], y[0]);
71 z[2] = accum.extract();
72 accum.mul(x[0], y[3]);
73 accum.mul(x[1], y[2]);
74 accum.mul(x[2], y[1]);
75 accum.mul(x[3], y[0]);
76 z[3] = accum.extract();
77 accum.mul(x[1], y[3]);
78 accum.mul(x[2], y[2]);
79 accum.mul(x[3], y[1]);
80 z[4] = accum.extract();
81 accum.mul(x[2], y[3]);
82 accum.mul(x[3], y[2]);
83 z[5] = accum.extract();
84 accum.mul(x[3], y[3]);
85 z[6] = accum.extract();
86 z[7] = accum.extract();
87}
void bigint_mulx_mul4(word z[8], const word x[4], const word y[4])
Definition mp_mulx.cpp:122

References Botan::CPUFeature::ADX, bigint_mulx_mul4(), Botan::CPUFeature::BMI, Botan::word3< W >::extract(), Botan::CPUID::has(), and Botan::word3< W >::mul().

Referenced by bigint_mul(), and comba_mul().

◆ bigint_comba_mul6()

BOTAN_FUZZER_API void Botan::bigint_comba_mul6 ( word z[12],
const word x[6],
const word y[6] )

Definition at line 139 of file mp_comba.cpp.

139 {
140#if defined(BOTAN_HAS_MP_MULX)
142 return bigint_mulx_mul6(z, x, y);
143 }
144#endif
145
146 word3<word> accum;
147
148 accum.mul(x[0], y[0]);
149 z[0] = accum.extract();
150 accum.mul(x[0], y[1]);
151 accum.mul(x[1], y[0]);
152 z[1] = accum.extract();
153 accum.mul(x[0], y[2]);
154 accum.mul(x[1], y[1]);
155 accum.mul(x[2], y[0]);
156 z[2] = accum.extract();
157 accum.mul(x[0], y[3]);
158 accum.mul(x[1], y[2]);
159 accum.mul(x[2], y[1]);
160 accum.mul(x[3], y[0]);
161 z[3] = accum.extract();
162 accum.mul(x[0], y[4]);
163 accum.mul(x[1], y[3]);
164 accum.mul(x[2], y[2]);
165 accum.mul(x[3], y[1]);
166 accum.mul(x[4], y[0]);
167 z[4] = accum.extract();
168 accum.mul(x[0], y[5]);
169 accum.mul(x[1], y[4]);
170 accum.mul(x[2], y[3]);
171 accum.mul(x[3], y[2]);
172 accum.mul(x[4], y[1]);
173 accum.mul(x[5], y[0]);
174 z[5] = accum.extract();
175 accum.mul(x[1], y[5]);
176 accum.mul(x[2], y[4]);
177 accum.mul(x[3], y[3]);
178 accum.mul(x[4], y[2]);
179 accum.mul(x[5], y[1]);
180 z[6] = accum.extract();
181 accum.mul(x[2], y[5]);
182 accum.mul(x[3], y[4]);
183 accum.mul(x[4], y[3]);
184 accum.mul(x[5], y[2]);
185 z[7] = accum.extract();
186 accum.mul(x[3], y[5]);
187 accum.mul(x[4], y[4]);
188 accum.mul(x[5], y[3]);
189 z[8] = accum.extract();
190 accum.mul(x[4], y[5]);
191 accum.mul(x[5], y[4]);
192 z[9] = accum.extract();
193 accum.mul(x[5], y[5]);
194 z[10] = accum.extract();
195 z[11] = accum.extract();
196}
void bigint_mulx_mul6(word z[12], const word x[6], const word y[6])
Definition mp_mulx.cpp:371

References Botan::CPUFeature::ADX, bigint_mulx_mul6(), Botan::CPUFeature::BMI, Botan::word3< W >::extract(), Botan::CPUID::has(), and Botan::word3< W >::mul().

Referenced by bigint_mul(), and comba_mul().

◆ bigint_comba_mul7()

BOTAN_FUZZER_API void Botan::bigint_comba_mul7 ( word z[14],
const word x[7],
const word y[7] )

Definition at line 251 of file mp_comba.cpp.

251 {
252 word3<word> accum;
253
254 accum.mul(x[0], y[0]);
255 z[0] = accum.extract();
256 accum.mul(x[0], y[1]);
257 accum.mul(x[1], y[0]);
258 z[1] = accum.extract();
259 accum.mul(x[0], y[2]);
260 accum.mul(x[1], y[1]);
261 accum.mul(x[2], y[0]);
262 z[2] = accum.extract();
263 accum.mul(x[0], y[3]);
264 accum.mul(x[1], y[2]);
265 accum.mul(x[2], y[1]);
266 accum.mul(x[3], y[0]);
267 z[3] = accum.extract();
268 accum.mul(x[0], y[4]);
269 accum.mul(x[1], y[3]);
270 accum.mul(x[2], y[2]);
271 accum.mul(x[3], y[1]);
272 accum.mul(x[4], y[0]);
273 z[4] = accum.extract();
274 accum.mul(x[0], y[5]);
275 accum.mul(x[1], y[4]);
276 accum.mul(x[2], y[3]);
277 accum.mul(x[3], y[2]);
278 accum.mul(x[4], y[1]);
279 accum.mul(x[5], y[0]);
280 z[5] = accum.extract();
281 accum.mul(x[0], y[6]);
282 accum.mul(x[1], y[5]);
283 accum.mul(x[2], y[4]);
284 accum.mul(x[3], y[3]);
285 accum.mul(x[4], y[2]);
286 accum.mul(x[5], y[1]);
287 accum.mul(x[6], y[0]);
288 z[6] = accum.extract();
289 accum.mul(x[1], y[6]);
290 accum.mul(x[2], y[5]);
291 accum.mul(x[3], y[4]);
292 accum.mul(x[4], y[3]);
293 accum.mul(x[5], y[2]);
294 accum.mul(x[6], y[1]);
295 z[7] = accum.extract();
296 accum.mul(x[2], y[6]);
297 accum.mul(x[3], y[5]);
298 accum.mul(x[4], y[4]);
299 accum.mul(x[5], y[3]);
300 accum.mul(x[6], y[2]);
301 z[8] = accum.extract();
302 accum.mul(x[3], y[6]);
303 accum.mul(x[4], y[5]);
304 accum.mul(x[5], y[4]);
305 accum.mul(x[6], y[3]);
306 z[9] = accum.extract();
307 accum.mul(x[4], y[6]);
308 accum.mul(x[5], y[5]);
309 accum.mul(x[6], y[4]);
310 z[10] = accum.extract();
311 accum.mul(x[5], y[6]);
312 accum.mul(x[6], y[5]);
313 z[11] = accum.extract();
314 accum.mul(x[6], y[6]);
315 z[12] = accum.extract();
316 z[13] = accum.extract();
317}

References Botan::word3< W >::extract(), and Botan::word3< W >::mul().

Referenced by comba_mul().

◆ bigint_comba_mul8()

BOTAN_FUZZER_API void Botan::bigint_comba_mul8 ( word z[16],
const word x[8],
const word y[8] )

Definition at line 388 of file mp_comba.cpp.

388 {
389#if defined(BOTAN_HAS_MP_MULX)
391 return bigint_mulx_mul8(z, x, y);
392 }
393#endif
394
395 word3<word> accum;
396
397 accum.mul(x[0], y[0]);
398 z[0] = accum.extract();
399 accum.mul(x[0], y[1]);
400 accum.mul(x[1], y[0]);
401 z[1] = accum.extract();
402 accum.mul(x[0], y[2]);
403 accum.mul(x[1], y[1]);
404 accum.mul(x[2], y[0]);
405 z[2] = accum.extract();
406 accum.mul(x[0], y[3]);
407 accum.mul(x[1], y[2]);
408 accum.mul(x[2], y[1]);
409 accum.mul(x[3], y[0]);
410 z[3] = accum.extract();
411 accum.mul(x[0], y[4]);
412 accum.mul(x[1], y[3]);
413 accum.mul(x[2], y[2]);
414 accum.mul(x[3], y[1]);
415 accum.mul(x[4], y[0]);
416 z[4] = accum.extract();
417 accum.mul(x[0], y[5]);
418 accum.mul(x[1], y[4]);
419 accum.mul(x[2], y[3]);
420 accum.mul(x[3], y[2]);
421 accum.mul(x[4], y[1]);
422 accum.mul(x[5], y[0]);
423 z[5] = accum.extract();
424 accum.mul(x[0], y[6]);
425 accum.mul(x[1], y[5]);
426 accum.mul(x[2], y[4]);
427 accum.mul(x[3], y[3]);
428 accum.mul(x[4], y[2]);
429 accum.mul(x[5], y[1]);
430 accum.mul(x[6], y[0]);
431 z[6] = accum.extract();
432 accum.mul(x[0], y[7]);
433 accum.mul(x[1], y[6]);
434 accum.mul(x[2], y[5]);
435 accum.mul(x[3], y[4]);
436 accum.mul(x[4], y[3]);
437 accum.mul(x[5], y[2]);
438 accum.mul(x[6], y[1]);
439 accum.mul(x[7], y[0]);
440 z[7] = accum.extract();
441 accum.mul(x[1], y[7]);
442 accum.mul(x[2], y[6]);
443 accum.mul(x[3], y[5]);
444 accum.mul(x[4], y[4]);
445 accum.mul(x[5], y[3]);
446 accum.mul(x[6], y[2]);
447 accum.mul(x[7], y[1]);
448 z[8] = accum.extract();
449 accum.mul(x[2], y[7]);
450 accum.mul(x[3], y[6]);
451 accum.mul(x[4], y[5]);
452 accum.mul(x[5], y[4]);
453 accum.mul(x[6], y[3]);
454 accum.mul(x[7], y[2]);
455 z[9] = accum.extract();
456 accum.mul(x[3], y[7]);
457 accum.mul(x[4], y[6]);
458 accum.mul(x[5], y[5]);
459 accum.mul(x[6], y[4]);
460 accum.mul(x[7], y[3]);
461 z[10] = accum.extract();
462 accum.mul(x[4], y[7]);
463 accum.mul(x[5], y[6]);
464 accum.mul(x[6], y[5]);
465 accum.mul(x[7], y[4]);
466 z[11] = accum.extract();
467 accum.mul(x[5], y[7]);
468 accum.mul(x[6], y[6]);
469 accum.mul(x[7], y[5]);
470 z[12] = accum.extract();
471 accum.mul(x[6], y[7]);
472 accum.mul(x[7], y[6]);
473 z[13] = accum.extract();
474 accum.mul(x[7], y[7]);
475 z[14] = accum.extract();
476 z[15] = accum.extract();
477}
void bigint_mulx_mul8(word z[16], const word x[8], const word y[8])
Definition mp_mulx.cpp:772

References Botan::CPUFeature::ADX, bigint_mulx_mul8(), Botan::CPUFeature::BMI, Botan::word3< W >::extract(), Botan::CPUID::has(), and Botan::word3< W >::mul().

Referenced by bigint_mul(), and comba_mul().

◆ bigint_comba_mul9()

BOTAN_FUZZER_API void Botan::bigint_comba_mul9 ( word z[18],
const word x[9],
const word y[9] )

Definition at line 559 of file mp_comba.cpp.

559 {
560#if defined(BOTAN_HAS_MP_MULX)
562 return bigint_mulx_mul9(z, x, y);
563 }
564#endif
565
566 word3<word> accum;
567
568 accum.mul(x[0], y[0]);
569 z[0] = accum.extract();
570 accum.mul(x[0], y[1]);
571 accum.mul(x[1], y[0]);
572 z[1] = accum.extract();
573 accum.mul(x[0], y[2]);
574 accum.mul(x[1], y[1]);
575 accum.mul(x[2], y[0]);
576 z[2] = accum.extract();
577 accum.mul(x[0], y[3]);
578 accum.mul(x[1], y[2]);
579 accum.mul(x[2], y[1]);
580 accum.mul(x[3], y[0]);
581 z[3] = accum.extract();
582 accum.mul(x[0], y[4]);
583 accum.mul(x[1], y[3]);
584 accum.mul(x[2], y[2]);
585 accum.mul(x[3], y[1]);
586 accum.mul(x[4], y[0]);
587 z[4] = accum.extract();
588 accum.mul(x[0], y[5]);
589 accum.mul(x[1], y[4]);
590 accum.mul(x[2], y[3]);
591 accum.mul(x[3], y[2]);
592 accum.mul(x[4], y[1]);
593 accum.mul(x[5], y[0]);
594 z[5] = accum.extract();
595 accum.mul(x[0], y[6]);
596 accum.mul(x[1], y[5]);
597 accum.mul(x[2], y[4]);
598 accum.mul(x[3], y[3]);
599 accum.mul(x[4], y[2]);
600 accum.mul(x[5], y[1]);
601 accum.mul(x[6], y[0]);
602 z[6] = accum.extract();
603 accum.mul(x[0], y[7]);
604 accum.mul(x[1], y[6]);
605 accum.mul(x[2], y[5]);
606 accum.mul(x[3], y[4]);
607 accum.mul(x[4], y[3]);
608 accum.mul(x[5], y[2]);
609 accum.mul(x[6], y[1]);
610 accum.mul(x[7], y[0]);
611 z[7] = accum.extract();
612 accum.mul(x[0], y[8]);
613 accum.mul(x[1], y[7]);
614 accum.mul(x[2], y[6]);
615 accum.mul(x[3], y[5]);
616 accum.mul(x[4], y[4]);
617 accum.mul(x[5], y[3]);
618 accum.mul(x[6], y[2]);
619 accum.mul(x[7], y[1]);
620 accum.mul(x[8], y[0]);
621 z[8] = accum.extract();
622 accum.mul(x[1], y[8]);
623 accum.mul(x[2], y[7]);
624 accum.mul(x[3], y[6]);
625 accum.mul(x[4], y[5]);
626 accum.mul(x[5], y[4]);
627 accum.mul(x[6], y[3]);
628 accum.mul(x[7], y[2]);
629 accum.mul(x[8], y[1]);
630 z[9] = accum.extract();
631 accum.mul(x[2], y[8]);
632 accum.mul(x[3], y[7]);
633 accum.mul(x[4], y[6]);
634 accum.mul(x[5], y[5]);
635 accum.mul(x[6], y[4]);
636 accum.mul(x[7], y[3]);
637 accum.mul(x[8], y[2]);
638 z[10] = accum.extract();
639 accum.mul(x[3], y[8]);
640 accum.mul(x[4], y[7]);
641 accum.mul(x[5], y[6]);
642 accum.mul(x[6], y[5]);
643 accum.mul(x[7], y[4]);
644 accum.mul(x[8], y[3]);
645 z[11] = accum.extract();
646 accum.mul(x[4], y[8]);
647 accum.mul(x[5], y[7]);
648 accum.mul(x[6], y[6]);
649 accum.mul(x[7], y[5]);
650 accum.mul(x[8], y[4]);
651 z[12] = accum.extract();
652 accum.mul(x[5], y[8]);
653 accum.mul(x[6], y[7]);
654 accum.mul(x[7], y[6]);
655 accum.mul(x[8], y[5]);
656 z[13] = accum.extract();
657 accum.mul(x[6], y[8]);
658 accum.mul(x[7], y[7]);
659 accum.mul(x[8], y[6]);
660 z[14] = accum.extract();
661 accum.mul(x[7], y[8]);
662 accum.mul(x[8], y[7]);
663 z[15] = accum.extract();
664 accum.mul(x[8], y[8]);
665 z[16] = accum.extract();
666 z[17] = accum.extract();
667}
void bigint_mulx_mul9(word z[18], const word x[9], const word y[9])
Definition mp_mulx.cpp:1315

References Botan::CPUFeature::ADX, bigint_mulx_mul9(), Botan::CPUFeature::BMI, Botan::word3< W >::extract(), Botan::CPUID::has(), and Botan::word3< W >::mul().

Referenced by bigint_mul(), and comba_mul().

◆ bigint_comba_sqr16()

BOTAN_FUZZER_API void Botan::bigint_comba_sqr16 ( word z[32],
const word x[16] )

Definition at line 672 of file mp_comba.cpp.

672 {
673 word3<word> accum;
674
675 accum.mul(x[0], x[0]);
676 z[0] = accum.extract();
677 accum.mul_x2(x[0], x[1]);
678 z[1] = accum.extract();
679 accum.mul_x2(x[0], x[2]);
680 accum.mul(x[1], x[1]);
681 z[2] = accum.extract();
682 accum.mul_x2(x[0], x[3]);
683 accum.mul_x2(x[1], x[2]);
684 z[3] = accum.extract();
685 accum.mul_x2(x[0], x[4]);
686 accum.mul_x2(x[1], x[3]);
687 accum.mul(x[2], x[2]);
688 z[4] = accum.extract();
689 accum.mul_x2(x[0], x[5]);
690 accum.mul_x2(x[1], x[4]);
691 accum.mul_x2(x[2], x[3]);
692 z[5] = accum.extract();
693 accum.mul_x2(x[0], x[6]);
694 accum.mul_x2(x[1], x[5]);
695 accum.mul_x2(x[2], x[4]);
696 accum.mul(x[3], x[3]);
697 z[6] = accum.extract();
698 accum.mul_x2(x[0], x[7]);
699 accum.mul_x2(x[1], x[6]);
700 accum.mul_x2(x[2], x[5]);
701 accum.mul_x2(x[3], x[4]);
702 z[7] = accum.extract();
703 accum.mul_x2(x[0], x[8]);
704 accum.mul_x2(x[1], x[7]);
705 accum.mul_x2(x[2], x[6]);
706 accum.mul_x2(x[3], x[5]);
707 accum.mul(x[4], x[4]);
708 z[8] = accum.extract();
709 accum.mul_x2(x[0], x[9]);
710 accum.mul_x2(x[1], x[8]);
711 accum.mul_x2(x[2], x[7]);
712 accum.mul_x2(x[3], x[6]);
713 accum.mul_x2(x[4], x[5]);
714 z[9] = accum.extract();
715 accum.mul_x2(x[0], x[10]);
716 accum.mul_x2(x[1], x[9]);
717 accum.mul_x2(x[2], x[8]);
718 accum.mul_x2(x[3], x[7]);
719 accum.mul_x2(x[4], x[6]);
720 accum.mul(x[5], x[5]);
721 z[10] = accum.extract();
722 accum.mul_x2(x[0], x[11]);
723 accum.mul_x2(x[1], x[10]);
724 accum.mul_x2(x[2], x[9]);
725 accum.mul_x2(x[3], x[8]);
726 accum.mul_x2(x[4], x[7]);
727 accum.mul_x2(x[5], x[6]);
728 z[11] = accum.extract();
729 accum.mul_x2(x[0], x[12]);
730 accum.mul_x2(x[1], x[11]);
731 accum.mul_x2(x[2], x[10]);
732 accum.mul_x2(x[3], x[9]);
733 accum.mul_x2(x[4], x[8]);
734 accum.mul_x2(x[5], x[7]);
735 accum.mul(x[6], x[6]);
736 z[12] = accum.extract();
737 accum.mul_x2(x[0], x[13]);
738 accum.mul_x2(x[1], x[12]);
739 accum.mul_x2(x[2], x[11]);
740 accum.mul_x2(x[3], x[10]);
741 accum.mul_x2(x[4], x[9]);
742 accum.mul_x2(x[5], x[8]);
743 accum.mul_x2(x[6], x[7]);
744 z[13] = accum.extract();
745 accum.mul_x2(x[0], x[14]);
746 accum.mul_x2(x[1], x[13]);
747 accum.mul_x2(x[2], x[12]);
748 accum.mul_x2(x[3], x[11]);
749 accum.mul_x2(x[4], x[10]);
750 accum.mul_x2(x[5], x[9]);
751 accum.mul_x2(x[6], x[8]);
752 accum.mul(x[7], x[7]);
753 z[14] = accum.extract();
754 accum.mul_x2(x[0], x[15]);
755 accum.mul_x2(x[1], x[14]);
756 accum.mul_x2(x[2], x[13]);
757 accum.mul_x2(x[3], x[12]);
758 accum.mul_x2(x[4], x[11]);
759 accum.mul_x2(x[5], x[10]);
760 accum.mul_x2(x[6], x[9]);
761 accum.mul_x2(x[7], x[8]);
762 z[15] = accum.extract();
763 accum.mul_x2(x[1], x[15]);
764 accum.mul_x2(x[2], x[14]);
765 accum.mul_x2(x[3], x[13]);
766 accum.mul_x2(x[4], x[12]);
767 accum.mul_x2(x[5], x[11]);
768 accum.mul_x2(x[6], x[10]);
769 accum.mul_x2(x[7], x[9]);
770 accum.mul(x[8], x[8]);
771 z[16] = accum.extract();
772 accum.mul_x2(x[2], x[15]);
773 accum.mul_x2(x[3], x[14]);
774 accum.mul_x2(x[4], x[13]);
775 accum.mul_x2(x[5], x[12]);
776 accum.mul_x2(x[6], x[11]);
777 accum.mul_x2(x[7], x[10]);
778 accum.mul_x2(x[8], x[9]);
779 z[17] = accum.extract();
780 accum.mul_x2(x[3], x[15]);
781 accum.mul_x2(x[4], x[14]);
782 accum.mul_x2(x[5], x[13]);
783 accum.mul_x2(x[6], x[12]);
784 accum.mul_x2(x[7], x[11]);
785 accum.mul_x2(x[8], x[10]);
786 accum.mul(x[9], x[9]);
787 z[18] = accum.extract();
788 accum.mul_x2(x[4], x[15]);
789 accum.mul_x2(x[5], x[14]);
790 accum.mul_x2(x[6], x[13]);
791 accum.mul_x2(x[7], x[12]);
792 accum.mul_x2(x[8], x[11]);
793 accum.mul_x2(x[9], x[10]);
794 z[19] = accum.extract();
795 accum.mul_x2(x[5], x[15]);
796 accum.mul_x2(x[6], x[14]);
797 accum.mul_x2(x[7], x[13]);
798 accum.mul_x2(x[8], x[12]);
799 accum.mul_x2(x[9], x[11]);
800 accum.mul(x[10], x[10]);
801 z[20] = accum.extract();
802 accum.mul_x2(x[6], x[15]);
803 accum.mul_x2(x[7], x[14]);
804 accum.mul_x2(x[8], x[13]);
805 accum.mul_x2(x[9], x[12]);
806 accum.mul_x2(x[10], x[11]);
807 z[21] = accum.extract();
808 accum.mul_x2(x[7], x[15]);
809 accum.mul_x2(x[8], x[14]);
810 accum.mul_x2(x[9], x[13]);
811 accum.mul_x2(x[10], x[12]);
812 accum.mul(x[11], x[11]);
813 z[22] = accum.extract();
814 accum.mul_x2(x[8], x[15]);
815 accum.mul_x2(x[9], x[14]);
816 accum.mul_x2(x[10], x[13]);
817 accum.mul_x2(x[11], x[12]);
818 z[23] = accum.extract();
819 accum.mul_x2(x[9], x[15]);
820 accum.mul_x2(x[10], x[14]);
821 accum.mul_x2(x[11], x[13]);
822 accum.mul(x[12], x[12]);
823 z[24] = accum.extract();
824 accum.mul_x2(x[10], x[15]);
825 accum.mul_x2(x[11], x[14]);
826 accum.mul_x2(x[12], x[13]);
827 z[25] = accum.extract();
828 accum.mul_x2(x[11], x[15]);
829 accum.mul_x2(x[12], x[14]);
830 accum.mul(x[13], x[13]);
831 z[26] = accum.extract();
832 accum.mul_x2(x[12], x[15]);
833 accum.mul_x2(x[13], x[14]);
834 z[27] = accum.extract();
835 accum.mul_x2(x[13], x[15]);
836 accum.mul(x[14], x[14]);
837 z[28] = accum.extract();
838 accum.mul_x2(x[14], x[15]);
839 z[29] = accum.extract();
840 accum.mul(x[15], x[15]);
841 z[30] = accum.extract();
842 z[31] = accum.extract();
843}
constexpr void mul_x2(W x, W y)
Definition mp_asmi.h:593

References Botan::word3< W >::extract(), Botan::word3< W >::mul(), and Botan::word3< W >::mul_x2().

Referenced by bigint_sqr(), and comba_sqr().

◆ bigint_comba_sqr24()

BOTAN_FUZZER_API void Botan::bigint_comba_sqr24 ( word z[48],
const word x[24] )

Definition at line 1144 of file mp_comba.cpp.

1144 {
1145 word3<word> accum;
1146
1147 accum.mul(x[0], x[0]);
1148 z[0] = accum.extract();
1149 accum.mul_x2(x[0], x[1]);
1150 z[1] = accum.extract();
1151 accum.mul_x2(x[0], x[2]);
1152 accum.mul(x[1], x[1]);
1153 z[2] = accum.extract();
1154 accum.mul_x2(x[0], x[3]);
1155 accum.mul_x2(x[1], x[2]);
1156 z[3] = accum.extract();
1157 accum.mul_x2(x[0], x[4]);
1158 accum.mul_x2(x[1], x[3]);
1159 accum.mul(x[2], x[2]);
1160 z[4] = accum.extract();
1161 accum.mul_x2(x[0], x[5]);
1162 accum.mul_x2(x[1], x[4]);
1163 accum.mul_x2(x[2], x[3]);
1164 z[5] = accum.extract();
1165 accum.mul_x2(x[0], x[6]);
1166 accum.mul_x2(x[1], x[5]);
1167 accum.mul_x2(x[2], x[4]);
1168 accum.mul(x[3], x[3]);
1169 z[6] = accum.extract();
1170 accum.mul_x2(x[0], x[7]);
1171 accum.mul_x2(x[1], x[6]);
1172 accum.mul_x2(x[2], x[5]);
1173 accum.mul_x2(x[3], x[4]);
1174 z[7] = accum.extract();
1175 accum.mul_x2(x[0], x[8]);
1176 accum.mul_x2(x[1], x[7]);
1177 accum.mul_x2(x[2], x[6]);
1178 accum.mul_x2(x[3], x[5]);
1179 accum.mul(x[4], x[4]);
1180 z[8] = accum.extract();
1181 accum.mul_x2(x[0], x[9]);
1182 accum.mul_x2(x[1], x[8]);
1183 accum.mul_x2(x[2], x[7]);
1184 accum.mul_x2(x[3], x[6]);
1185 accum.mul_x2(x[4], x[5]);
1186 z[9] = accum.extract();
1187 accum.mul_x2(x[0], x[10]);
1188 accum.mul_x2(x[1], x[9]);
1189 accum.mul_x2(x[2], x[8]);
1190 accum.mul_x2(x[3], x[7]);
1191 accum.mul_x2(x[4], x[6]);
1192 accum.mul(x[5], x[5]);
1193 z[10] = accum.extract();
1194 accum.mul_x2(x[0], x[11]);
1195 accum.mul_x2(x[1], x[10]);
1196 accum.mul_x2(x[2], x[9]);
1197 accum.mul_x2(x[3], x[8]);
1198 accum.mul_x2(x[4], x[7]);
1199 accum.mul_x2(x[5], x[6]);
1200 z[11] = accum.extract();
1201 accum.mul_x2(x[0], x[12]);
1202 accum.mul_x2(x[1], x[11]);
1203 accum.mul_x2(x[2], x[10]);
1204 accum.mul_x2(x[3], x[9]);
1205 accum.mul_x2(x[4], x[8]);
1206 accum.mul_x2(x[5], x[7]);
1207 accum.mul(x[6], x[6]);
1208 z[12] = accum.extract();
1209 accum.mul_x2(x[0], x[13]);
1210 accum.mul_x2(x[1], x[12]);
1211 accum.mul_x2(x[2], x[11]);
1212 accum.mul_x2(x[3], x[10]);
1213 accum.mul_x2(x[4], x[9]);
1214 accum.mul_x2(x[5], x[8]);
1215 accum.mul_x2(x[6], x[7]);
1216 z[13] = accum.extract();
1217 accum.mul_x2(x[0], x[14]);
1218 accum.mul_x2(x[1], x[13]);
1219 accum.mul_x2(x[2], x[12]);
1220 accum.mul_x2(x[3], x[11]);
1221 accum.mul_x2(x[4], x[10]);
1222 accum.mul_x2(x[5], x[9]);
1223 accum.mul_x2(x[6], x[8]);
1224 accum.mul(x[7], x[7]);
1225 z[14] = accum.extract();
1226 accum.mul_x2(x[0], x[15]);
1227 accum.mul_x2(x[1], x[14]);
1228 accum.mul_x2(x[2], x[13]);
1229 accum.mul_x2(x[3], x[12]);
1230 accum.mul_x2(x[4], x[11]);
1231 accum.mul_x2(x[5], x[10]);
1232 accum.mul_x2(x[6], x[9]);
1233 accum.mul_x2(x[7], x[8]);
1234 z[15] = accum.extract();
1235 accum.mul_x2(x[0], x[16]);
1236 accum.mul_x2(x[1], x[15]);
1237 accum.mul_x2(x[2], x[14]);
1238 accum.mul_x2(x[3], x[13]);
1239 accum.mul_x2(x[4], x[12]);
1240 accum.mul_x2(x[5], x[11]);
1241 accum.mul_x2(x[6], x[10]);
1242 accum.mul_x2(x[7], x[9]);
1243 accum.mul(x[8], x[8]);
1244 z[16] = accum.extract();
1245 accum.mul_x2(x[0], x[17]);
1246 accum.mul_x2(x[1], x[16]);
1247 accum.mul_x2(x[2], x[15]);
1248 accum.mul_x2(x[3], x[14]);
1249 accum.mul_x2(x[4], x[13]);
1250 accum.mul_x2(x[5], x[12]);
1251 accum.mul_x2(x[6], x[11]);
1252 accum.mul_x2(x[7], x[10]);
1253 accum.mul_x2(x[8], x[9]);
1254 z[17] = accum.extract();
1255 accum.mul_x2(x[0], x[18]);
1256 accum.mul_x2(x[1], x[17]);
1257 accum.mul_x2(x[2], x[16]);
1258 accum.mul_x2(x[3], x[15]);
1259 accum.mul_x2(x[4], x[14]);
1260 accum.mul_x2(x[5], x[13]);
1261 accum.mul_x2(x[6], x[12]);
1262 accum.mul_x2(x[7], x[11]);
1263 accum.mul_x2(x[8], x[10]);
1264 accum.mul(x[9], x[9]);
1265 z[18] = accum.extract();
1266 accum.mul_x2(x[0], x[19]);
1267 accum.mul_x2(x[1], x[18]);
1268 accum.mul_x2(x[2], x[17]);
1269 accum.mul_x2(x[3], x[16]);
1270 accum.mul_x2(x[4], x[15]);
1271 accum.mul_x2(x[5], x[14]);
1272 accum.mul_x2(x[6], x[13]);
1273 accum.mul_x2(x[7], x[12]);
1274 accum.mul_x2(x[8], x[11]);
1275 accum.mul_x2(x[9], x[10]);
1276 z[19] = accum.extract();
1277 accum.mul_x2(x[0], x[20]);
1278 accum.mul_x2(x[1], x[19]);
1279 accum.mul_x2(x[2], x[18]);
1280 accum.mul_x2(x[3], x[17]);
1281 accum.mul_x2(x[4], x[16]);
1282 accum.mul_x2(x[5], x[15]);
1283 accum.mul_x2(x[6], x[14]);
1284 accum.mul_x2(x[7], x[13]);
1285 accum.mul_x2(x[8], x[12]);
1286 accum.mul_x2(x[9], x[11]);
1287 accum.mul(x[10], x[10]);
1288 z[20] = accum.extract();
1289 accum.mul_x2(x[0], x[21]);
1290 accum.mul_x2(x[1], x[20]);
1291 accum.mul_x2(x[2], x[19]);
1292 accum.mul_x2(x[3], x[18]);
1293 accum.mul_x2(x[4], x[17]);
1294 accum.mul_x2(x[5], x[16]);
1295 accum.mul_x2(x[6], x[15]);
1296 accum.mul_x2(x[7], x[14]);
1297 accum.mul_x2(x[8], x[13]);
1298 accum.mul_x2(x[9], x[12]);
1299 accum.mul_x2(x[10], x[11]);
1300 z[21] = accum.extract();
1301 accum.mul_x2(x[0], x[22]);
1302 accum.mul_x2(x[1], x[21]);
1303 accum.mul_x2(x[2], x[20]);
1304 accum.mul_x2(x[3], x[19]);
1305 accum.mul_x2(x[4], x[18]);
1306 accum.mul_x2(x[5], x[17]);
1307 accum.mul_x2(x[6], x[16]);
1308 accum.mul_x2(x[7], x[15]);
1309 accum.mul_x2(x[8], x[14]);
1310 accum.mul_x2(x[9], x[13]);
1311 accum.mul_x2(x[10], x[12]);
1312 accum.mul(x[11], x[11]);
1313 z[22] = accum.extract();
1314 accum.mul_x2(x[0], x[23]);
1315 accum.mul_x2(x[1], x[22]);
1316 accum.mul_x2(x[2], x[21]);
1317 accum.mul_x2(x[3], x[20]);
1318 accum.mul_x2(x[4], x[19]);
1319 accum.mul_x2(x[5], x[18]);
1320 accum.mul_x2(x[6], x[17]);
1321 accum.mul_x2(x[7], x[16]);
1322 accum.mul_x2(x[8], x[15]);
1323 accum.mul_x2(x[9], x[14]);
1324 accum.mul_x2(x[10], x[13]);
1325 accum.mul_x2(x[11], x[12]);
1326 z[23] = accum.extract();
1327 accum.mul_x2(x[1], x[23]);
1328 accum.mul_x2(x[2], x[22]);
1329 accum.mul_x2(x[3], x[21]);
1330 accum.mul_x2(x[4], x[20]);
1331 accum.mul_x2(x[5], x[19]);
1332 accum.mul_x2(x[6], x[18]);
1333 accum.mul_x2(x[7], x[17]);
1334 accum.mul_x2(x[8], x[16]);
1335 accum.mul_x2(x[9], x[15]);
1336 accum.mul_x2(x[10], x[14]);
1337 accum.mul_x2(x[11], x[13]);
1338 accum.mul(x[12], x[12]);
1339 z[24] = accum.extract();
1340 accum.mul_x2(x[2], x[23]);
1341 accum.mul_x2(x[3], x[22]);
1342 accum.mul_x2(x[4], x[21]);
1343 accum.mul_x2(x[5], x[20]);
1344 accum.mul_x2(x[6], x[19]);
1345 accum.mul_x2(x[7], x[18]);
1346 accum.mul_x2(x[8], x[17]);
1347 accum.mul_x2(x[9], x[16]);
1348 accum.mul_x2(x[10], x[15]);
1349 accum.mul_x2(x[11], x[14]);
1350 accum.mul_x2(x[12], x[13]);
1351 z[25] = accum.extract();
1352 accum.mul_x2(x[3], x[23]);
1353 accum.mul_x2(x[4], x[22]);
1354 accum.mul_x2(x[5], x[21]);
1355 accum.mul_x2(x[6], x[20]);
1356 accum.mul_x2(x[7], x[19]);
1357 accum.mul_x2(x[8], x[18]);
1358 accum.mul_x2(x[9], x[17]);
1359 accum.mul_x2(x[10], x[16]);
1360 accum.mul_x2(x[11], x[15]);
1361 accum.mul_x2(x[12], x[14]);
1362 accum.mul(x[13], x[13]);
1363 z[26] = accum.extract();
1364 accum.mul_x2(x[4], x[23]);
1365 accum.mul_x2(x[5], x[22]);
1366 accum.mul_x2(x[6], x[21]);
1367 accum.mul_x2(x[7], x[20]);
1368 accum.mul_x2(x[8], x[19]);
1369 accum.mul_x2(x[9], x[18]);
1370 accum.mul_x2(x[10], x[17]);
1371 accum.mul_x2(x[11], x[16]);
1372 accum.mul_x2(x[12], x[15]);
1373 accum.mul_x2(x[13], x[14]);
1374 z[27] = accum.extract();
1375 accum.mul_x2(x[5], x[23]);
1376 accum.mul_x2(x[6], x[22]);
1377 accum.mul_x2(x[7], x[21]);
1378 accum.mul_x2(x[8], x[20]);
1379 accum.mul_x2(x[9], x[19]);
1380 accum.mul_x2(x[10], x[18]);
1381 accum.mul_x2(x[11], x[17]);
1382 accum.mul_x2(x[12], x[16]);
1383 accum.mul_x2(x[13], x[15]);
1384 accum.mul(x[14], x[14]);
1385 z[28] = accum.extract();
1386 accum.mul_x2(x[6], x[23]);
1387 accum.mul_x2(x[7], x[22]);
1388 accum.mul_x2(x[8], x[21]);
1389 accum.mul_x2(x[9], x[20]);
1390 accum.mul_x2(x[10], x[19]);
1391 accum.mul_x2(x[11], x[18]);
1392 accum.mul_x2(x[12], x[17]);
1393 accum.mul_x2(x[13], x[16]);
1394 accum.mul_x2(x[14], x[15]);
1395 z[29] = accum.extract();
1396 accum.mul_x2(x[7], x[23]);
1397 accum.mul_x2(x[8], x[22]);
1398 accum.mul_x2(x[9], x[21]);
1399 accum.mul_x2(x[10], x[20]);
1400 accum.mul_x2(x[11], x[19]);
1401 accum.mul_x2(x[12], x[18]);
1402 accum.mul_x2(x[13], x[17]);
1403 accum.mul_x2(x[14], x[16]);
1404 accum.mul(x[15], x[15]);
1405 z[30] = accum.extract();
1406 accum.mul_x2(x[8], x[23]);
1407 accum.mul_x2(x[9], x[22]);
1408 accum.mul_x2(x[10], x[21]);
1409 accum.mul_x2(x[11], x[20]);
1410 accum.mul_x2(x[12], x[19]);
1411 accum.mul_x2(x[13], x[18]);
1412 accum.mul_x2(x[14], x[17]);
1413 accum.mul_x2(x[15], x[16]);
1414 z[31] = accum.extract();
1415 accum.mul_x2(x[9], x[23]);
1416 accum.mul_x2(x[10], x[22]);
1417 accum.mul_x2(x[11], x[21]);
1418 accum.mul_x2(x[12], x[20]);
1419 accum.mul_x2(x[13], x[19]);
1420 accum.mul_x2(x[14], x[18]);
1421 accum.mul_x2(x[15], x[17]);
1422 accum.mul(x[16], x[16]);
1423 z[32] = accum.extract();
1424 accum.mul_x2(x[10], x[23]);
1425 accum.mul_x2(x[11], x[22]);
1426 accum.mul_x2(x[12], x[21]);
1427 accum.mul_x2(x[13], x[20]);
1428 accum.mul_x2(x[14], x[19]);
1429 accum.mul_x2(x[15], x[18]);
1430 accum.mul_x2(x[16], x[17]);
1431 z[33] = accum.extract();
1432 accum.mul_x2(x[11], x[23]);
1433 accum.mul_x2(x[12], x[22]);
1434 accum.mul_x2(x[13], x[21]);
1435 accum.mul_x2(x[14], x[20]);
1436 accum.mul_x2(x[15], x[19]);
1437 accum.mul_x2(x[16], x[18]);
1438 accum.mul(x[17], x[17]);
1439 z[34] = accum.extract();
1440 accum.mul_x2(x[12], x[23]);
1441 accum.mul_x2(x[13], x[22]);
1442 accum.mul_x2(x[14], x[21]);
1443 accum.mul_x2(x[15], x[20]);
1444 accum.mul_x2(x[16], x[19]);
1445 accum.mul_x2(x[17], x[18]);
1446 z[35] = accum.extract();
1447 accum.mul_x2(x[13], x[23]);
1448 accum.mul_x2(x[14], x[22]);
1449 accum.mul_x2(x[15], x[21]);
1450 accum.mul_x2(x[16], x[20]);
1451 accum.mul_x2(x[17], x[19]);
1452 accum.mul(x[18], x[18]);
1453 z[36] = accum.extract();
1454 accum.mul_x2(x[14], x[23]);
1455 accum.mul_x2(x[15], x[22]);
1456 accum.mul_x2(x[16], x[21]);
1457 accum.mul_x2(x[17], x[20]);
1458 accum.mul_x2(x[18], x[19]);
1459 z[37] = accum.extract();
1460 accum.mul_x2(x[15], x[23]);
1461 accum.mul_x2(x[16], x[22]);
1462 accum.mul_x2(x[17], x[21]);
1463 accum.mul_x2(x[18], x[20]);
1464 accum.mul(x[19], x[19]);
1465 z[38] = accum.extract();
1466 accum.mul_x2(x[16], x[23]);
1467 accum.mul_x2(x[17], x[22]);
1468 accum.mul_x2(x[18], x[21]);
1469 accum.mul_x2(x[19], x[20]);
1470 z[39] = accum.extract();
1471 accum.mul_x2(x[17], x[23]);
1472 accum.mul_x2(x[18], x[22]);
1473 accum.mul_x2(x[19], x[21]);
1474 accum.mul(x[20], x[20]);
1475 z[40] = accum.extract();
1476 accum.mul_x2(x[18], x[23]);
1477 accum.mul_x2(x[19], x[22]);
1478 accum.mul_x2(x[20], x[21]);
1479 z[41] = accum.extract();
1480 accum.mul_x2(x[19], x[23]);
1481 accum.mul_x2(x[20], x[22]);
1482 accum.mul(x[21], x[21]);
1483 z[42] = accum.extract();
1484 accum.mul_x2(x[20], x[23]);
1485 accum.mul_x2(x[21], x[22]);
1486 z[43] = accum.extract();
1487 accum.mul_x2(x[21], x[23]);
1488 accum.mul(x[22], x[22]);
1489 z[44] = accum.extract();
1490 accum.mul_x2(x[22], x[23]);
1491 z[45] = accum.extract();
1492 accum.mul(x[23], x[23]);
1493 z[46] = accum.extract();
1494 z[47] = accum.extract();
1495}

References Botan::word3< W >::extract(), Botan::word3< W >::mul(), and Botan::word3< W >::mul_x2().

Referenced by bigint_sqr().

◆ bigint_comba_sqr4()

BOTAN_FUZZER_API void Botan::bigint_comba_sqr4 ( word z[8],
const word x[4] )

Definition at line 22 of file mp_comba.cpp.

22 {
23#if defined(BOTAN_HAS_MP_MULX)
25 return bigint_mulx_sqr4(z, x);
26 }
27#endif
28
29 word3<word> accum;
30
31 accum.mul(x[0], x[0]);
32 z[0] = accum.extract();
33 accum.mul_x2(x[0], x[1]);
34 z[1] = accum.extract();
35 accum.mul_x2(x[0], x[2]);
36 accum.mul(x[1], x[1]);
37 z[2] = accum.extract();
38 accum.mul_x2(x[0], x[3]);
39 accum.mul_x2(x[1], x[2]);
40 z[3] = accum.extract();
41 accum.mul_x2(x[1], x[3]);
42 accum.mul(x[2], x[2]);
43 z[4] = accum.extract();
44 accum.mul_x2(x[2], x[3]);
45 z[5] = accum.extract();
46 accum.mul(x[3], x[3]);
47 z[6] = accum.extract();
48 z[7] = accum.extract();
49}
void bigint_mulx_sqr4(word z[8], const word x[4])
Definition mp_mulx.cpp:28

References Botan::CPUFeature::ADX, bigint_mulx_sqr4(), Botan::CPUFeature::BMI, Botan::word3< W >::extract(), Botan::CPUID::has(), Botan::word3< W >::mul(), and Botan::word3< W >::mul_x2().

Referenced by bigint_sqr(), and comba_sqr().

◆ bigint_comba_sqr6()

BOTAN_FUZZER_API void Botan::bigint_comba_sqr6 ( word z[12],
const word x[6] )

Definition at line 92 of file mp_comba.cpp.

92 {
93#if defined(BOTAN_HAS_MP_MULX)
95 return bigint_mulx_sqr6(z, x);
96 }
97#endif
98
99 word3<word> accum;
100
101 accum.mul(x[0], x[0]);
102 z[0] = accum.extract();
103 accum.mul_x2(x[0], x[1]);
104 z[1] = accum.extract();
105 accum.mul_x2(x[0], x[2]);
106 accum.mul(x[1], x[1]);
107 z[2] = accum.extract();
108 accum.mul_x2(x[0], x[3]);
109 accum.mul_x2(x[1], x[2]);
110 z[3] = accum.extract();
111 accum.mul_x2(x[0], x[4]);
112 accum.mul_x2(x[1], x[3]);
113 accum.mul(x[2], x[2]);
114 z[4] = accum.extract();
115 accum.mul_x2(x[0], x[5]);
116 accum.mul_x2(x[1], x[4]);
117 accum.mul_x2(x[2], x[3]);
118 z[5] = accum.extract();
119 accum.mul_x2(x[1], x[5]);
120 accum.mul_x2(x[2], x[4]);
121 accum.mul(x[3], x[3]);
122 z[6] = accum.extract();
123 accum.mul_x2(x[2], x[5]);
124 accum.mul_x2(x[3], x[4]);
125 z[7] = accum.extract();
126 accum.mul_x2(x[3], x[5]);
127 accum.mul(x[4], x[4]);
128 z[8] = accum.extract();
129 accum.mul_x2(x[4], x[5]);
130 z[9] = accum.extract();
131 accum.mul(x[5], x[5]);
132 z[10] = accum.extract();
133 z[11] = accum.extract();
134}
void bigint_mulx_sqr6(word z[12], const word x[6])
Definition mp_mulx.cpp:213

References Botan::CPUFeature::ADX, bigint_mulx_sqr6(), Botan::CPUFeature::BMI, Botan::word3< W >::extract(), Botan::CPUID::has(), Botan::word3< W >::mul(), and Botan::word3< W >::mul_x2().

Referenced by bigint_sqr(), and comba_sqr().

◆ bigint_comba_sqr7()

BOTAN_FUZZER_API void Botan::bigint_comba_sqr7 ( word z[14],
const word x[7] )

Definition at line 201 of file mp_comba.cpp.

201 {
202 word3<word> accum;
203
204 accum.mul(x[0], x[0]);
205 z[0] = accum.extract();
206 accum.mul_x2(x[0], x[1]);
207 z[1] = accum.extract();
208 accum.mul_x2(x[0], x[2]);
209 accum.mul(x[1], x[1]);
210 z[2] = accum.extract();
211 accum.mul_x2(x[0], x[3]);
212 accum.mul_x2(x[1], x[2]);
213 z[3] = accum.extract();
214 accum.mul_x2(x[0], x[4]);
215 accum.mul_x2(x[1], x[3]);
216 accum.mul(x[2], x[2]);
217 z[4] = accum.extract();
218 accum.mul_x2(x[0], x[5]);
219 accum.mul_x2(x[1], x[4]);
220 accum.mul_x2(x[2], x[3]);
221 z[5] = accum.extract();
222 accum.mul_x2(x[0], x[6]);
223 accum.mul_x2(x[1], x[5]);
224 accum.mul_x2(x[2], x[4]);
225 accum.mul(x[3], x[3]);
226 z[6] = accum.extract();
227 accum.mul_x2(x[1], x[6]);
228 accum.mul_x2(x[2], x[5]);
229 accum.mul_x2(x[3], x[4]);
230 z[7] = accum.extract();
231 accum.mul_x2(x[2], x[6]);
232 accum.mul_x2(x[3], x[5]);
233 accum.mul(x[4], x[4]);
234 z[8] = accum.extract();
235 accum.mul_x2(x[3], x[6]);
236 accum.mul_x2(x[4], x[5]);
237 z[9] = accum.extract();
238 accum.mul_x2(x[4], x[6]);
239 accum.mul(x[5], x[5]);
240 z[10] = accum.extract();
241 accum.mul_x2(x[5], x[6]);
242 z[11] = accum.extract();
243 accum.mul(x[6], x[6]);
244 z[12] = accum.extract();
245 z[13] = accum.extract();
246}

References Botan::word3< W >::extract(), Botan::word3< W >::mul(), and Botan::word3< W >::mul_x2().

Referenced by comba_sqr().

◆ bigint_comba_sqr8()

BOTAN_FUZZER_API void Botan::bigint_comba_sqr8 ( word z[16],
const word x[8] )

Definition at line 322 of file mp_comba.cpp.

322 {
323#if defined(BOTAN_HAS_MP_MULX)
325 return bigint_mulx_sqr8(z, x);
326 }
327#endif
328
329 word3<word> accum;
330
331 accum.mul(x[0], x[0]);
332 z[0] = accum.extract();
333 accum.mul_x2(x[0], x[1]);
334 z[1] = accum.extract();
335 accum.mul_x2(x[0], x[2]);
336 accum.mul(x[1], x[1]);
337 z[2] = accum.extract();
338 accum.mul_x2(x[0], x[3]);
339 accum.mul_x2(x[1], x[2]);
340 z[3] = accum.extract();
341 accum.mul_x2(x[0], x[4]);
342 accum.mul_x2(x[1], x[3]);
343 accum.mul(x[2], x[2]);
344 z[4] = accum.extract();
345 accum.mul_x2(x[0], x[5]);
346 accum.mul_x2(x[1], x[4]);
347 accum.mul_x2(x[2], x[3]);
348 z[5] = accum.extract();
349 accum.mul_x2(x[0], x[6]);
350 accum.mul_x2(x[1], x[5]);
351 accum.mul_x2(x[2], x[4]);
352 accum.mul(x[3], x[3]);
353 z[6] = accum.extract();
354 accum.mul_x2(x[0], x[7]);
355 accum.mul_x2(x[1], x[6]);
356 accum.mul_x2(x[2], x[5]);
357 accum.mul_x2(x[3], x[4]);
358 z[7] = accum.extract();
359 accum.mul_x2(x[1], x[7]);
360 accum.mul_x2(x[2], x[6]);
361 accum.mul_x2(x[3], x[5]);
362 accum.mul(x[4], x[4]);
363 z[8] = accum.extract();
364 accum.mul_x2(x[2], x[7]);
365 accum.mul_x2(x[3], x[6]);
366 accum.mul_x2(x[4], x[5]);
367 z[9] = accum.extract();
368 accum.mul_x2(x[3], x[7]);
369 accum.mul_x2(x[4], x[6]);
370 accum.mul(x[5], x[5]);
371 z[10] = accum.extract();
372 accum.mul_x2(x[4], x[7]);
373 accum.mul_x2(x[5], x[6]);
374 z[11] = accum.extract();
375 accum.mul_x2(x[5], x[7]);
376 accum.mul(x[6], x[6]);
377 z[12] = accum.extract();
378 accum.mul_x2(x[6], x[7]);
379 z[13] = accum.extract();
380 accum.mul(x[7], x[7]);
381 z[14] = accum.extract();
382 z[15] = accum.extract();
383}
void bigint_mulx_sqr8(word z[16], const word x[8])
Definition mp_mulx.cpp:538

References Botan::CPUFeature::ADX, bigint_mulx_sqr8(), Botan::CPUFeature::BMI, Botan::word3< W >::extract(), Botan::CPUID::has(), Botan::word3< W >::mul(), and Botan::word3< W >::mul_x2().

Referenced by bigint_sqr(), and comba_sqr().

◆ bigint_comba_sqr9()

BOTAN_FUZZER_API void Botan::bigint_comba_sqr9 ( word z[18],
const word x[9] )

Definition at line 482 of file mp_comba.cpp.

482 {
483#if defined(BOTAN_HAS_MP_MULX)
485 return bigint_mulx_sqr9(z, x);
486 }
487#endif
488
489 word3<word> accum;
490
491 accum.mul(x[0], x[0]);
492 z[0] = accum.extract();
493 accum.mul_x2(x[0], x[1]);
494 z[1] = accum.extract();
495 accum.mul_x2(x[0], x[2]);
496 accum.mul(x[1], x[1]);
497 z[2] = accum.extract();
498 accum.mul_x2(x[0], x[3]);
499 accum.mul_x2(x[1], x[2]);
500 z[3] = accum.extract();
501 accum.mul_x2(x[0], x[4]);
502 accum.mul_x2(x[1], x[3]);
503 accum.mul(x[2], x[2]);
504 z[4] = accum.extract();
505 accum.mul_x2(x[0], x[5]);
506 accum.mul_x2(x[1], x[4]);
507 accum.mul_x2(x[2], x[3]);
508 z[5] = accum.extract();
509 accum.mul_x2(x[0], x[6]);
510 accum.mul_x2(x[1], x[5]);
511 accum.mul_x2(x[2], x[4]);
512 accum.mul(x[3], x[3]);
513 z[6] = accum.extract();
514 accum.mul_x2(x[0], x[7]);
515 accum.mul_x2(x[1], x[6]);
516 accum.mul_x2(x[2], x[5]);
517 accum.mul_x2(x[3], x[4]);
518 z[7] = accum.extract();
519 accum.mul_x2(x[0], x[8]);
520 accum.mul_x2(x[1], x[7]);
521 accum.mul_x2(x[2], x[6]);
522 accum.mul_x2(x[3], x[5]);
523 accum.mul(x[4], x[4]);
524 z[8] = accum.extract();
525 accum.mul_x2(x[1], x[8]);
526 accum.mul_x2(x[2], x[7]);
527 accum.mul_x2(x[3], x[6]);
528 accum.mul_x2(x[4], x[5]);
529 z[9] = accum.extract();
530 accum.mul_x2(x[2], x[8]);
531 accum.mul_x2(x[3], x[7]);
532 accum.mul_x2(x[4], x[6]);
533 accum.mul(x[5], x[5]);
534 z[10] = accum.extract();
535 accum.mul_x2(x[3], x[8]);
536 accum.mul_x2(x[4], x[7]);
537 accum.mul_x2(x[5], x[6]);
538 z[11] = accum.extract();
539 accum.mul_x2(x[4], x[8]);
540 accum.mul_x2(x[5], x[7]);
541 accum.mul(x[6], x[6]);
542 z[12] = accum.extract();
543 accum.mul_x2(x[5], x[8]);
544 accum.mul_x2(x[6], x[7]);
545 z[13] = accum.extract();
546 accum.mul_x2(x[6], x[8]);
547 accum.mul(x[7], x[7]);
548 z[14] = accum.extract();
549 accum.mul_x2(x[7], x[8]);
550 z[15] = accum.extract();
551 accum.mul(x[8], x[8]);
552 z[16] = accum.extract();
553 z[17] = accum.extract();
554}
void bigint_mulx_sqr9(word z[18], const word x[9])
Definition mp_mulx.cpp:1039

References Botan::CPUFeature::ADX, bigint_mulx_sqr9(), Botan::CPUFeature::BMI, Botan::word3< W >::extract(), Botan::CPUID::has(), Botan::word3< W >::mul(), and Botan::word3< W >::mul_x2().

Referenced by bigint_sqr(), and comba_sqr().

◆ bigint_ct_is_eq()

template<WordType W>
auto Botan::bigint_ct_is_eq ( const W x[],
size_t x_size,
const W y[],
size_t y_size ) -> CT::Mask< W >
inlineconstexpr

Definition at line 543 of file mp_core.h.

543 {
544 const size_t common_elems = std::min(x_size, y_size);
545
546 W diff = 0;
547
548 for(size_t i = 0; i != common_elems; i++) {
549 diff |= (x[i] ^ y[i]);
550 }
551
552 // If any bits were set in high part of x/y, then they are not equal
553 if(x_size < y_size) {
554 for(size_t i = x_size; i != y_size; i++) {
555 diff |= y[i];
556 }
557 } else if(y_size < x_size) {
558 for(size_t i = y_size; i != x_size; i++) {
559 diff |= x[i];
560 }
561 }
562
563 return CT::Mask<W>::is_zero(diff);
564}

References Botan::CT::Mask< T >::is_zero().

Referenced by Botan::BigInt::is_equal().

◆ bigint_ct_is_lt()

template<WordType W>
auto Botan::bigint_ct_is_lt ( const W x[],
size_t x_size,
const W y[],
size_t y_size,
bool lt_or_equal = false ) -> CT::Mask< W >
inlineconstexpr

Compare x and y Returns a Mask: |1| if x[0:x_size] < y[0:y_size] or |0| otherwise If lt_or_equal is true, returns |1| also for x == y

Definition at line 510 of file mp_core.h.

511 {
512 const size_t common_elems = std::min(x_size, y_size);
513
514 auto is_lt = CT::Mask<W>::expand(lt_or_equal);
515
516 for(size_t i = 0; i != common_elems; i++) {
517 const auto eq = CT::Mask<W>::is_equal(x[i], y[i]);
518 const auto lt = CT::Mask<W>::is_lt(x[i], y[i]);
519 is_lt = eq.select_mask(is_lt, lt);
520 }
521
522 if(x_size < y_size) {
523 W mask = 0;
524 for(size_t i = x_size; i != y_size; i++) {
525 mask |= y[i];
526 }
527 // If any bits were set in high part of y, then is_lt should be forced true
528 is_lt |= CT::Mask<W>::expand(mask);
529 } else if(y_size < x_size) {
530 W mask = 0;
531 for(size_t i = y_size; i != x_size; i++) {
532 mask |= x[i];
533 }
534
535 // If any bits were set in high part of x, then is_lt should be false
536 is_lt &= CT::Mask<W>::is_zero(mask);
537 }
538
539 return is_lt;
540}

References Botan::CT::Mask< T >::expand(), Botan::CT::Mask< T >::is_equal(), Botan::CT::Mask< T >::is_lt(), and Botan::CT::Mask< T >::is_zero().

Referenced by Botan::BLS12_381::FieldElement::_is_lexicographically_largest(), Botan::BLS12_381::FieldElement::deserialize(), Botan::BLS12_381::Scalar::deserialize(), Botan::IntMod< MontgomeryRep< ScalarParams > >::deserialize(), Botan::BigInt::is_less_than(), Botan::PCurve::GenericPrimeOrderCurve::mul2_vartime_x_mod_order_eq(), and Botan::PCurve::PrimeOrderCurveImpl< C >::mul2_vartime_x_mod_order_eq().

◆ bigint_linmul2()

template<WordType W>
auto Botan::bigint_linmul2 ( W x[],
size_t x_size,
W y ) -> W
inlinenodiscardconstexpr

Definition at line 409 of file mp_core.h.

409 {
410 W carry = 0;
411
412 for(size_t i = 0; i != x_size; ++i) {
413 x[i] = word_madd2(x[i], y, &carry);
414 }
415
416 return carry;
417}
constexpr auto word_madd2(W a, W b, W *c) -> W
Definition mp_asmi.h:111

References word_madd2().

Referenced by Botan::BigInt::operator*=().

◆ bigint_linmul3()

template<WordType W>
void Botan::bigint_linmul3 ( W z[],
const W x[],
size_t x_size,
W y )
inlineconstexpr

Definition at line 420 of file mp_core.h.

420 {
421 const size_t blocks = x_size - (x_size % 8);
422
423 W carry = 0;
424
425 for(size_t i = 0; i != blocks; i += 8) {
426 carry = word8_linmul3(z + i, x + i, y, carry);
427 }
428
429 for(size_t i = blocks; i != x_size; ++i) {
430 z[i] = word_madd2(x[i], y, &carry);
431 }
432
433 z[x_size] = carry;
434}
constexpr auto word8_linmul3(W z[8], const W x[8], W y, W carry) -> W
Definition mp_asmi.h:438

References word8_linmul3(), and word_madd2().

Referenced by bigint_mul(), bigint_sqr(), Botan::BigInt::mul(), Botan::Montgomery_Int::mul_by_word(), operator*(), and operator*().

◆ bigint_monty_maybe_sub() [1/2]

template<WordType W>
void Botan::bigint_monty_maybe_sub ( size_t N,
W z[],
W x0,
const W x[],
const W p[] )
inlineconstexpr

Conditional subtraction for Montgomery reduction

This function assumes that (x0 || x) is less than 2*p

Computes z[0:N] = (x0 || x[0:N]) - p[0:N]

If z would be positive, returns z[0:N] Otherwise returns original input x

Definition at line 229 of file mp_core.h.

229 {
230 W borrow = 0;
231
232 const size_t blocks = N - (N % 8);
233
234 for(size_t i = 0; i != blocks; i += 8) {
235 borrow = word8_sub3(z + i, x + i, p + i, borrow);
236 }
237
238 for(size_t i = blocks; i != N; ++i) {
239 z[i] = word_sub(x[i], p[i], &borrow);
240 }
241
242 borrow = (x0 - borrow) > x0;
243
244 CT::conditional_assign_mem(borrow, z, x, N);
245}
constexpr Mask< T > conditional_assign_mem(T cnd, T *dest, const T *src, size_t elems)
Definition ct_utils.h:754
constexpr auto word8_sub3(W z[8], const W x[8], const W y[8], W carry) -> W
Definition mp_asmi.h:409

References Botan::CT::conditional_assign_mem(), word8_sub3(), and word_sub().

Referenced by Botan::BLS12_381::FieldElement::add(), Botan::BLS12_381::Scalar::add(), bigint_monty_redc_12(), bigint_monty_redc_16(), bigint_monty_redc_24(), bigint_monty_redc_32(), bigint_monty_redc_4(), bigint_monty_redc_6(), bigint_monty_redc_8(), bigint_monty_redc_generic(), bigint_mulx_monty_mul(), bigint_mulx_monty_redc(), monty_redc(), monty_redc_pdash1(), Botan::IntMod< MontgomeryRep< ScalarParams > >::mul2(), Botan::Montgomery_Int::mul_by_word(), Botan::IntMod< MontgomeryRep< ScalarParams > >::operator+, and Botan::Montgomery_Int::operator+().

◆ bigint_monty_maybe_sub() [2/2]

template<size_t N, WordType W>
void Botan::bigint_monty_maybe_sub ( W z[N],
W x0,
const W x[N],
const W y[N] )
inlineconstexpr

Conditional subtraction for Montgomery reduction

This function assumes that (x0 || x) is less than 2*p

Computes z[0:N] = (x0 || x[0:N]) - p[0:N]

If z would be positive, returns z[0:N] Otherwise returns original input x

Definition at line 258 of file mp_core.h.

258 {
259 W borrow = 0;
260
261 for(size_t i = 0; i != N; ++i) {
262 z[i] = word_sub(x[i], y[i], &borrow);
263 }
264
265 borrow = (x0 - borrow) > x0;
266
267 CT::conditional_assign_mem(borrow, z, x, N);
268}

References Botan::CT::conditional_assign_mem(), and word_sub().

◆ bigint_monty_mul()

void Botan::bigint_monty_mul ( word z[],
const word x[],
const word y[],
const word p[],
size_t p_size,
word p_dash,
word ws[],
size_t ws_size )

Montgomery multiplication

Computes z[0..p_size) = x*y/R mod p, where R = 2^(p_size * word bits), and x and y are each p_size words and less than p. z may alias x or y.

ws must be at least 4*p_size words

Definition at line 143 of file mp_monty.cpp.

144 {
145 BOTAN_ARG_CHECK(ws_size >= 4 * p_size && p_size > 0, "Invalid workspace for Montgomery multiplication");
146
147#if defined(BOTAN_HAS_MP_MULX)
148 if(use_mulx_monty(p_size)) {
149 return bigint_mulx_monty_mul(z, x, y, p, p_size, p_dash, ws);
150 }
151#endif
152
153 word* prod = ws;
154 word* mul_ws = ws + 2 * p_size;
155 bigint_mul(prod, 2 * p_size, x, p_size, p_size, y, p_size, p_size, mul_ws, 2 * p_size);
156 bigint_monty_redc(z, prod, p, p_size, p_dash, mul_ws, 2 * p_size);
157}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
void bigint_mulx_monty_mul(word z[], const word x[], const word y[], const word p[], size_t N, word p_dash, word ws[])
void bigint_mul(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw, word workspace[], size_t ws_size)
Definition mp_karat.cpp:283
void bigint_monty_redc(word r[], const word z[], const word p[], size_t p_size, word p_dash, word ws[], size_t ws_size)
Definition mp_core.h:1086
bool use_mulx_monty(size_t p_size)
Definition mp_mulx.h:33

References bigint_monty_redc(), bigint_mul(), bigint_mulx_monty_mul(), BOTAN_ARG_CHECK, and use_mulx_monty().

Referenced by Botan::Montgomery_Int::mul(), and Botan::Montgomery_Int::mul_by().

◆ bigint_monty_redc()

void Botan::bigint_monty_redc ( word r[],
const word z[],
const word p[],
size_t p_size,
word p_dash,
word ws[],
size_t ws_size )
inline

Montgomery Reduction

Parameters
rresult of exactly p_size words
zinteger to reduce, of size exactly 2*p_size.
pmodulus
p_sizesize of p
p_dashMontgomery value
wsarray of at least p_size words
ws_sizesize of ws in words

It is allowed to set &r[0] == &z[0] however in this case note that only the first p_size words of r will be written to and the high p_size words of r/z will still hold the original inputs, these must be cleared after use. See bigint_monty_redc_inplace

Definition at line 1086 of file mp_core.h.

1087 {
1088 const size_t z_size = 2 * p_size;
1089
1090 BOTAN_ARG_CHECK(ws_size >= p_size, "Montgomery reduction workspace too small");
1091
1092 if(p_size == 4) {
1093 bigint_monty_redc_4(r, z, p, p_dash, ws);
1094 } else if(p_size == 6) {
1095 bigint_monty_redc_6(r, z, p, p_dash, ws);
1096 } else if(p_size == 8) {
1097 bigint_monty_redc_8(r, z, p, p_dash, ws);
1098 } else if(p_size == 12) {
1099 bigint_monty_redc_12(r, z, p, p_dash, ws);
1100 } else if(p_size == 16) {
1101 bigint_monty_redc_16(r, z, p, p_dash, ws);
1102 } else if(p_size == 24) {
1103 bigint_monty_redc_24(r, z, p, p_dash, ws);
1104 } else if(p_size == 32) {
1105 bigint_monty_redc_32(r, z, p, p_dash, ws);
1106 } else {
1107 bigint_monty_redc_generic(r, z, z_size, p, p_size, p_dash, ws);
1108 }
1109}
BOTAN_FUZZER_API void bigint_monty_redc_6(word r[6], const word z[12], const word p[6], word p_dash, word ws[6])
BOTAN_FUZZER_API void bigint_monty_redc_24(word r[24], const word z[48], const word p[24], word p_dash, word ws[24])
BOTAN_FUZZER_API void bigint_monty_redc_generic(word r[], const word z[], size_t z_size, const word p[], size_t p_size, word p_dash, word ws[])
Definition mp_monty.cpp:94
BOTAN_FUZZER_API void bigint_monty_redc_4(word r[4], const word z[8], const word p[4], word p_dash, word ws[4])
BOTAN_FUZZER_API void bigint_monty_redc_12(word r[12], const word z[24], const word p[12], word p_dash, word ws[12])
BOTAN_FUZZER_API void bigint_monty_redc_16(word r[16], const word z[32], const word p[16], word p_dash, word ws[16])
BOTAN_FUZZER_API void bigint_monty_redc_8(word r[8], const word z[16], const word p[8], word p_dash, word ws[8])
BOTAN_FUZZER_API void bigint_monty_redc_32(word r[32], const word z[64], const word p[32], word p_dash, word ws[32])

References bigint_monty_redc_12(), bigint_monty_redc_16(), bigint_monty_redc_24(), bigint_monty_redc_32(), bigint_monty_redc_4(), bigint_monty_redc_6(), bigint_monty_redc_8(), bigint_monty_redc_generic(), and BOTAN_ARG_CHECK.

Referenced by bigint_monty_mul(), bigint_monty_redc_inplace(), and bigint_monty_sqr().

◆ bigint_monty_redc_12()

void Botan::bigint_monty_redc_12 ( word r[12],
const word z[24],
const word p[12],
word p_dash,
word ws[12] )

Definition at line 200 of file mp_monty_n.cpp.

200 {
201 word3<word> accum;
202 accum.add(z[0]);
203 ws[0] = accum.monty_step(p[0], p_dash);
204 accum.mul(ws[0], p[1]);
205 accum.add(z[1]);
206 ws[1] = accum.monty_step(p[0], p_dash);
207 accum.mul(ws[0], p[2]);
208 accum.mul(ws[1], p[1]);
209 accum.add(z[2]);
210 ws[2] = accum.monty_step(p[0], p_dash);
211 accum.mul(ws[0], p[3]);
212 accum.mul(ws[1], p[2]);
213 accum.mul(ws[2], p[1]);
214 accum.add(z[3]);
215 ws[3] = accum.monty_step(p[0], p_dash);
216 accum.mul(ws[0], p[4]);
217 accum.mul(ws[1], p[3]);
218 accum.mul(ws[2], p[2]);
219 accum.mul(ws[3], p[1]);
220 accum.add(z[4]);
221 ws[4] = accum.monty_step(p[0], p_dash);
222 accum.mul(ws[0], p[5]);
223 accum.mul(ws[1], p[4]);
224 accum.mul(ws[2], p[3]);
225 accum.mul(ws[3], p[2]);
226 accum.mul(ws[4], p[1]);
227 accum.add(z[5]);
228 ws[5] = accum.monty_step(p[0], p_dash);
229 accum.mul(ws[0], p[6]);
230 accum.mul(ws[1], p[5]);
231 accum.mul(ws[2], p[4]);
232 accum.mul(ws[3], p[3]);
233 accum.mul(ws[4], p[2]);
234 accum.mul(ws[5], p[1]);
235 accum.add(z[6]);
236 ws[6] = accum.monty_step(p[0], p_dash);
237 accum.mul(ws[0], p[7]);
238 accum.mul(ws[1], p[6]);
239 accum.mul(ws[2], p[5]);
240 accum.mul(ws[3], p[4]);
241 accum.mul(ws[4], p[3]);
242 accum.mul(ws[5], p[2]);
243 accum.mul(ws[6], p[1]);
244 accum.add(z[7]);
245 ws[7] = accum.monty_step(p[0], p_dash);
246 accum.mul(ws[0], p[8]);
247 accum.mul(ws[1], p[7]);
248 accum.mul(ws[2], p[6]);
249 accum.mul(ws[3], p[5]);
250 accum.mul(ws[4], p[4]);
251 accum.mul(ws[5], p[3]);
252 accum.mul(ws[6], p[2]);
253 accum.mul(ws[7], p[1]);
254 accum.add(z[8]);
255 ws[8] = accum.monty_step(p[0], p_dash);
256 accum.mul(ws[0], p[9]);
257 accum.mul(ws[1], p[8]);
258 accum.mul(ws[2], p[7]);
259 accum.mul(ws[3], p[6]);
260 accum.mul(ws[4], p[5]);
261 accum.mul(ws[5], p[4]);
262 accum.mul(ws[6], p[3]);
263 accum.mul(ws[7], p[2]);
264 accum.mul(ws[8], p[1]);
265 accum.add(z[9]);
266 ws[9] = accum.monty_step(p[0], p_dash);
267 accum.mul(ws[0], p[10]);
268 accum.mul(ws[1], p[9]);
269 accum.mul(ws[2], p[8]);
270 accum.mul(ws[3], p[7]);
271 accum.mul(ws[4], p[6]);
272 accum.mul(ws[5], p[5]);
273 accum.mul(ws[6], p[4]);
274 accum.mul(ws[7], p[3]);
275 accum.mul(ws[8], p[2]);
276 accum.mul(ws[9], p[1]);
277 accum.add(z[10]);
278 ws[10] = accum.monty_step(p[0], p_dash);
279 accum.mul(ws[0], p[11]);
280 accum.mul(ws[1], p[10]);
281 accum.mul(ws[2], p[9]);
282 accum.mul(ws[3], p[8]);
283 accum.mul(ws[4], p[7]);
284 accum.mul(ws[5], p[6]);
285 accum.mul(ws[6], p[5]);
286 accum.mul(ws[7], p[4]);
287 accum.mul(ws[8], p[3]);
288 accum.mul(ws[9], p[2]);
289 accum.mul(ws[10], p[1]);
290 accum.add(z[11]);
291 ws[11] = accum.monty_step(p[0], p_dash);
292 accum.mul(ws[1], p[11]);
293 accum.mul(ws[2], p[10]);
294 accum.mul(ws[3], p[9]);
295 accum.mul(ws[4], p[8]);
296 accum.mul(ws[5], p[7]);
297 accum.mul(ws[6], p[6]);
298 accum.mul(ws[7], p[5]);
299 accum.mul(ws[8], p[4]);
300 accum.mul(ws[9], p[3]);
301 accum.mul(ws[10], p[2]);
302 accum.mul(ws[11], p[1]);
303 accum.add(z[12]);
304 ws[0] = accum.extract();
305 accum.mul(ws[2], p[11]);
306 accum.mul(ws[3], p[10]);
307 accum.mul(ws[4], p[9]);
308 accum.mul(ws[5], p[8]);
309 accum.mul(ws[6], p[7]);
310 accum.mul(ws[7], p[6]);
311 accum.mul(ws[8], p[5]);
312 accum.mul(ws[9], p[4]);
313 accum.mul(ws[10], p[3]);
314 accum.mul(ws[11], p[2]);
315 accum.add(z[13]);
316 ws[1] = accum.extract();
317 accum.mul(ws[3], p[11]);
318 accum.mul(ws[4], p[10]);
319 accum.mul(ws[5], p[9]);
320 accum.mul(ws[6], p[8]);
321 accum.mul(ws[7], p[7]);
322 accum.mul(ws[8], p[6]);
323 accum.mul(ws[9], p[5]);
324 accum.mul(ws[10], p[4]);
325 accum.mul(ws[11], p[3]);
326 accum.add(z[14]);
327 ws[2] = accum.extract();
328 accum.mul(ws[4], p[11]);
329 accum.mul(ws[5], p[10]);
330 accum.mul(ws[6], p[9]);
331 accum.mul(ws[7], p[8]);
332 accum.mul(ws[8], p[7]);
333 accum.mul(ws[9], p[6]);
334 accum.mul(ws[10], p[5]);
335 accum.mul(ws[11], p[4]);
336 accum.add(z[15]);
337 ws[3] = accum.extract();
338 accum.mul(ws[5], p[11]);
339 accum.mul(ws[6], p[10]);
340 accum.mul(ws[7], p[9]);
341 accum.mul(ws[8], p[8]);
342 accum.mul(ws[9], p[7]);
343 accum.mul(ws[10], p[6]);
344 accum.mul(ws[11], p[5]);
345 accum.add(z[16]);
346 ws[4] = accum.extract();
347 accum.mul(ws[6], p[11]);
348 accum.mul(ws[7], p[10]);
349 accum.mul(ws[8], p[9]);
350 accum.mul(ws[9], p[8]);
351 accum.mul(ws[10], p[7]);
352 accum.mul(ws[11], p[6]);
353 accum.add(z[17]);
354 ws[5] = accum.extract();
355 accum.mul(ws[7], p[11]);
356 accum.mul(ws[8], p[10]);
357 accum.mul(ws[9], p[9]);
358 accum.mul(ws[10], p[8]);
359 accum.mul(ws[11], p[7]);
360 accum.add(z[18]);
361 ws[6] = accum.extract();
362 accum.mul(ws[8], p[11]);
363 accum.mul(ws[9], p[10]);
364 accum.mul(ws[10], p[9]);
365 accum.mul(ws[11], p[8]);
366 accum.add(z[19]);
367 ws[7] = accum.extract();
368 accum.mul(ws[9], p[11]);
369 accum.mul(ws[10], p[10]);
370 accum.mul(ws[11], p[9]);
371 accum.add(z[20]);
372 ws[8] = accum.extract();
373 accum.mul(ws[10], p[11]);
374 accum.mul(ws[11], p[10]);
375 accum.add(z[21]);
376 ws[9] = accum.extract();
377 accum.mul(ws[11], p[11]);
378 accum.add(z[22]);
379 ws[10] = accum.extract();
380 accum.add(z[23]);
381 ws[11] = accum.extract();
382 const word w1 = accum.extract();
383 bigint_monty_maybe_sub<12>(r, w1, ws, p);
384}
constexpr void add(W x)
Definition mp_asmi.h:656
constexpr W monty_step(W p0, W p_dash)
Definition mp_asmi.h:673
constexpr void bigint_monty_maybe_sub(size_t N, W z[], W x0, const W x[], const W p[])
Definition mp_core.h:229

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step(), and Botan::word3< W >::mul().

Referenced by bigint_monty_redc(), and monty_redc().

◆ bigint_monty_redc_16()

void Botan::bigint_monty_redc_16 ( word r[16],
const word z[32],
const word p[16],
word p_dash,
word ws[16] )

Definition at line 386 of file mp_monty_n.cpp.

386 {
387 word3<word> accum;
388 accum.add(z[0]);
389 ws[0] = accum.monty_step(p[0], p_dash);
390 accum.mul(ws[0], p[1]);
391 accum.add(z[1]);
392 ws[1] = accum.monty_step(p[0], p_dash);
393 accum.mul(ws[0], p[2]);
394 accum.mul(ws[1], p[1]);
395 accum.add(z[2]);
396 ws[2] = accum.monty_step(p[0], p_dash);
397 accum.mul(ws[0], p[3]);
398 accum.mul(ws[1], p[2]);
399 accum.mul(ws[2], p[1]);
400 accum.add(z[3]);
401 ws[3] = accum.monty_step(p[0], p_dash);
402 accum.mul(ws[0], p[4]);
403 accum.mul(ws[1], p[3]);
404 accum.mul(ws[2], p[2]);
405 accum.mul(ws[3], p[1]);
406 accum.add(z[4]);
407 ws[4] = accum.monty_step(p[0], p_dash);
408 accum.mul(ws[0], p[5]);
409 accum.mul(ws[1], p[4]);
410 accum.mul(ws[2], p[3]);
411 accum.mul(ws[3], p[2]);
412 accum.mul(ws[4], p[1]);
413 accum.add(z[5]);
414 ws[5] = accum.monty_step(p[0], p_dash);
415 accum.mul(ws[0], p[6]);
416 accum.mul(ws[1], p[5]);
417 accum.mul(ws[2], p[4]);
418 accum.mul(ws[3], p[3]);
419 accum.mul(ws[4], p[2]);
420 accum.mul(ws[5], p[1]);
421 accum.add(z[6]);
422 ws[6] = accum.monty_step(p[0], p_dash);
423 accum.mul(ws[0], p[7]);
424 accum.mul(ws[1], p[6]);
425 accum.mul(ws[2], p[5]);
426 accum.mul(ws[3], p[4]);
427 accum.mul(ws[4], p[3]);
428 accum.mul(ws[5], p[2]);
429 accum.mul(ws[6], p[1]);
430 accum.add(z[7]);
431 ws[7] = accum.monty_step(p[0], p_dash);
432 accum.mul(ws[0], p[8]);
433 accum.mul(ws[1], p[7]);
434 accum.mul(ws[2], p[6]);
435 accum.mul(ws[3], p[5]);
436 accum.mul(ws[4], p[4]);
437 accum.mul(ws[5], p[3]);
438 accum.mul(ws[6], p[2]);
439 accum.mul(ws[7], p[1]);
440 accum.add(z[8]);
441 ws[8] = accum.monty_step(p[0], p_dash);
442 accum.mul(ws[0], p[9]);
443 accum.mul(ws[1], p[8]);
444 accum.mul(ws[2], p[7]);
445 accum.mul(ws[3], p[6]);
446 accum.mul(ws[4], p[5]);
447 accum.mul(ws[5], p[4]);
448 accum.mul(ws[6], p[3]);
449 accum.mul(ws[7], p[2]);
450 accum.mul(ws[8], p[1]);
451 accum.add(z[9]);
452 ws[9] = accum.monty_step(p[0], p_dash);
453 accum.mul(ws[0], p[10]);
454 accum.mul(ws[1], p[9]);
455 accum.mul(ws[2], p[8]);
456 accum.mul(ws[3], p[7]);
457 accum.mul(ws[4], p[6]);
458 accum.mul(ws[5], p[5]);
459 accum.mul(ws[6], p[4]);
460 accum.mul(ws[7], p[3]);
461 accum.mul(ws[8], p[2]);
462 accum.mul(ws[9], p[1]);
463 accum.add(z[10]);
464 ws[10] = accum.monty_step(p[0], p_dash);
465 accum.mul(ws[0], p[11]);
466 accum.mul(ws[1], p[10]);
467 accum.mul(ws[2], p[9]);
468 accum.mul(ws[3], p[8]);
469 accum.mul(ws[4], p[7]);
470 accum.mul(ws[5], p[6]);
471 accum.mul(ws[6], p[5]);
472 accum.mul(ws[7], p[4]);
473 accum.mul(ws[8], p[3]);
474 accum.mul(ws[9], p[2]);
475 accum.mul(ws[10], p[1]);
476 accum.add(z[11]);
477 ws[11] = accum.monty_step(p[0], p_dash);
478 accum.mul(ws[0], p[12]);
479 accum.mul(ws[1], p[11]);
480 accum.mul(ws[2], p[10]);
481 accum.mul(ws[3], p[9]);
482 accum.mul(ws[4], p[8]);
483 accum.mul(ws[5], p[7]);
484 accum.mul(ws[6], p[6]);
485 accum.mul(ws[7], p[5]);
486 accum.mul(ws[8], p[4]);
487 accum.mul(ws[9], p[3]);
488 accum.mul(ws[10], p[2]);
489 accum.mul(ws[11], p[1]);
490 accum.add(z[12]);
491 ws[12] = accum.monty_step(p[0], p_dash);
492 accum.mul(ws[0], p[13]);
493 accum.mul(ws[1], p[12]);
494 accum.mul(ws[2], p[11]);
495 accum.mul(ws[3], p[10]);
496 accum.mul(ws[4], p[9]);
497 accum.mul(ws[5], p[8]);
498 accum.mul(ws[6], p[7]);
499 accum.mul(ws[7], p[6]);
500 accum.mul(ws[8], p[5]);
501 accum.mul(ws[9], p[4]);
502 accum.mul(ws[10], p[3]);
503 accum.mul(ws[11], p[2]);
504 accum.mul(ws[12], p[1]);
505 accum.add(z[13]);
506 ws[13] = accum.monty_step(p[0], p_dash);
507 accum.mul(ws[0], p[14]);
508 accum.mul(ws[1], p[13]);
509 accum.mul(ws[2], p[12]);
510 accum.mul(ws[3], p[11]);
511 accum.mul(ws[4], p[10]);
512 accum.mul(ws[5], p[9]);
513 accum.mul(ws[6], p[8]);
514 accum.mul(ws[7], p[7]);
515 accum.mul(ws[8], p[6]);
516 accum.mul(ws[9], p[5]);
517 accum.mul(ws[10], p[4]);
518 accum.mul(ws[11], p[3]);
519 accum.mul(ws[12], p[2]);
520 accum.mul(ws[13], p[1]);
521 accum.add(z[14]);
522 ws[14] = accum.monty_step(p[0], p_dash);
523 accum.mul(ws[0], p[15]);
524 accum.mul(ws[1], p[14]);
525 accum.mul(ws[2], p[13]);
526 accum.mul(ws[3], p[12]);
527 accum.mul(ws[4], p[11]);
528 accum.mul(ws[5], p[10]);
529 accum.mul(ws[6], p[9]);
530 accum.mul(ws[7], p[8]);
531 accum.mul(ws[8], p[7]);
532 accum.mul(ws[9], p[6]);
533 accum.mul(ws[10], p[5]);
534 accum.mul(ws[11], p[4]);
535 accum.mul(ws[12], p[3]);
536 accum.mul(ws[13], p[2]);
537 accum.mul(ws[14], p[1]);
538 accum.add(z[15]);
539 ws[15] = accum.monty_step(p[0], p_dash);
540 accum.mul(ws[1], p[15]);
541 accum.mul(ws[2], p[14]);
542 accum.mul(ws[3], p[13]);
543 accum.mul(ws[4], p[12]);
544 accum.mul(ws[5], p[11]);
545 accum.mul(ws[6], p[10]);
546 accum.mul(ws[7], p[9]);
547 accum.mul(ws[8], p[8]);
548 accum.mul(ws[9], p[7]);
549 accum.mul(ws[10], p[6]);
550 accum.mul(ws[11], p[5]);
551 accum.mul(ws[12], p[4]);
552 accum.mul(ws[13], p[3]);
553 accum.mul(ws[14], p[2]);
554 accum.mul(ws[15], p[1]);
555 accum.add(z[16]);
556 ws[0] = accum.extract();
557 accum.mul(ws[2], p[15]);
558 accum.mul(ws[3], p[14]);
559 accum.mul(ws[4], p[13]);
560 accum.mul(ws[5], p[12]);
561 accum.mul(ws[6], p[11]);
562 accum.mul(ws[7], p[10]);
563 accum.mul(ws[8], p[9]);
564 accum.mul(ws[9], p[8]);
565 accum.mul(ws[10], p[7]);
566 accum.mul(ws[11], p[6]);
567 accum.mul(ws[12], p[5]);
568 accum.mul(ws[13], p[4]);
569 accum.mul(ws[14], p[3]);
570 accum.mul(ws[15], p[2]);
571 accum.add(z[17]);
572 ws[1] = accum.extract();
573 accum.mul(ws[3], p[15]);
574 accum.mul(ws[4], p[14]);
575 accum.mul(ws[5], p[13]);
576 accum.mul(ws[6], p[12]);
577 accum.mul(ws[7], p[11]);
578 accum.mul(ws[8], p[10]);
579 accum.mul(ws[9], p[9]);
580 accum.mul(ws[10], p[8]);
581 accum.mul(ws[11], p[7]);
582 accum.mul(ws[12], p[6]);
583 accum.mul(ws[13], p[5]);
584 accum.mul(ws[14], p[4]);
585 accum.mul(ws[15], p[3]);
586 accum.add(z[18]);
587 ws[2] = accum.extract();
588 accum.mul(ws[4], p[15]);
589 accum.mul(ws[5], p[14]);
590 accum.mul(ws[6], p[13]);
591 accum.mul(ws[7], p[12]);
592 accum.mul(ws[8], p[11]);
593 accum.mul(ws[9], p[10]);
594 accum.mul(ws[10], p[9]);
595 accum.mul(ws[11], p[8]);
596 accum.mul(ws[12], p[7]);
597 accum.mul(ws[13], p[6]);
598 accum.mul(ws[14], p[5]);
599 accum.mul(ws[15], p[4]);
600 accum.add(z[19]);
601 ws[3] = accum.extract();
602 accum.mul(ws[5], p[15]);
603 accum.mul(ws[6], p[14]);
604 accum.mul(ws[7], p[13]);
605 accum.mul(ws[8], p[12]);
606 accum.mul(ws[9], p[11]);
607 accum.mul(ws[10], p[10]);
608 accum.mul(ws[11], p[9]);
609 accum.mul(ws[12], p[8]);
610 accum.mul(ws[13], p[7]);
611 accum.mul(ws[14], p[6]);
612 accum.mul(ws[15], p[5]);
613 accum.add(z[20]);
614 ws[4] = accum.extract();
615 accum.mul(ws[6], p[15]);
616 accum.mul(ws[7], p[14]);
617 accum.mul(ws[8], p[13]);
618 accum.mul(ws[9], p[12]);
619 accum.mul(ws[10], p[11]);
620 accum.mul(ws[11], p[10]);
621 accum.mul(ws[12], p[9]);
622 accum.mul(ws[13], p[8]);
623 accum.mul(ws[14], p[7]);
624 accum.mul(ws[15], p[6]);
625 accum.add(z[21]);
626 ws[5] = accum.extract();
627 accum.mul(ws[7], p[15]);
628 accum.mul(ws[8], p[14]);
629 accum.mul(ws[9], p[13]);
630 accum.mul(ws[10], p[12]);
631 accum.mul(ws[11], p[11]);
632 accum.mul(ws[12], p[10]);
633 accum.mul(ws[13], p[9]);
634 accum.mul(ws[14], p[8]);
635 accum.mul(ws[15], p[7]);
636 accum.add(z[22]);
637 ws[6] = accum.extract();
638 accum.mul(ws[8], p[15]);
639 accum.mul(ws[9], p[14]);
640 accum.mul(ws[10], p[13]);
641 accum.mul(ws[11], p[12]);
642 accum.mul(ws[12], p[11]);
643 accum.mul(ws[13], p[10]);
644 accum.mul(ws[14], p[9]);
645 accum.mul(ws[15], p[8]);
646 accum.add(z[23]);
647 ws[7] = accum.extract();
648 accum.mul(ws[9], p[15]);
649 accum.mul(ws[10], p[14]);
650 accum.mul(ws[11], p[13]);
651 accum.mul(ws[12], p[12]);
652 accum.mul(ws[13], p[11]);
653 accum.mul(ws[14], p[10]);
654 accum.mul(ws[15], p[9]);
655 accum.add(z[24]);
656 ws[8] = accum.extract();
657 accum.mul(ws[10], p[15]);
658 accum.mul(ws[11], p[14]);
659 accum.mul(ws[12], p[13]);
660 accum.mul(ws[13], p[12]);
661 accum.mul(ws[14], p[11]);
662 accum.mul(ws[15], p[10]);
663 accum.add(z[25]);
664 ws[9] = accum.extract();
665 accum.mul(ws[11], p[15]);
666 accum.mul(ws[12], p[14]);
667 accum.mul(ws[13], p[13]);
668 accum.mul(ws[14], p[12]);
669 accum.mul(ws[15], p[11]);
670 accum.add(z[26]);
671 ws[10] = accum.extract();
672 accum.mul(ws[12], p[15]);
673 accum.mul(ws[13], p[14]);
674 accum.mul(ws[14], p[13]);
675 accum.mul(ws[15], p[12]);
676 accum.add(z[27]);
677 ws[11] = accum.extract();
678 accum.mul(ws[13], p[15]);
679 accum.mul(ws[14], p[14]);
680 accum.mul(ws[15], p[13]);
681 accum.add(z[28]);
682 ws[12] = accum.extract();
683 accum.mul(ws[14], p[15]);
684 accum.mul(ws[15], p[14]);
685 accum.add(z[29]);
686 ws[13] = accum.extract();
687 accum.mul(ws[15], p[15]);
688 accum.add(z[30]);
689 ws[14] = accum.extract();
690 accum.add(z[31]);
691 ws[15] = accum.extract();
692 const word w1 = accum.extract();
693 bigint_monty_maybe_sub<16>(r, w1, ws, p);
694}

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step(), and Botan::word3< W >::mul().

Referenced by bigint_monty_redc(), and monty_redc().

◆ bigint_monty_redc_24()

void Botan::bigint_monty_redc_24 ( word r[24],
const word z[48],
const word p[24],
word p_dash,
word ws[24] )

Definition at line 696 of file mp_monty_n.cpp.

696 {
697 word3<word> accum;
698 accum.add(z[0]);
699 ws[0] = accum.monty_step(p[0], p_dash);
700 accum.mul(ws[0], p[1]);
701 accum.add(z[1]);
702 ws[1] = accum.monty_step(p[0], p_dash);
703 accum.mul(ws[0], p[2]);
704 accum.mul(ws[1], p[1]);
705 accum.add(z[2]);
706 ws[2] = accum.monty_step(p[0], p_dash);
707 accum.mul(ws[0], p[3]);
708 accum.mul(ws[1], p[2]);
709 accum.mul(ws[2], p[1]);
710 accum.add(z[3]);
711 ws[3] = accum.monty_step(p[0], p_dash);
712 accum.mul(ws[0], p[4]);
713 accum.mul(ws[1], p[3]);
714 accum.mul(ws[2], p[2]);
715 accum.mul(ws[3], p[1]);
716 accum.add(z[4]);
717 ws[4] = accum.monty_step(p[0], p_dash);
718 accum.mul(ws[0], p[5]);
719 accum.mul(ws[1], p[4]);
720 accum.mul(ws[2], p[3]);
721 accum.mul(ws[3], p[2]);
722 accum.mul(ws[4], p[1]);
723 accum.add(z[5]);
724 ws[5] = accum.monty_step(p[0], p_dash);
725 accum.mul(ws[0], p[6]);
726 accum.mul(ws[1], p[5]);
727 accum.mul(ws[2], p[4]);
728 accum.mul(ws[3], p[3]);
729 accum.mul(ws[4], p[2]);
730 accum.mul(ws[5], p[1]);
731 accum.add(z[6]);
732 ws[6] = accum.monty_step(p[0], p_dash);
733 accum.mul(ws[0], p[7]);
734 accum.mul(ws[1], p[6]);
735 accum.mul(ws[2], p[5]);
736 accum.mul(ws[3], p[4]);
737 accum.mul(ws[4], p[3]);
738 accum.mul(ws[5], p[2]);
739 accum.mul(ws[6], p[1]);
740 accum.add(z[7]);
741 ws[7] = accum.monty_step(p[0], p_dash);
742 accum.mul(ws[0], p[8]);
743 accum.mul(ws[1], p[7]);
744 accum.mul(ws[2], p[6]);
745 accum.mul(ws[3], p[5]);
746 accum.mul(ws[4], p[4]);
747 accum.mul(ws[5], p[3]);
748 accum.mul(ws[6], p[2]);
749 accum.mul(ws[7], p[1]);
750 accum.add(z[8]);
751 ws[8] = accum.monty_step(p[0], p_dash);
752 accum.mul(ws[0], p[9]);
753 accum.mul(ws[1], p[8]);
754 accum.mul(ws[2], p[7]);
755 accum.mul(ws[3], p[6]);
756 accum.mul(ws[4], p[5]);
757 accum.mul(ws[5], p[4]);
758 accum.mul(ws[6], p[3]);
759 accum.mul(ws[7], p[2]);
760 accum.mul(ws[8], p[1]);
761 accum.add(z[9]);
762 ws[9] = accum.monty_step(p[0], p_dash);
763 accum.mul(ws[0], p[10]);
764 accum.mul(ws[1], p[9]);
765 accum.mul(ws[2], p[8]);
766 accum.mul(ws[3], p[7]);
767 accum.mul(ws[4], p[6]);
768 accum.mul(ws[5], p[5]);
769 accum.mul(ws[6], p[4]);
770 accum.mul(ws[7], p[3]);
771 accum.mul(ws[8], p[2]);
772 accum.mul(ws[9], p[1]);
773 accum.add(z[10]);
774 ws[10] = accum.monty_step(p[0], p_dash);
775 accum.mul(ws[0], p[11]);
776 accum.mul(ws[1], p[10]);
777 accum.mul(ws[2], p[9]);
778 accum.mul(ws[3], p[8]);
779 accum.mul(ws[4], p[7]);
780 accum.mul(ws[5], p[6]);
781 accum.mul(ws[6], p[5]);
782 accum.mul(ws[7], p[4]);
783 accum.mul(ws[8], p[3]);
784 accum.mul(ws[9], p[2]);
785 accum.mul(ws[10], p[1]);
786 accum.add(z[11]);
787 ws[11] = accum.monty_step(p[0], p_dash);
788 accum.mul(ws[0], p[12]);
789 accum.mul(ws[1], p[11]);
790 accum.mul(ws[2], p[10]);
791 accum.mul(ws[3], p[9]);
792 accum.mul(ws[4], p[8]);
793 accum.mul(ws[5], p[7]);
794 accum.mul(ws[6], p[6]);
795 accum.mul(ws[7], p[5]);
796 accum.mul(ws[8], p[4]);
797 accum.mul(ws[9], p[3]);
798 accum.mul(ws[10], p[2]);
799 accum.mul(ws[11], p[1]);
800 accum.add(z[12]);
801 ws[12] = accum.monty_step(p[0], p_dash);
802 accum.mul(ws[0], p[13]);
803 accum.mul(ws[1], p[12]);
804 accum.mul(ws[2], p[11]);
805 accum.mul(ws[3], p[10]);
806 accum.mul(ws[4], p[9]);
807 accum.mul(ws[5], p[8]);
808 accum.mul(ws[6], p[7]);
809 accum.mul(ws[7], p[6]);
810 accum.mul(ws[8], p[5]);
811 accum.mul(ws[9], p[4]);
812 accum.mul(ws[10], p[3]);
813 accum.mul(ws[11], p[2]);
814 accum.mul(ws[12], p[1]);
815 accum.add(z[13]);
816 ws[13] = accum.monty_step(p[0], p_dash);
817 accum.mul(ws[0], p[14]);
818 accum.mul(ws[1], p[13]);
819 accum.mul(ws[2], p[12]);
820 accum.mul(ws[3], p[11]);
821 accum.mul(ws[4], p[10]);
822 accum.mul(ws[5], p[9]);
823 accum.mul(ws[6], p[8]);
824 accum.mul(ws[7], p[7]);
825 accum.mul(ws[8], p[6]);
826 accum.mul(ws[9], p[5]);
827 accum.mul(ws[10], p[4]);
828 accum.mul(ws[11], p[3]);
829 accum.mul(ws[12], p[2]);
830 accum.mul(ws[13], p[1]);
831 accum.add(z[14]);
832 ws[14] = accum.monty_step(p[0], p_dash);
833 accum.mul(ws[0], p[15]);
834 accum.mul(ws[1], p[14]);
835 accum.mul(ws[2], p[13]);
836 accum.mul(ws[3], p[12]);
837 accum.mul(ws[4], p[11]);
838 accum.mul(ws[5], p[10]);
839 accum.mul(ws[6], p[9]);
840 accum.mul(ws[7], p[8]);
841 accum.mul(ws[8], p[7]);
842 accum.mul(ws[9], p[6]);
843 accum.mul(ws[10], p[5]);
844 accum.mul(ws[11], p[4]);
845 accum.mul(ws[12], p[3]);
846 accum.mul(ws[13], p[2]);
847 accum.mul(ws[14], p[1]);
848 accum.add(z[15]);
849 ws[15] = accum.monty_step(p[0], p_dash);
850 accum.mul(ws[0], p[16]);
851 accum.mul(ws[1], p[15]);
852 accum.mul(ws[2], p[14]);
853 accum.mul(ws[3], p[13]);
854 accum.mul(ws[4], p[12]);
855 accum.mul(ws[5], p[11]);
856 accum.mul(ws[6], p[10]);
857 accum.mul(ws[7], p[9]);
858 accum.mul(ws[8], p[8]);
859 accum.mul(ws[9], p[7]);
860 accum.mul(ws[10], p[6]);
861 accum.mul(ws[11], p[5]);
862 accum.mul(ws[12], p[4]);
863 accum.mul(ws[13], p[3]);
864 accum.mul(ws[14], p[2]);
865 accum.mul(ws[15], p[1]);
866 accum.add(z[16]);
867 ws[16] = accum.monty_step(p[0], p_dash);
868 accum.mul(ws[0], p[17]);
869 accum.mul(ws[1], p[16]);
870 accum.mul(ws[2], p[15]);
871 accum.mul(ws[3], p[14]);
872 accum.mul(ws[4], p[13]);
873 accum.mul(ws[5], p[12]);
874 accum.mul(ws[6], p[11]);
875 accum.mul(ws[7], p[10]);
876 accum.mul(ws[8], p[9]);
877 accum.mul(ws[9], p[8]);
878 accum.mul(ws[10], p[7]);
879 accum.mul(ws[11], p[6]);
880 accum.mul(ws[12], p[5]);
881 accum.mul(ws[13], p[4]);
882 accum.mul(ws[14], p[3]);
883 accum.mul(ws[15], p[2]);
884 accum.mul(ws[16], p[1]);
885 accum.add(z[17]);
886 ws[17] = accum.monty_step(p[0], p_dash);
887 accum.mul(ws[0], p[18]);
888 accum.mul(ws[1], p[17]);
889 accum.mul(ws[2], p[16]);
890 accum.mul(ws[3], p[15]);
891 accum.mul(ws[4], p[14]);
892 accum.mul(ws[5], p[13]);
893 accum.mul(ws[6], p[12]);
894 accum.mul(ws[7], p[11]);
895 accum.mul(ws[8], p[10]);
896 accum.mul(ws[9], p[9]);
897 accum.mul(ws[10], p[8]);
898 accum.mul(ws[11], p[7]);
899 accum.mul(ws[12], p[6]);
900 accum.mul(ws[13], p[5]);
901 accum.mul(ws[14], p[4]);
902 accum.mul(ws[15], p[3]);
903 accum.mul(ws[16], p[2]);
904 accum.mul(ws[17], p[1]);
905 accum.add(z[18]);
906 ws[18] = accum.monty_step(p[0], p_dash);
907 accum.mul(ws[0], p[19]);
908 accum.mul(ws[1], p[18]);
909 accum.mul(ws[2], p[17]);
910 accum.mul(ws[3], p[16]);
911 accum.mul(ws[4], p[15]);
912 accum.mul(ws[5], p[14]);
913 accum.mul(ws[6], p[13]);
914 accum.mul(ws[7], p[12]);
915 accum.mul(ws[8], p[11]);
916 accum.mul(ws[9], p[10]);
917 accum.mul(ws[10], p[9]);
918 accum.mul(ws[11], p[8]);
919 accum.mul(ws[12], p[7]);
920 accum.mul(ws[13], p[6]);
921 accum.mul(ws[14], p[5]);
922 accum.mul(ws[15], p[4]);
923 accum.mul(ws[16], p[3]);
924 accum.mul(ws[17], p[2]);
925 accum.mul(ws[18], p[1]);
926 accum.add(z[19]);
927 ws[19] = accum.monty_step(p[0], p_dash);
928 accum.mul(ws[0], p[20]);
929 accum.mul(ws[1], p[19]);
930 accum.mul(ws[2], p[18]);
931 accum.mul(ws[3], p[17]);
932 accum.mul(ws[4], p[16]);
933 accum.mul(ws[5], p[15]);
934 accum.mul(ws[6], p[14]);
935 accum.mul(ws[7], p[13]);
936 accum.mul(ws[8], p[12]);
937 accum.mul(ws[9], p[11]);
938 accum.mul(ws[10], p[10]);
939 accum.mul(ws[11], p[9]);
940 accum.mul(ws[12], p[8]);
941 accum.mul(ws[13], p[7]);
942 accum.mul(ws[14], p[6]);
943 accum.mul(ws[15], p[5]);
944 accum.mul(ws[16], p[4]);
945 accum.mul(ws[17], p[3]);
946 accum.mul(ws[18], p[2]);
947 accum.mul(ws[19], p[1]);
948 accum.add(z[20]);
949 ws[20] = accum.monty_step(p[0], p_dash);
950 accum.mul(ws[0], p[21]);
951 accum.mul(ws[1], p[20]);
952 accum.mul(ws[2], p[19]);
953 accum.mul(ws[3], p[18]);
954 accum.mul(ws[4], p[17]);
955 accum.mul(ws[5], p[16]);
956 accum.mul(ws[6], p[15]);
957 accum.mul(ws[7], p[14]);
958 accum.mul(ws[8], p[13]);
959 accum.mul(ws[9], p[12]);
960 accum.mul(ws[10], p[11]);
961 accum.mul(ws[11], p[10]);
962 accum.mul(ws[12], p[9]);
963 accum.mul(ws[13], p[8]);
964 accum.mul(ws[14], p[7]);
965 accum.mul(ws[15], p[6]);
966 accum.mul(ws[16], p[5]);
967 accum.mul(ws[17], p[4]);
968 accum.mul(ws[18], p[3]);
969 accum.mul(ws[19], p[2]);
970 accum.mul(ws[20], p[1]);
971 accum.add(z[21]);
972 ws[21] = accum.monty_step(p[0], p_dash);
973 accum.mul(ws[0], p[22]);
974 accum.mul(ws[1], p[21]);
975 accum.mul(ws[2], p[20]);
976 accum.mul(ws[3], p[19]);
977 accum.mul(ws[4], p[18]);
978 accum.mul(ws[5], p[17]);
979 accum.mul(ws[6], p[16]);
980 accum.mul(ws[7], p[15]);
981 accum.mul(ws[8], p[14]);
982 accum.mul(ws[9], p[13]);
983 accum.mul(ws[10], p[12]);
984 accum.mul(ws[11], p[11]);
985 accum.mul(ws[12], p[10]);
986 accum.mul(ws[13], p[9]);
987 accum.mul(ws[14], p[8]);
988 accum.mul(ws[15], p[7]);
989 accum.mul(ws[16], p[6]);
990 accum.mul(ws[17], p[5]);
991 accum.mul(ws[18], p[4]);
992 accum.mul(ws[19], p[3]);
993 accum.mul(ws[20], p[2]);
994 accum.mul(ws[21], p[1]);
995 accum.add(z[22]);
996 ws[22] = accum.monty_step(p[0], p_dash);
997 accum.mul(ws[0], p[23]);
998 accum.mul(ws[1], p[22]);
999 accum.mul(ws[2], p[21]);
1000 accum.mul(ws[3], p[20]);
1001 accum.mul(ws[4], p[19]);
1002 accum.mul(ws[5], p[18]);
1003 accum.mul(ws[6], p[17]);
1004 accum.mul(ws[7], p[16]);
1005 accum.mul(ws[8], p[15]);
1006 accum.mul(ws[9], p[14]);
1007 accum.mul(ws[10], p[13]);
1008 accum.mul(ws[11], p[12]);
1009 accum.mul(ws[12], p[11]);
1010 accum.mul(ws[13], p[10]);
1011 accum.mul(ws[14], p[9]);
1012 accum.mul(ws[15], p[8]);
1013 accum.mul(ws[16], p[7]);
1014 accum.mul(ws[17], p[6]);
1015 accum.mul(ws[18], p[5]);
1016 accum.mul(ws[19], p[4]);
1017 accum.mul(ws[20], p[3]);
1018 accum.mul(ws[21], p[2]);
1019 accum.mul(ws[22], p[1]);
1020 accum.add(z[23]);
1021 ws[23] = accum.monty_step(p[0], p_dash);
1022 accum.mul(ws[1], p[23]);
1023 accum.mul(ws[2], p[22]);
1024 accum.mul(ws[3], p[21]);
1025 accum.mul(ws[4], p[20]);
1026 accum.mul(ws[5], p[19]);
1027 accum.mul(ws[6], p[18]);
1028 accum.mul(ws[7], p[17]);
1029 accum.mul(ws[8], p[16]);
1030 accum.mul(ws[9], p[15]);
1031 accum.mul(ws[10], p[14]);
1032 accum.mul(ws[11], p[13]);
1033 accum.mul(ws[12], p[12]);
1034 accum.mul(ws[13], p[11]);
1035 accum.mul(ws[14], p[10]);
1036 accum.mul(ws[15], p[9]);
1037 accum.mul(ws[16], p[8]);
1038 accum.mul(ws[17], p[7]);
1039 accum.mul(ws[18], p[6]);
1040 accum.mul(ws[19], p[5]);
1041 accum.mul(ws[20], p[4]);
1042 accum.mul(ws[21], p[3]);
1043 accum.mul(ws[22], p[2]);
1044 accum.mul(ws[23], p[1]);
1045 accum.add(z[24]);
1046 ws[0] = accum.extract();
1047 accum.mul(ws[2], p[23]);
1048 accum.mul(ws[3], p[22]);
1049 accum.mul(ws[4], p[21]);
1050 accum.mul(ws[5], p[20]);
1051 accum.mul(ws[6], p[19]);
1052 accum.mul(ws[7], p[18]);
1053 accum.mul(ws[8], p[17]);
1054 accum.mul(ws[9], p[16]);
1055 accum.mul(ws[10], p[15]);
1056 accum.mul(ws[11], p[14]);
1057 accum.mul(ws[12], p[13]);
1058 accum.mul(ws[13], p[12]);
1059 accum.mul(ws[14], p[11]);
1060 accum.mul(ws[15], p[10]);
1061 accum.mul(ws[16], p[9]);
1062 accum.mul(ws[17], p[8]);
1063 accum.mul(ws[18], p[7]);
1064 accum.mul(ws[19], p[6]);
1065 accum.mul(ws[20], p[5]);
1066 accum.mul(ws[21], p[4]);
1067 accum.mul(ws[22], p[3]);
1068 accum.mul(ws[23], p[2]);
1069 accum.add(z[25]);
1070 ws[1] = accum.extract();
1071 accum.mul(ws[3], p[23]);
1072 accum.mul(ws[4], p[22]);
1073 accum.mul(ws[5], p[21]);
1074 accum.mul(ws[6], p[20]);
1075 accum.mul(ws[7], p[19]);
1076 accum.mul(ws[8], p[18]);
1077 accum.mul(ws[9], p[17]);
1078 accum.mul(ws[10], p[16]);
1079 accum.mul(ws[11], p[15]);
1080 accum.mul(ws[12], p[14]);
1081 accum.mul(ws[13], p[13]);
1082 accum.mul(ws[14], p[12]);
1083 accum.mul(ws[15], p[11]);
1084 accum.mul(ws[16], p[10]);
1085 accum.mul(ws[17], p[9]);
1086 accum.mul(ws[18], p[8]);
1087 accum.mul(ws[19], p[7]);
1088 accum.mul(ws[20], p[6]);
1089 accum.mul(ws[21], p[5]);
1090 accum.mul(ws[22], p[4]);
1091 accum.mul(ws[23], p[3]);
1092 accum.add(z[26]);
1093 ws[2] = accum.extract();
1094 accum.mul(ws[4], p[23]);
1095 accum.mul(ws[5], p[22]);
1096 accum.mul(ws[6], p[21]);
1097 accum.mul(ws[7], p[20]);
1098 accum.mul(ws[8], p[19]);
1099 accum.mul(ws[9], p[18]);
1100 accum.mul(ws[10], p[17]);
1101 accum.mul(ws[11], p[16]);
1102 accum.mul(ws[12], p[15]);
1103 accum.mul(ws[13], p[14]);
1104 accum.mul(ws[14], p[13]);
1105 accum.mul(ws[15], p[12]);
1106 accum.mul(ws[16], p[11]);
1107 accum.mul(ws[17], p[10]);
1108 accum.mul(ws[18], p[9]);
1109 accum.mul(ws[19], p[8]);
1110 accum.mul(ws[20], p[7]);
1111 accum.mul(ws[21], p[6]);
1112 accum.mul(ws[22], p[5]);
1113 accum.mul(ws[23], p[4]);
1114 accum.add(z[27]);
1115 ws[3] = accum.extract();
1116 accum.mul(ws[5], p[23]);
1117 accum.mul(ws[6], p[22]);
1118 accum.mul(ws[7], p[21]);
1119 accum.mul(ws[8], p[20]);
1120 accum.mul(ws[9], p[19]);
1121 accum.mul(ws[10], p[18]);
1122 accum.mul(ws[11], p[17]);
1123 accum.mul(ws[12], p[16]);
1124 accum.mul(ws[13], p[15]);
1125 accum.mul(ws[14], p[14]);
1126 accum.mul(ws[15], p[13]);
1127 accum.mul(ws[16], p[12]);
1128 accum.mul(ws[17], p[11]);
1129 accum.mul(ws[18], p[10]);
1130 accum.mul(ws[19], p[9]);
1131 accum.mul(ws[20], p[8]);
1132 accum.mul(ws[21], p[7]);
1133 accum.mul(ws[22], p[6]);
1134 accum.mul(ws[23], p[5]);
1135 accum.add(z[28]);
1136 ws[4] = accum.extract();
1137 accum.mul(ws[6], p[23]);
1138 accum.mul(ws[7], p[22]);
1139 accum.mul(ws[8], p[21]);
1140 accum.mul(ws[9], p[20]);
1141 accum.mul(ws[10], p[19]);
1142 accum.mul(ws[11], p[18]);
1143 accum.mul(ws[12], p[17]);
1144 accum.mul(ws[13], p[16]);
1145 accum.mul(ws[14], p[15]);
1146 accum.mul(ws[15], p[14]);
1147 accum.mul(ws[16], p[13]);
1148 accum.mul(ws[17], p[12]);
1149 accum.mul(ws[18], p[11]);
1150 accum.mul(ws[19], p[10]);
1151 accum.mul(ws[20], p[9]);
1152 accum.mul(ws[21], p[8]);
1153 accum.mul(ws[22], p[7]);
1154 accum.mul(ws[23], p[6]);
1155 accum.add(z[29]);
1156 ws[5] = accum.extract();
1157 accum.mul(ws[7], p[23]);
1158 accum.mul(ws[8], p[22]);
1159 accum.mul(ws[9], p[21]);
1160 accum.mul(ws[10], p[20]);
1161 accum.mul(ws[11], p[19]);
1162 accum.mul(ws[12], p[18]);
1163 accum.mul(ws[13], p[17]);
1164 accum.mul(ws[14], p[16]);
1165 accum.mul(ws[15], p[15]);
1166 accum.mul(ws[16], p[14]);
1167 accum.mul(ws[17], p[13]);
1168 accum.mul(ws[18], p[12]);
1169 accum.mul(ws[19], p[11]);
1170 accum.mul(ws[20], p[10]);
1171 accum.mul(ws[21], p[9]);
1172 accum.mul(ws[22], p[8]);
1173 accum.mul(ws[23], p[7]);
1174 accum.add(z[30]);
1175 ws[6] = accum.extract();
1176 accum.mul(ws[8], p[23]);
1177 accum.mul(ws[9], p[22]);
1178 accum.mul(ws[10], p[21]);
1179 accum.mul(ws[11], p[20]);
1180 accum.mul(ws[12], p[19]);
1181 accum.mul(ws[13], p[18]);
1182 accum.mul(ws[14], p[17]);
1183 accum.mul(ws[15], p[16]);
1184 accum.mul(ws[16], p[15]);
1185 accum.mul(ws[17], p[14]);
1186 accum.mul(ws[18], p[13]);
1187 accum.mul(ws[19], p[12]);
1188 accum.mul(ws[20], p[11]);
1189 accum.mul(ws[21], p[10]);
1190 accum.mul(ws[22], p[9]);
1191 accum.mul(ws[23], p[8]);
1192 accum.add(z[31]);
1193 ws[7] = accum.extract();
1194 accum.mul(ws[9], p[23]);
1195 accum.mul(ws[10], p[22]);
1196 accum.mul(ws[11], p[21]);
1197 accum.mul(ws[12], p[20]);
1198 accum.mul(ws[13], p[19]);
1199 accum.mul(ws[14], p[18]);
1200 accum.mul(ws[15], p[17]);
1201 accum.mul(ws[16], p[16]);
1202 accum.mul(ws[17], p[15]);
1203 accum.mul(ws[18], p[14]);
1204 accum.mul(ws[19], p[13]);
1205 accum.mul(ws[20], p[12]);
1206 accum.mul(ws[21], p[11]);
1207 accum.mul(ws[22], p[10]);
1208 accum.mul(ws[23], p[9]);
1209 accum.add(z[32]);
1210 ws[8] = accum.extract();
1211 accum.mul(ws[10], p[23]);
1212 accum.mul(ws[11], p[22]);
1213 accum.mul(ws[12], p[21]);
1214 accum.mul(ws[13], p[20]);
1215 accum.mul(ws[14], p[19]);
1216 accum.mul(ws[15], p[18]);
1217 accum.mul(ws[16], p[17]);
1218 accum.mul(ws[17], p[16]);
1219 accum.mul(ws[18], p[15]);
1220 accum.mul(ws[19], p[14]);
1221 accum.mul(ws[20], p[13]);
1222 accum.mul(ws[21], p[12]);
1223 accum.mul(ws[22], p[11]);
1224 accum.mul(ws[23], p[10]);
1225 accum.add(z[33]);
1226 ws[9] = accum.extract();
1227 accum.mul(ws[11], p[23]);
1228 accum.mul(ws[12], p[22]);
1229 accum.mul(ws[13], p[21]);
1230 accum.mul(ws[14], p[20]);
1231 accum.mul(ws[15], p[19]);
1232 accum.mul(ws[16], p[18]);
1233 accum.mul(ws[17], p[17]);
1234 accum.mul(ws[18], p[16]);
1235 accum.mul(ws[19], p[15]);
1236 accum.mul(ws[20], p[14]);
1237 accum.mul(ws[21], p[13]);
1238 accum.mul(ws[22], p[12]);
1239 accum.mul(ws[23], p[11]);
1240 accum.add(z[34]);
1241 ws[10] = accum.extract();
1242 accum.mul(ws[12], p[23]);
1243 accum.mul(ws[13], p[22]);
1244 accum.mul(ws[14], p[21]);
1245 accum.mul(ws[15], p[20]);
1246 accum.mul(ws[16], p[19]);
1247 accum.mul(ws[17], p[18]);
1248 accum.mul(ws[18], p[17]);
1249 accum.mul(ws[19], p[16]);
1250 accum.mul(ws[20], p[15]);
1251 accum.mul(ws[21], p[14]);
1252 accum.mul(ws[22], p[13]);
1253 accum.mul(ws[23], p[12]);
1254 accum.add(z[35]);
1255 ws[11] = accum.extract();
1256 accum.mul(ws[13], p[23]);
1257 accum.mul(ws[14], p[22]);
1258 accum.mul(ws[15], p[21]);
1259 accum.mul(ws[16], p[20]);
1260 accum.mul(ws[17], p[19]);
1261 accum.mul(ws[18], p[18]);
1262 accum.mul(ws[19], p[17]);
1263 accum.mul(ws[20], p[16]);
1264 accum.mul(ws[21], p[15]);
1265 accum.mul(ws[22], p[14]);
1266 accum.mul(ws[23], p[13]);
1267 accum.add(z[36]);
1268 ws[12] = accum.extract();
1269 accum.mul(ws[14], p[23]);
1270 accum.mul(ws[15], p[22]);
1271 accum.mul(ws[16], p[21]);
1272 accum.mul(ws[17], p[20]);
1273 accum.mul(ws[18], p[19]);
1274 accum.mul(ws[19], p[18]);
1275 accum.mul(ws[20], p[17]);
1276 accum.mul(ws[21], p[16]);
1277 accum.mul(ws[22], p[15]);
1278 accum.mul(ws[23], p[14]);
1279 accum.add(z[37]);
1280 ws[13] = accum.extract();
1281 accum.mul(ws[15], p[23]);
1282 accum.mul(ws[16], p[22]);
1283 accum.mul(ws[17], p[21]);
1284 accum.mul(ws[18], p[20]);
1285 accum.mul(ws[19], p[19]);
1286 accum.mul(ws[20], p[18]);
1287 accum.mul(ws[21], p[17]);
1288 accum.mul(ws[22], p[16]);
1289 accum.mul(ws[23], p[15]);
1290 accum.add(z[38]);
1291 ws[14] = accum.extract();
1292 accum.mul(ws[16], p[23]);
1293 accum.mul(ws[17], p[22]);
1294 accum.mul(ws[18], p[21]);
1295 accum.mul(ws[19], p[20]);
1296 accum.mul(ws[20], p[19]);
1297 accum.mul(ws[21], p[18]);
1298 accum.mul(ws[22], p[17]);
1299 accum.mul(ws[23], p[16]);
1300 accum.add(z[39]);
1301 ws[15] = accum.extract();
1302 accum.mul(ws[17], p[23]);
1303 accum.mul(ws[18], p[22]);
1304 accum.mul(ws[19], p[21]);
1305 accum.mul(ws[20], p[20]);
1306 accum.mul(ws[21], p[19]);
1307 accum.mul(ws[22], p[18]);
1308 accum.mul(ws[23], p[17]);
1309 accum.add(z[40]);
1310 ws[16] = accum.extract();
1311 accum.mul(ws[18], p[23]);
1312 accum.mul(ws[19], p[22]);
1313 accum.mul(ws[20], p[21]);
1314 accum.mul(ws[21], p[20]);
1315 accum.mul(ws[22], p[19]);
1316 accum.mul(ws[23], p[18]);
1317 accum.add(z[41]);
1318 ws[17] = accum.extract();
1319 accum.mul(ws[19], p[23]);
1320 accum.mul(ws[20], p[22]);
1321 accum.mul(ws[21], p[21]);
1322 accum.mul(ws[22], p[20]);
1323 accum.mul(ws[23], p[19]);
1324 accum.add(z[42]);
1325 ws[18] = accum.extract();
1326 accum.mul(ws[20], p[23]);
1327 accum.mul(ws[21], p[22]);
1328 accum.mul(ws[22], p[21]);
1329 accum.mul(ws[23], p[20]);
1330 accum.add(z[43]);
1331 ws[19] = accum.extract();
1332 accum.mul(ws[21], p[23]);
1333 accum.mul(ws[22], p[22]);
1334 accum.mul(ws[23], p[21]);
1335 accum.add(z[44]);
1336 ws[20] = accum.extract();
1337 accum.mul(ws[22], p[23]);
1338 accum.mul(ws[23], p[22]);
1339 accum.add(z[45]);
1340 ws[21] = accum.extract();
1341 accum.mul(ws[23], p[23]);
1342 accum.add(z[46]);
1343 ws[22] = accum.extract();
1344 accum.add(z[47]);
1345 ws[23] = accum.extract();
1346 const word w1 = accum.extract();
1347 bigint_monty_maybe_sub<24>(r, w1, ws, p);
1348}

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step(), and Botan::word3< W >::mul().

Referenced by bigint_monty_redc().

◆ bigint_monty_redc_32()

void Botan::bigint_monty_redc_32 ( word r[32],
const word z[64],
const word p[32],
word p_dash,
word ws[32] )

Definition at line 1350 of file mp_monty_n.cpp.

1350 {
1351 word3<word> accum;
1352 accum.add(z[0]);
1353 ws[0] = accum.monty_step(p[0], p_dash);
1354 accum.mul(ws[0], p[1]);
1355 accum.add(z[1]);
1356 ws[1] = accum.monty_step(p[0], p_dash);
1357 accum.mul(ws[0], p[2]);
1358 accum.mul(ws[1], p[1]);
1359 accum.add(z[2]);
1360 ws[2] = accum.monty_step(p[0], p_dash);
1361 accum.mul(ws[0], p[3]);
1362 accum.mul(ws[1], p[2]);
1363 accum.mul(ws[2], p[1]);
1364 accum.add(z[3]);
1365 ws[3] = accum.monty_step(p[0], p_dash);
1366 accum.mul(ws[0], p[4]);
1367 accum.mul(ws[1], p[3]);
1368 accum.mul(ws[2], p[2]);
1369 accum.mul(ws[3], p[1]);
1370 accum.add(z[4]);
1371 ws[4] = accum.monty_step(p[0], p_dash);
1372 accum.mul(ws[0], p[5]);
1373 accum.mul(ws[1], p[4]);
1374 accum.mul(ws[2], p[3]);
1375 accum.mul(ws[3], p[2]);
1376 accum.mul(ws[4], p[1]);
1377 accum.add(z[5]);
1378 ws[5] = accum.monty_step(p[0], p_dash);
1379 accum.mul(ws[0], p[6]);
1380 accum.mul(ws[1], p[5]);
1381 accum.mul(ws[2], p[4]);
1382 accum.mul(ws[3], p[3]);
1383 accum.mul(ws[4], p[2]);
1384 accum.mul(ws[5], p[1]);
1385 accum.add(z[6]);
1386 ws[6] = accum.monty_step(p[0], p_dash);
1387 accum.mul(ws[0], p[7]);
1388 accum.mul(ws[1], p[6]);
1389 accum.mul(ws[2], p[5]);
1390 accum.mul(ws[3], p[4]);
1391 accum.mul(ws[4], p[3]);
1392 accum.mul(ws[5], p[2]);
1393 accum.mul(ws[6], p[1]);
1394 accum.add(z[7]);
1395 ws[7] = accum.monty_step(p[0], p_dash);
1396 accum.mul(ws[0], p[8]);
1397 accum.mul(ws[1], p[7]);
1398 accum.mul(ws[2], p[6]);
1399 accum.mul(ws[3], p[5]);
1400 accum.mul(ws[4], p[4]);
1401 accum.mul(ws[5], p[3]);
1402 accum.mul(ws[6], p[2]);
1403 accum.mul(ws[7], p[1]);
1404 accum.add(z[8]);
1405 ws[8] = accum.monty_step(p[0], p_dash);
1406 accum.mul(ws[0], p[9]);
1407 accum.mul(ws[1], p[8]);
1408 accum.mul(ws[2], p[7]);
1409 accum.mul(ws[3], p[6]);
1410 accum.mul(ws[4], p[5]);
1411 accum.mul(ws[5], p[4]);
1412 accum.mul(ws[6], p[3]);
1413 accum.mul(ws[7], p[2]);
1414 accum.mul(ws[8], p[1]);
1415 accum.add(z[9]);
1416 ws[9] = accum.monty_step(p[0], p_dash);
1417 accum.mul(ws[0], p[10]);
1418 accum.mul(ws[1], p[9]);
1419 accum.mul(ws[2], p[8]);
1420 accum.mul(ws[3], p[7]);
1421 accum.mul(ws[4], p[6]);
1422 accum.mul(ws[5], p[5]);
1423 accum.mul(ws[6], p[4]);
1424 accum.mul(ws[7], p[3]);
1425 accum.mul(ws[8], p[2]);
1426 accum.mul(ws[9], p[1]);
1427 accum.add(z[10]);
1428 ws[10] = accum.monty_step(p[0], p_dash);
1429 accum.mul(ws[0], p[11]);
1430 accum.mul(ws[1], p[10]);
1431 accum.mul(ws[2], p[9]);
1432 accum.mul(ws[3], p[8]);
1433 accum.mul(ws[4], p[7]);
1434 accum.mul(ws[5], p[6]);
1435 accum.mul(ws[6], p[5]);
1436 accum.mul(ws[7], p[4]);
1437 accum.mul(ws[8], p[3]);
1438 accum.mul(ws[9], p[2]);
1439 accum.mul(ws[10], p[1]);
1440 accum.add(z[11]);
1441 ws[11] = accum.monty_step(p[0], p_dash);
1442 accum.mul(ws[0], p[12]);
1443 accum.mul(ws[1], p[11]);
1444 accum.mul(ws[2], p[10]);
1445 accum.mul(ws[3], p[9]);
1446 accum.mul(ws[4], p[8]);
1447 accum.mul(ws[5], p[7]);
1448 accum.mul(ws[6], p[6]);
1449 accum.mul(ws[7], p[5]);
1450 accum.mul(ws[8], p[4]);
1451 accum.mul(ws[9], p[3]);
1452 accum.mul(ws[10], p[2]);
1453 accum.mul(ws[11], p[1]);
1454 accum.add(z[12]);
1455 ws[12] = accum.monty_step(p[0], p_dash);
1456 accum.mul(ws[0], p[13]);
1457 accum.mul(ws[1], p[12]);
1458 accum.mul(ws[2], p[11]);
1459 accum.mul(ws[3], p[10]);
1460 accum.mul(ws[4], p[9]);
1461 accum.mul(ws[5], p[8]);
1462 accum.mul(ws[6], p[7]);
1463 accum.mul(ws[7], p[6]);
1464 accum.mul(ws[8], p[5]);
1465 accum.mul(ws[9], p[4]);
1466 accum.mul(ws[10], p[3]);
1467 accum.mul(ws[11], p[2]);
1468 accum.mul(ws[12], p[1]);
1469 accum.add(z[13]);
1470 ws[13] = accum.monty_step(p[0], p_dash);
1471 accum.mul(ws[0], p[14]);
1472 accum.mul(ws[1], p[13]);
1473 accum.mul(ws[2], p[12]);
1474 accum.mul(ws[3], p[11]);
1475 accum.mul(ws[4], p[10]);
1476 accum.mul(ws[5], p[9]);
1477 accum.mul(ws[6], p[8]);
1478 accum.mul(ws[7], p[7]);
1479 accum.mul(ws[8], p[6]);
1480 accum.mul(ws[9], p[5]);
1481 accum.mul(ws[10], p[4]);
1482 accum.mul(ws[11], p[3]);
1483 accum.mul(ws[12], p[2]);
1484 accum.mul(ws[13], p[1]);
1485 accum.add(z[14]);
1486 ws[14] = accum.monty_step(p[0], p_dash);
1487 accum.mul(ws[0], p[15]);
1488 accum.mul(ws[1], p[14]);
1489 accum.mul(ws[2], p[13]);
1490 accum.mul(ws[3], p[12]);
1491 accum.mul(ws[4], p[11]);
1492 accum.mul(ws[5], p[10]);
1493 accum.mul(ws[6], p[9]);
1494 accum.mul(ws[7], p[8]);
1495 accum.mul(ws[8], p[7]);
1496 accum.mul(ws[9], p[6]);
1497 accum.mul(ws[10], p[5]);
1498 accum.mul(ws[11], p[4]);
1499 accum.mul(ws[12], p[3]);
1500 accum.mul(ws[13], p[2]);
1501 accum.mul(ws[14], p[1]);
1502 accum.add(z[15]);
1503 ws[15] = accum.monty_step(p[0], p_dash);
1504 accum.mul(ws[0], p[16]);
1505 accum.mul(ws[1], p[15]);
1506 accum.mul(ws[2], p[14]);
1507 accum.mul(ws[3], p[13]);
1508 accum.mul(ws[4], p[12]);
1509 accum.mul(ws[5], p[11]);
1510 accum.mul(ws[6], p[10]);
1511 accum.mul(ws[7], p[9]);
1512 accum.mul(ws[8], p[8]);
1513 accum.mul(ws[9], p[7]);
1514 accum.mul(ws[10], p[6]);
1515 accum.mul(ws[11], p[5]);
1516 accum.mul(ws[12], p[4]);
1517 accum.mul(ws[13], p[3]);
1518 accum.mul(ws[14], p[2]);
1519 accum.mul(ws[15], p[1]);
1520 accum.add(z[16]);
1521 ws[16] = accum.monty_step(p[0], p_dash);
1522 accum.mul(ws[0], p[17]);
1523 accum.mul(ws[1], p[16]);
1524 accum.mul(ws[2], p[15]);
1525 accum.mul(ws[3], p[14]);
1526 accum.mul(ws[4], p[13]);
1527 accum.mul(ws[5], p[12]);
1528 accum.mul(ws[6], p[11]);
1529 accum.mul(ws[7], p[10]);
1530 accum.mul(ws[8], p[9]);
1531 accum.mul(ws[9], p[8]);
1532 accum.mul(ws[10], p[7]);
1533 accum.mul(ws[11], p[6]);
1534 accum.mul(ws[12], p[5]);
1535 accum.mul(ws[13], p[4]);
1536 accum.mul(ws[14], p[3]);
1537 accum.mul(ws[15], p[2]);
1538 accum.mul(ws[16], p[1]);
1539 accum.add(z[17]);
1540 ws[17] = accum.monty_step(p[0], p_dash);
1541 accum.mul(ws[0], p[18]);
1542 accum.mul(ws[1], p[17]);
1543 accum.mul(ws[2], p[16]);
1544 accum.mul(ws[3], p[15]);
1545 accum.mul(ws[4], p[14]);
1546 accum.mul(ws[5], p[13]);
1547 accum.mul(ws[6], p[12]);
1548 accum.mul(ws[7], p[11]);
1549 accum.mul(ws[8], p[10]);
1550 accum.mul(ws[9], p[9]);
1551 accum.mul(ws[10], p[8]);
1552 accum.mul(ws[11], p[7]);
1553 accum.mul(ws[12], p[6]);
1554 accum.mul(ws[13], p[5]);
1555 accum.mul(ws[14], p[4]);
1556 accum.mul(ws[15], p[3]);
1557 accum.mul(ws[16], p[2]);
1558 accum.mul(ws[17], p[1]);
1559 accum.add(z[18]);
1560 ws[18] = accum.monty_step(p[0], p_dash);
1561 accum.mul(ws[0], p[19]);
1562 accum.mul(ws[1], p[18]);
1563 accum.mul(ws[2], p[17]);
1564 accum.mul(ws[3], p[16]);
1565 accum.mul(ws[4], p[15]);
1566 accum.mul(ws[5], p[14]);
1567 accum.mul(ws[6], p[13]);
1568 accum.mul(ws[7], p[12]);
1569 accum.mul(ws[8], p[11]);
1570 accum.mul(ws[9], p[10]);
1571 accum.mul(ws[10], p[9]);
1572 accum.mul(ws[11], p[8]);
1573 accum.mul(ws[12], p[7]);
1574 accum.mul(ws[13], p[6]);
1575 accum.mul(ws[14], p[5]);
1576 accum.mul(ws[15], p[4]);
1577 accum.mul(ws[16], p[3]);
1578 accum.mul(ws[17], p[2]);
1579 accum.mul(ws[18], p[1]);
1580 accum.add(z[19]);
1581 ws[19] = accum.monty_step(p[0], p_dash);
1582 accum.mul(ws[0], p[20]);
1583 accum.mul(ws[1], p[19]);
1584 accum.mul(ws[2], p[18]);
1585 accum.mul(ws[3], p[17]);
1586 accum.mul(ws[4], p[16]);
1587 accum.mul(ws[5], p[15]);
1588 accum.mul(ws[6], p[14]);
1589 accum.mul(ws[7], p[13]);
1590 accum.mul(ws[8], p[12]);
1591 accum.mul(ws[9], p[11]);
1592 accum.mul(ws[10], p[10]);
1593 accum.mul(ws[11], p[9]);
1594 accum.mul(ws[12], p[8]);
1595 accum.mul(ws[13], p[7]);
1596 accum.mul(ws[14], p[6]);
1597 accum.mul(ws[15], p[5]);
1598 accum.mul(ws[16], p[4]);
1599 accum.mul(ws[17], p[3]);
1600 accum.mul(ws[18], p[2]);
1601 accum.mul(ws[19], p[1]);
1602 accum.add(z[20]);
1603 ws[20] = accum.monty_step(p[0], p_dash);
1604 accum.mul(ws[0], p[21]);
1605 accum.mul(ws[1], p[20]);
1606 accum.mul(ws[2], p[19]);
1607 accum.mul(ws[3], p[18]);
1608 accum.mul(ws[4], p[17]);
1609 accum.mul(ws[5], p[16]);
1610 accum.mul(ws[6], p[15]);
1611 accum.mul(ws[7], p[14]);
1612 accum.mul(ws[8], p[13]);
1613 accum.mul(ws[9], p[12]);
1614 accum.mul(ws[10], p[11]);
1615 accum.mul(ws[11], p[10]);
1616 accum.mul(ws[12], p[9]);
1617 accum.mul(ws[13], p[8]);
1618 accum.mul(ws[14], p[7]);
1619 accum.mul(ws[15], p[6]);
1620 accum.mul(ws[16], p[5]);
1621 accum.mul(ws[17], p[4]);
1622 accum.mul(ws[18], p[3]);
1623 accum.mul(ws[19], p[2]);
1624 accum.mul(ws[20], p[1]);
1625 accum.add(z[21]);
1626 ws[21] = accum.monty_step(p[0], p_dash);
1627 accum.mul(ws[0], p[22]);
1628 accum.mul(ws[1], p[21]);
1629 accum.mul(ws[2], p[20]);
1630 accum.mul(ws[3], p[19]);
1631 accum.mul(ws[4], p[18]);
1632 accum.mul(ws[5], p[17]);
1633 accum.mul(ws[6], p[16]);
1634 accum.mul(ws[7], p[15]);
1635 accum.mul(ws[8], p[14]);
1636 accum.mul(ws[9], p[13]);
1637 accum.mul(ws[10], p[12]);
1638 accum.mul(ws[11], p[11]);
1639 accum.mul(ws[12], p[10]);
1640 accum.mul(ws[13], p[9]);
1641 accum.mul(ws[14], p[8]);
1642 accum.mul(ws[15], p[7]);
1643 accum.mul(ws[16], p[6]);
1644 accum.mul(ws[17], p[5]);
1645 accum.mul(ws[18], p[4]);
1646 accum.mul(ws[19], p[3]);
1647 accum.mul(ws[20], p[2]);
1648 accum.mul(ws[21], p[1]);
1649 accum.add(z[22]);
1650 ws[22] = accum.monty_step(p[0], p_dash);
1651 accum.mul(ws[0], p[23]);
1652 accum.mul(ws[1], p[22]);
1653 accum.mul(ws[2], p[21]);
1654 accum.mul(ws[3], p[20]);
1655 accum.mul(ws[4], p[19]);
1656 accum.mul(ws[5], p[18]);
1657 accum.mul(ws[6], p[17]);
1658 accum.mul(ws[7], p[16]);
1659 accum.mul(ws[8], p[15]);
1660 accum.mul(ws[9], p[14]);
1661 accum.mul(ws[10], p[13]);
1662 accum.mul(ws[11], p[12]);
1663 accum.mul(ws[12], p[11]);
1664 accum.mul(ws[13], p[10]);
1665 accum.mul(ws[14], p[9]);
1666 accum.mul(ws[15], p[8]);
1667 accum.mul(ws[16], p[7]);
1668 accum.mul(ws[17], p[6]);
1669 accum.mul(ws[18], p[5]);
1670 accum.mul(ws[19], p[4]);
1671 accum.mul(ws[20], p[3]);
1672 accum.mul(ws[21], p[2]);
1673 accum.mul(ws[22], p[1]);
1674 accum.add(z[23]);
1675 ws[23] = accum.monty_step(p[0], p_dash);
1676 accum.mul(ws[0], p[24]);
1677 accum.mul(ws[1], p[23]);
1678 accum.mul(ws[2], p[22]);
1679 accum.mul(ws[3], p[21]);
1680 accum.mul(ws[4], p[20]);
1681 accum.mul(ws[5], p[19]);
1682 accum.mul(ws[6], p[18]);
1683 accum.mul(ws[7], p[17]);
1684 accum.mul(ws[8], p[16]);
1685 accum.mul(ws[9], p[15]);
1686 accum.mul(ws[10], p[14]);
1687 accum.mul(ws[11], p[13]);
1688 accum.mul(ws[12], p[12]);
1689 accum.mul(ws[13], p[11]);
1690 accum.mul(ws[14], p[10]);
1691 accum.mul(ws[15], p[9]);
1692 accum.mul(ws[16], p[8]);
1693 accum.mul(ws[17], p[7]);
1694 accum.mul(ws[18], p[6]);
1695 accum.mul(ws[19], p[5]);
1696 accum.mul(ws[20], p[4]);
1697 accum.mul(ws[21], p[3]);
1698 accum.mul(ws[22], p[2]);
1699 accum.mul(ws[23], p[1]);
1700 accum.add(z[24]);
1701 ws[24] = accum.monty_step(p[0], p_dash);
1702 accum.mul(ws[0], p[25]);
1703 accum.mul(ws[1], p[24]);
1704 accum.mul(ws[2], p[23]);
1705 accum.mul(ws[3], p[22]);
1706 accum.mul(ws[4], p[21]);
1707 accum.mul(ws[5], p[20]);
1708 accum.mul(ws[6], p[19]);
1709 accum.mul(ws[7], p[18]);
1710 accum.mul(ws[8], p[17]);
1711 accum.mul(ws[9], p[16]);
1712 accum.mul(ws[10], p[15]);
1713 accum.mul(ws[11], p[14]);
1714 accum.mul(ws[12], p[13]);
1715 accum.mul(ws[13], p[12]);
1716 accum.mul(ws[14], p[11]);
1717 accum.mul(ws[15], p[10]);
1718 accum.mul(ws[16], p[9]);
1719 accum.mul(ws[17], p[8]);
1720 accum.mul(ws[18], p[7]);
1721 accum.mul(ws[19], p[6]);
1722 accum.mul(ws[20], p[5]);
1723 accum.mul(ws[21], p[4]);
1724 accum.mul(ws[22], p[3]);
1725 accum.mul(ws[23], p[2]);
1726 accum.mul(ws[24], p[1]);
1727 accum.add(z[25]);
1728 ws[25] = accum.monty_step(p[0], p_dash);
1729 accum.mul(ws[0], p[26]);
1730 accum.mul(ws[1], p[25]);
1731 accum.mul(ws[2], p[24]);
1732 accum.mul(ws[3], p[23]);
1733 accum.mul(ws[4], p[22]);
1734 accum.mul(ws[5], p[21]);
1735 accum.mul(ws[6], p[20]);
1736 accum.mul(ws[7], p[19]);
1737 accum.mul(ws[8], p[18]);
1738 accum.mul(ws[9], p[17]);
1739 accum.mul(ws[10], p[16]);
1740 accum.mul(ws[11], p[15]);
1741 accum.mul(ws[12], p[14]);
1742 accum.mul(ws[13], p[13]);
1743 accum.mul(ws[14], p[12]);
1744 accum.mul(ws[15], p[11]);
1745 accum.mul(ws[16], p[10]);
1746 accum.mul(ws[17], p[9]);
1747 accum.mul(ws[18], p[8]);
1748 accum.mul(ws[19], p[7]);
1749 accum.mul(ws[20], p[6]);
1750 accum.mul(ws[21], p[5]);
1751 accum.mul(ws[22], p[4]);
1752 accum.mul(ws[23], p[3]);
1753 accum.mul(ws[24], p[2]);
1754 accum.mul(ws[25], p[1]);
1755 accum.add(z[26]);
1756 ws[26] = accum.monty_step(p[0], p_dash);
1757 accum.mul(ws[0], p[27]);
1758 accum.mul(ws[1], p[26]);
1759 accum.mul(ws[2], p[25]);
1760 accum.mul(ws[3], p[24]);
1761 accum.mul(ws[4], p[23]);
1762 accum.mul(ws[5], p[22]);
1763 accum.mul(ws[6], p[21]);
1764 accum.mul(ws[7], p[20]);
1765 accum.mul(ws[8], p[19]);
1766 accum.mul(ws[9], p[18]);
1767 accum.mul(ws[10], p[17]);
1768 accum.mul(ws[11], p[16]);
1769 accum.mul(ws[12], p[15]);
1770 accum.mul(ws[13], p[14]);
1771 accum.mul(ws[14], p[13]);
1772 accum.mul(ws[15], p[12]);
1773 accum.mul(ws[16], p[11]);
1774 accum.mul(ws[17], p[10]);
1775 accum.mul(ws[18], p[9]);
1776 accum.mul(ws[19], p[8]);
1777 accum.mul(ws[20], p[7]);
1778 accum.mul(ws[21], p[6]);
1779 accum.mul(ws[22], p[5]);
1780 accum.mul(ws[23], p[4]);
1781 accum.mul(ws[24], p[3]);
1782 accum.mul(ws[25], p[2]);
1783 accum.mul(ws[26], p[1]);
1784 accum.add(z[27]);
1785 ws[27] = accum.monty_step(p[0], p_dash);
1786 accum.mul(ws[0], p[28]);
1787 accum.mul(ws[1], p[27]);
1788 accum.mul(ws[2], p[26]);
1789 accum.mul(ws[3], p[25]);
1790 accum.mul(ws[4], p[24]);
1791 accum.mul(ws[5], p[23]);
1792 accum.mul(ws[6], p[22]);
1793 accum.mul(ws[7], p[21]);
1794 accum.mul(ws[8], p[20]);
1795 accum.mul(ws[9], p[19]);
1796 accum.mul(ws[10], p[18]);
1797 accum.mul(ws[11], p[17]);
1798 accum.mul(ws[12], p[16]);
1799 accum.mul(ws[13], p[15]);
1800 accum.mul(ws[14], p[14]);
1801 accum.mul(ws[15], p[13]);
1802 accum.mul(ws[16], p[12]);
1803 accum.mul(ws[17], p[11]);
1804 accum.mul(ws[18], p[10]);
1805 accum.mul(ws[19], p[9]);
1806 accum.mul(ws[20], p[8]);
1807 accum.mul(ws[21], p[7]);
1808 accum.mul(ws[22], p[6]);
1809 accum.mul(ws[23], p[5]);
1810 accum.mul(ws[24], p[4]);
1811 accum.mul(ws[25], p[3]);
1812 accum.mul(ws[26], p[2]);
1813 accum.mul(ws[27], p[1]);
1814 accum.add(z[28]);
1815 ws[28] = accum.monty_step(p[0], p_dash);
1816 accum.mul(ws[0], p[29]);
1817 accum.mul(ws[1], p[28]);
1818 accum.mul(ws[2], p[27]);
1819 accum.mul(ws[3], p[26]);
1820 accum.mul(ws[4], p[25]);
1821 accum.mul(ws[5], p[24]);
1822 accum.mul(ws[6], p[23]);
1823 accum.mul(ws[7], p[22]);
1824 accum.mul(ws[8], p[21]);
1825 accum.mul(ws[9], p[20]);
1826 accum.mul(ws[10], p[19]);
1827 accum.mul(ws[11], p[18]);
1828 accum.mul(ws[12], p[17]);
1829 accum.mul(ws[13], p[16]);
1830 accum.mul(ws[14], p[15]);
1831 accum.mul(ws[15], p[14]);
1832 accum.mul(ws[16], p[13]);
1833 accum.mul(ws[17], p[12]);
1834 accum.mul(ws[18], p[11]);
1835 accum.mul(ws[19], p[10]);
1836 accum.mul(ws[20], p[9]);
1837 accum.mul(ws[21], p[8]);
1838 accum.mul(ws[22], p[7]);
1839 accum.mul(ws[23], p[6]);
1840 accum.mul(ws[24], p[5]);
1841 accum.mul(ws[25], p[4]);
1842 accum.mul(ws[26], p[3]);
1843 accum.mul(ws[27], p[2]);
1844 accum.mul(ws[28], p[1]);
1845 accum.add(z[29]);
1846 ws[29] = accum.monty_step(p[0], p_dash);
1847 accum.mul(ws[0], p[30]);
1848 accum.mul(ws[1], p[29]);
1849 accum.mul(ws[2], p[28]);
1850 accum.mul(ws[3], p[27]);
1851 accum.mul(ws[4], p[26]);
1852 accum.mul(ws[5], p[25]);
1853 accum.mul(ws[6], p[24]);
1854 accum.mul(ws[7], p[23]);
1855 accum.mul(ws[8], p[22]);
1856 accum.mul(ws[9], p[21]);
1857 accum.mul(ws[10], p[20]);
1858 accum.mul(ws[11], p[19]);
1859 accum.mul(ws[12], p[18]);
1860 accum.mul(ws[13], p[17]);
1861 accum.mul(ws[14], p[16]);
1862 accum.mul(ws[15], p[15]);
1863 accum.mul(ws[16], p[14]);
1864 accum.mul(ws[17], p[13]);
1865 accum.mul(ws[18], p[12]);
1866 accum.mul(ws[19], p[11]);
1867 accum.mul(ws[20], p[10]);
1868 accum.mul(ws[21], p[9]);
1869 accum.mul(ws[22], p[8]);
1870 accum.mul(ws[23], p[7]);
1871 accum.mul(ws[24], p[6]);
1872 accum.mul(ws[25], p[5]);
1873 accum.mul(ws[26], p[4]);
1874 accum.mul(ws[27], p[3]);
1875 accum.mul(ws[28], p[2]);
1876 accum.mul(ws[29], p[1]);
1877 accum.add(z[30]);
1878 ws[30] = accum.monty_step(p[0], p_dash);
1879 accum.mul(ws[0], p[31]);
1880 accum.mul(ws[1], p[30]);
1881 accum.mul(ws[2], p[29]);
1882 accum.mul(ws[3], p[28]);
1883 accum.mul(ws[4], p[27]);
1884 accum.mul(ws[5], p[26]);
1885 accum.mul(ws[6], p[25]);
1886 accum.mul(ws[7], p[24]);
1887 accum.mul(ws[8], p[23]);
1888 accum.mul(ws[9], p[22]);
1889 accum.mul(ws[10], p[21]);
1890 accum.mul(ws[11], p[20]);
1891 accum.mul(ws[12], p[19]);
1892 accum.mul(ws[13], p[18]);
1893 accum.mul(ws[14], p[17]);
1894 accum.mul(ws[15], p[16]);
1895 accum.mul(ws[16], p[15]);
1896 accum.mul(ws[17], p[14]);
1897 accum.mul(ws[18], p[13]);
1898 accum.mul(ws[19], p[12]);
1899 accum.mul(ws[20], p[11]);
1900 accum.mul(ws[21], p[10]);
1901 accum.mul(ws[22], p[9]);
1902 accum.mul(ws[23], p[8]);
1903 accum.mul(ws[24], p[7]);
1904 accum.mul(ws[25], p[6]);
1905 accum.mul(ws[26], p[5]);
1906 accum.mul(ws[27], p[4]);
1907 accum.mul(ws[28], p[3]);
1908 accum.mul(ws[29], p[2]);
1909 accum.mul(ws[30], p[1]);
1910 accum.add(z[31]);
1911 ws[31] = accum.monty_step(p[0], p_dash);
1912 accum.mul(ws[1], p[31]);
1913 accum.mul(ws[2], p[30]);
1914 accum.mul(ws[3], p[29]);
1915 accum.mul(ws[4], p[28]);
1916 accum.mul(ws[5], p[27]);
1917 accum.mul(ws[6], p[26]);
1918 accum.mul(ws[7], p[25]);
1919 accum.mul(ws[8], p[24]);
1920 accum.mul(ws[9], p[23]);
1921 accum.mul(ws[10], p[22]);
1922 accum.mul(ws[11], p[21]);
1923 accum.mul(ws[12], p[20]);
1924 accum.mul(ws[13], p[19]);
1925 accum.mul(ws[14], p[18]);
1926 accum.mul(ws[15], p[17]);
1927 accum.mul(ws[16], p[16]);
1928 accum.mul(ws[17], p[15]);
1929 accum.mul(ws[18], p[14]);
1930 accum.mul(ws[19], p[13]);
1931 accum.mul(ws[20], p[12]);
1932 accum.mul(ws[21], p[11]);
1933 accum.mul(ws[22], p[10]);
1934 accum.mul(ws[23], p[9]);
1935 accum.mul(ws[24], p[8]);
1936 accum.mul(ws[25], p[7]);
1937 accum.mul(ws[26], p[6]);
1938 accum.mul(ws[27], p[5]);
1939 accum.mul(ws[28], p[4]);
1940 accum.mul(ws[29], p[3]);
1941 accum.mul(ws[30], p[2]);
1942 accum.mul(ws[31], p[1]);
1943 accum.add(z[32]);
1944 ws[0] = accum.extract();
1945 accum.mul(ws[2], p[31]);
1946 accum.mul(ws[3], p[30]);
1947 accum.mul(ws[4], p[29]);
1948 accum.mul(ws[5], p[28]);
1949 accum.mul(ws[6], p[27]);
1950 accum.mul(ws[7], p[26]);
1951 accum.mul(ws[8], p[25]);
1952 accum.mul(ws[9], p[24]);
1953 accum.mul(ws[10], p[23]);
1954 accum.mul(ws[11], p[22]);
1955 accum.mul(ws[12], p[21]);
1956 accum.mul(ws[13], p[20]);
1957 accum.mul(ws[14], p[19]);
1958 accum.mul(ws[15], p[18]);
1959 accum.mul(ws[16], p[17]);
1960 accum.mul(ws[17], p[16]);
1961 accum.mul(ws[18], p[15]);
1962 accum.mul(ws[19], p[14]);
1963 accum.mul(ws[20], p[13]);
1964 accum.mul(ws[21], p[12]);
1965 accum.mul(ws[22], p[11]);
1966 accum.mul(ws[23], p[10]);
1967 accum.mul(ws[24], p[9]);
1968 accum.mul(ws[25], p[8]);
1969 accum.mul(ws[26], p[7]);
1970 accum.mul(ws[27], p[6]);
1971 accum.mul(ws[28], p[5]);
1972 accum.mul(ws[29], p[4]);
1973 accum.mul(ws[30], p[3]);
1974 accum.mul(ws[31], p[2]);
1975 accum.add(z[33]);
1976 ws[1] = accum.extract();
1977 accum.mul(ws[3], p[31]);
1978 accum.mul(ws[4], p[30]);
1979 accum.mul(ws[5], p[29]);
1980 accum.mul(ws[6], p[28]);
1981 accum.mul(ws[7], p[27]);
1982 accum.mul(ws[8], p[26]);
1983 accum.mul(ws[9], p[25]);
1984 accum.mul(ws[10], p[24]);
1985 accum.mul(ws[11], p[23]);
1986 accum.mul(ws[12], p[22]);
1987 accum.mul(ws[13], p[21]);
1988 accum.mul(ws[14], p[20]);
1989 accum.mul(ws[15], p[19]);
1990 accum.mul(ws[16], p[18]);
1991 accum.mul(ws[17], p[17]);
1992 accum.mul(ws[18], p[16]);
1993 accum.mul(ws[19], p[15]);
1994 accum.mul(ws[20], p[14]);
1995 accum.mul(ws[21], p[13]);
1996 accum.mul(ws[22], p[12]);
1997 accum.mul(ws[23], p[11]);
1998 accum.mul(ws[24], p[10]);
1999 accum.mul(ws[25], p[9]);
2000 accum.mul(ws[26], p[8]);
2001 accum.mul(ws[27], p[7]);
2002 accum.mul(ws[28], p[6]);
2003 accum.mul(ws[29], p[5]);
2004 accum.mul(ws[30], p[4]);
2005 accum.mul(ws[31], p[3]);
2006 accum.add(z[34]);
2007 ws[2] = accum.extract();
2008 accum.mul(ws[4], p[31]);
2009 accum.mul(ws[5], p[30]);
2010 accum.mul(ws[6], p[29]);
2011 accum.mul(ws[7], p[28]);
2012 accum.mul(ws[8], p[27]);
2013 accum.mul(ws[9], p[26]);
2014 accum.mul(ws[10], p[25]);
2015 accum.mul(ws[11], p[24]);
2016 accum.mul(ws[12], p[23]);
2017 accum.mul(ws[13], p[22]);
2018 accum.mul(ws[14], p[21]);
2019 accum.mul(ws[15], p[20]);
2020 accum.mul(ws[16], p[19]);
2021 accum.mul(ws[17], p[18]);
2022 accum.mul(ws[18], p[17]);
2023 accum.mul(ws[19], p[16]);
2024 accum.mul(ws[20], p[15]);
2025 accum.mul(ws[21], p[14]);
2026 accum.mul(ws[22], p[13]);
2027 accum.mul(ws[23], p[12]);
2028 accum.mul(ws[24], p[11]);
2029 accum.mul(ws[25], p[10]);
2030 accum.mul(ws[26], p[9]);
2031 accum.mul(ws[27], p[8]);
2032 accum.mul(ws[28], p[7]);
2033 accum.mul(ws[29], p[6]);
2034 accum.mul(ws[30], p[5]);
2035 accum.mul(ws[31], p[4]);
2036 accum.add(z[35]);
2037 ws[3] = accum.extract();
2038 accum.mul(ws[5], p[31]);
2039 accum.mul(ws[6], p[30]);
2040 accum.mul(ws[7], p[29]);
2041 accum.mul(ws[8], p[28]);
2042 accum.mul(ws[9], p[27]);
2043 accum.mul(ws[10], p[26]);
2044 accum.mul(ws[11], p[25]);
2045 accum.mul(ws[12], p[24]);
2046 accum.mul(ws[13], p[23]);
2047 accum.mul(ws[14], p[22]);
2048 accum.mul(ws[15], p[21]);
2049 accum.mul(ws[16], p[20]);
2050 accum.mul(ws[17], p[19]);
2051 accum.mul(ws[18], p[18]);
2052 accum.mul(ws[19], p[17]);
2053 accum.mul(ws[20], p[16]);
2054 accum.mul(ws[21], p[15]);
2055 accum.mul(ws[22], p[14]);
2056 accum.mul(ws[23], p[13]);
2057 accum.mul(ws[24], p[12]);
2058 accum.mul(ws[25], p[11]);
2059 accum.mul(ws[26], p[10]);
2060 accum.mul(ws[27], p[9]);
2061 accum.mul(ws[28], p[8]);
2062 accum.mul(ws[29], p[7]);
2063 accum.mul(ws[30], p[6]);
2064 accum.mul(ws[31], p[5]);
2065 accum.add(z[36]);
2066 ws[4] = accum.extract();
2067 accum.mul(ws[6], p[31]);
2068 accum.mul(ws[7], p[30]);
2069 accum.mul(ws[8], p[29]);
2070 accum.mul(ws[9], p[28]);
2071 accum.mul(ws[10], p[27]);
2072 accum.mul(ws[11], p[26]);
2073 accum.mul(ws[12], p[25]);
2074 accum.mul(ws[13], p[24]);
2075 accum.mul(ws[14], p[23]);
2076 accum.mul(ws[15], p[22]);
2077 accum.mul(ws[16], p[21]);
2078 accum.mul(ws[17], p[20]);
2079 accum.mul(ws[18], p[19]);
2080 accum.mul(ws[19], p[18]);
2081 accum.mul(ws[20], p[17]);
2082 accum.mul(ws[21], p[16]);
2083 accum.mul(ws[22], p[15]);
2084 accum.mul(ws[23], p[14]);
2085 accum.mul(ws[24], p[13]);
2086 accum.mul(ws[25], p[12]);
2087 accum.mul(ws[26], p[11]);
2088 accum.mul(ws[27], p[10]);
2089 accum.mul(ws[28], p[9]);
2090 accum.mul(ws[29], p[8]);
2091 accum.mul(ws[30], p[7]);
2092 accum.mul(ws[31], p[6]);
2093 accum.add(z[37]);
2094 ws[5] = accum.extract();
2095 accum.mul(ws[7], p[31]);
2096 accum.mul(ws[8], p[30]);
2097 accum.mul(ws[9], p[29]);
2098 accum.mul(ws[10], p[28]);
2099 accum.mul(ws[11], p[27]);
2100 accum.mul(ws[12], p[26]);
2101 accum.mul(ws[13], p[25]);
2102 accum.mul(ws[14], p[24]);
2103 accum.mul(ws[15], p[23]);
2104 accum.mul(ws[16], p[22]);
2105 accum.mul(ws[17], p[21]);
2106 accum.mul(ws[18], p[20]);
2107 accum.mul(ws[19], p[19]);
2108 accum.mul(ws[20], p[18]);
2109 accum.mul(ws[21], p[17]);
2110 accum.mul(ws[22], p[16]);
2111 accum.mul(ws[23], p[15]);
2112 accum.mul(ws[24], p[14]);
2113 accum.mul(ws[25], p[13]);
2114 accum.mul(ws[26], p[12]);
2115 accum.mul(ws[27], p[11]);
2116 accum.mul(ws[28], p[10]);
2117 accum.mul(ws[29], p[9]);
2118 accum.mul(ws[30], p[8]);
2119 accum.mul(ws[31], p[7]);
2120 accum.add(z[38]);
2121 ws[6] = accum.extract();
2122 accum.mul(ws[8], p[31]);
2123 accum.mul(ws[9], p[30]);
2124 accum.mul(ws[10], p[29]);
2125 accum.mul(ws[11], p[28]);
2126 accum.mul(ws[12], p[27]);
2127 accum.mul(ws[13], p[26]);
2128 accum.mul(ws[14], p[25]);
2129 accum.mul(ws[15], p[24]);
2130 accum.mul(ws[16], p[23]);
2131 accum.mul(ws[17], p[22]);
2132 accum.mul(ws[18], p[21]);
2133 accum.mul(ws[19], p[20]);
2134 accum.mul(ws[20], p[19]);
2135 accum.mul(ws[21], p[18]);
2136 accum.mul(ws[22], p[17]);
2137 accum.mul(ws[23], p[16]);
2138 accum.mul(ws[24], p[15]);
2139 accum.mul(ws[25], p[14]);
2140 accum.mul(ws[26], p[13]);
2141 accum.mul(ws[27], p[12]);
2142 accum.mul(ws[28], p[11]);
2143 accum.mul(ws[29], p[10]);
2144 accum.mul(ws[30], p[9]);
2145 accum.mul(ws[31], p[8]);
2146 accum.add(z[39]);
2147 ws[7] = accum.extract();
2148 accum.mul(ws[9], p[31]);
2149 accum.mul(ws[10], p[30]);
2150 accum.mul(ws[11], p[29]);
2151 accum.mul(ws[12], p[28]);
2152 accum.mul(ws[13], p[27]);
2153 accum.mul(ws[14], p[26]);
2154 accum.mul(ws[15], p[25]);
2155 accum.mul(ws[16], p[24]);
2156 accum.mul(ws[17], p[23]);
2157 accum.mul(ws[18], p[22]);
2158 accum.mul(ws[19], p[21]);
2159 accum.mul(ws[20], p[20]);
2160 accum.mul(ws[21], p[19]);
2161 accum.mul(ws[22], p[18]);
2162 accum.mul(ws[23], p[17]);
2163 accum.mul(ws[24], p[16]);
2164 accum.mul(ws[25], p[15]);
2165 accum.mul(ws[26], p[14]);
2166 accum.mul(ws[27], p[13]);
2167 accum.mul(ws[28], p[12]);
2168 accum.mul(ws[29], p[11]);
2169 accum.mul(ws[30], p[10]);
2170 accum.mul(ws[31], p[9]);
2171 accum.add(z[40]);
2172 ws[8] = accum.extract();
2173 accum.mul(ws[10], p[31]);
2174 accum.mul(ws[11], p[30]);
2175 accum.mul(ws[12], p[29]);
2176 accum.mul(ws[13], p[28]);
2177 accum.mul(ws[14], p[27]);
2178 accum.mul(ws[15], p[26]);
2179 accum.mul(ws[16], p[25]);
2180 accum.mul(ws[17], p[24]);
2181 accum.mul(ws[18], p[23]);
2182 accum.mul(ws[19], p[22]);
2183 accum.mul(ws[20], p[21]);
2184 accum.mul(ws[21], p[20]);
2185 accum.mul(ws[22], p[19]);
2186 accum.mul(ws[23], p[18]);
2187 accum.mul(ws[24], p[17]);
2188 accum.mul(ws[25], p[16]);
2189 accum.mul(ws[26], p[15]);
2190 accum.mul(ws[27], p[14]);
2191 accum.mul(ws[28], p[13]);
2192 accum.mul(ws[29], p[12]);
2193 accum.mul(ws[30], p[11]);
2194 accum.mul(ws[31], p[10]);
2195 accum.add(z[41]);
2196 ws[9] = accum.extract();
2197 accum.mul(ws[11], p[31]);
2198 accum.mul(ws[12], p[30]);
2199 accum.mul(ws[13], p[29]);
2200 accum.mul(ws[14], p[28]);
2201 accum.mul(ws[15], p[27]);
2202 accum.mul(ws[16], p[26]);
2203 accum.mul(ws[17], p[25]);
2204 accum.mul(ws[18], p[24]);
2205 accum.mul(ws[19], p[23]);
2206 accum.mul(ws[20], p[22]);
2207 accum.mul(ws[21], p[21]);
2208 accum.mul(ws[22], p[20]);
2209 accum.mul(ws[23], p[19]);
2210 accum.mul(ws[24], p[18]);
2211 accum.mul(ws[25], p[17]);
2212 accum.mul(ws[26], p[16]);
2213 accum.mul(ws[27], p[15]);
2214 accum.mul(ws[28], p[14]);
2215 accum.mul(ws[29], p[13]);
2216 accum.mul(ws[30], p[12]);
2217 accum.mul(ws[31], p[11]);
2218 accum.add(z[42]);
2219 ws[10] = accum.extract();
2220 accum.mul(ws[12], p[31]);
2221 accum.mul(ws[13], p[30]);
2222 accum.mul(ws[14], p[29]);
2223 accum.mul(ws[15], p[28]);
2224 accum.mul(ws[16], p[27]);
2225 accum.mul(ws[17], p[26]);
2226 accum.mul(ws[18], p[25]);
2227 accum.mul(ws[19], p[24]);
2228 accum.mul(ws[20], p[23]);
2229 accum.mul(ws[21], p[22]);
2230 accum.mul(ws[22], p[21]);
2231 accum.mul(ws[23], p[20]);
2232 accum.mul(ws[24], p[19]);
2233 accum.mul(ws[25], p[18]);
2234 accum.mul(ws[26], p[17]);
2235 accum.mul(ws[27], p[16]);
2236 accum.mul(ws[28], p[15]);
2237 accum.mul(ws[29], p[14]);
2238 accum.mul(ws[30], p[13]);
2239 accum.mul(ws[31], p[12]);
2240 accum.add(z[43]);
2241 ws[11] = accum.extract();
2242 accum.mul(ws[13], p[31]);
2243 accum.mul(ws[14], p[30]);
2244 accum.mul(ws[15], p[29]);
2245 accum.mul(ws[16], p[28]);
2246 accum.mul(ws[17], p[27]);
2247 accum.mul(ws[18], p[26]);
2248 accum.mul(ws[19], p[25]);
2249 accum.mul(ws[20], p[24]);
2250 accum.mul(ws[21], p[23]);
2251 accum.mul(ws[22], p[22]);
2252 accum.mul(ws[23], p[21]);
2253 accum.mul(ws[24], p[20]);
2254 accum.mul(ws[25], p[19]);
2255 accum.mul(ws[26], p[18]);
2256 accum.mul(ws[27], p[17]);
2257 accum.mul(ws[28], p[16]);
2258 accum.mul(ws[29], p[15]);
2259 accum.mul(ws[30], p[14]);
2260 accum.mul(ws[31], p[13]);
2261 accum.add(z[44]);
2262 ws[12] = accum.extract();
2263 accum.mul(ws[14], p[31]);
2264 accum.mul(ws[15], p[30]);
2265 accum.mul(ws[16], p[29]);
2266 accum.mul(ws[17], p[28]);
2267 accum.mul(ws[18], p[27]);
2268 accum.mul(ws[19], p[26]);
2269 accum.mul(ws[20], p[25]);
2270 accum.mul(ws[21], p[24]);
2271 accum.mul(ws[22], p[23]);
2272 accum.mul(ws[23], p[22]);
2273 accum.mul(ws[24], p[21]);
2274 accum.mul(ws[25], p[20]);
2275 accum.mul(ws[26], p[19]);
2276 accum.mul(ws[27], p[18]);
2277 accum.mul(ws[28], p[17]);
2278 accum.mul(ws[29], p[16]);
2279 accum.mul(ws[30], p[15]);
2280 accum.mul(ws[31], p[14]);
2281 accum.add(z[45]);
2282 ws[13] = accum.extract();
2283 accum.mul(ws[15], p[31]);
2284 accum.mul(ws[16], p[30]);
2285 accum.mul(ws[17], p[29]);
2286 accum.mul(ws[18], p[28]);
2287 accum.mul(ws[19], p[27]);
2288 accum.mul(ws[20], p[26]);
2289 accum.mul(ws[21], p[25]);
2290 accum.mul(ws[22], p[24]);
2291 accum.mul(ws[23], p[23]);
2292 accum.mul(ws[24], p[22]);
2293 accum.mul(ws[25], p[21]);
2294 accum.mul(ws[26], p[20]);
2295 accum.mul(ws[27], p[19]);
2296 accum.mul(ws[28], p[18]);
2297 accum.mul(ws[29], p[17]);
2298 accum.mul(ws[30], p[16]);
2299 accum.mul(ws[31], p[15]);
2300 accum.add(z[46]);
2301 ws[14] = accum.extract();
2302 accum.mul(ws[16], p[31]);
2303 accum.mul(ws[17], p[30]);
2304 accum.mul(ws[18], p[29]);
2305 accum.mul(ws[19], p[28]);
2306 accum.mul(ws[20], p[27]);
2307 accum.mul(ws[21], p[26]);
2308 accum.mul(ws[22], p[25]);
2309 accum.mul(ws[23], p[24]);
2310 accum.mul(ws[24], p[23]);
2311 accum.mul(ws[25], p[22]);
2312 accum.mul(ws[26], p[21]);
2313 accum.mul(ws[27], p[20]);
2314 accum.mul(ws[28], p[19]);
2315 accum.mul(ws[29], p[18]);
2316 accum.mul(ws[30], p[17]);
2317 accum.mul(ws[31], p[16]);
2318 accum.add(z[47]);
2319 ws[15] = accum.extract();
2320 accum.mul(ws[17], p[31]);
2321 accum.mul(ws[18], p[30]);
2322 accum.mul(ws[19], p[29]);
2323 accum.mul(ws[20], p[28]);
2324 accum.mul(ws[21], p[27]);
2325 accum.mul(ws[22], p[26]);
2326 accum.mul(ws[23], p[25]);
2327 accum.mul(ws[24], p[24]);
2328 accum.mul(ws[25], p[23]);
2329 accum.mul(ws[26], p[22]);
2330 accum.mul(ws[27], p[21]);
2331 accum.mul(ws[28], p[20]);
2332 accum.mul(ws[29], p[19]);
2333 accum.mul(ws[30], p[18]);
2334 accum.mul(ws[31], p[17]);
2335 accum.add(z[48]);
2336 ws[16] = accum.extract();
2337 accum.mul(ws[18], p[31]);
2338 accum.mul(ws[19], p[30]);
2339 accum.mul(ws[20], p[29]);
2340 accum.mul(ws[21], p[28]);
2341 accum.mul(ws[22], p[27]);
2342 accum.mul(ws[23], p[26]);
2343 accum.mul(ws[24], p[25]);
2344 accum.mul(ws[25], p[24]);
2345 accum.mul(ws[26], p[23]);
2346 accum.mul(ws[27], p[22]);
2347 accum.mul(ws[28], p[21]);
2348 accum.mul(ws[29], p[20]);
2349 accum.mul(ws[30], p[19]);
2350 accum.mul(ws[31], p[18]);
2351 accum.add(z[49]);
2352 ws[17] = accum.extract();
2353 accum.mul(ws[19], p[31]);
2354 accum.mul(ws[20], p[30]);
2355 accum.mul(ws[21], p[29]);
2356 accum.mul(ws[22], p[28]);
2357 accum.mul(ws[23], p[27]);
2358 accum.mul(ws[24], p[26]);
2359 accum.mul(ws[25], p[25]);
2360 accum.mul(ws[26], p[24]);
2361 accum.mul(ws[27], p[23]);
2362 accum.mul(ws[28], p[22]);
2363 accum.mul(ws[29], p[21]);
2364 accum.mul(ws[30], p[20]);
2365 accum.mul(ws[31], p[19]);
2366 accum.add(z[50]);
2367 ws[18] = accum.extract();
2368 accum.mul(ws[20], p[31]);
2369 accum.mul(ws[21], p[30]);
2370 accum.mul(ws[22], p[29]);
2371 accum.mul(ws[23], p[28]);
2372 accum.mul(ws[24], p[27]);
2373 accum.mul(ws[25], p[26]);
2374 accum.mul(ws[26], p[25]);
2375 accum.mul(ws[27], p[24]);
2376 accum.mul(ws[28], p[23]);
2377 accum.mul(ws[29], p[22]);
2378 accum.mul(ws[30], p[21]);
2379 accum.mul(ws[31], p[20]);
2380 accum.add(z[51]);
2381 ws[19] = accum.extract();
2382 accum.mul(ws[21], p[31]);
2383 accum.mul(ws[22], p[30]);
2384 accum.mul(ws[23], p[29]);
2385 accum.mul(ws[24], p[28]);
2386 accum.mul(ws[25], p[27]);
2387 accum.mul(ws[26], p[26]);
2388 accum.mul(ws[27], p[25]);
2389 accum.mul(ws[28], p[24]);
2390 accum.mul(ws[29], p[23]);
2391 accum.mul(ws[30], p[22]);
2392 accum.mul(ws[31], p[21]);
2393 accum.add(z[52]);
2394 ws[20] = accum.extract();
2395 accum.mul(ws[22], p[31]);
2396 accum.mul(ws[23], p[30]);
2397 accum.mul(ws[24], p[29]);
2398 accum.mul(ws[25], p[28]);
2399 accum.mul(ws[26], p[27]);
2400 accum.mul(ws[27], p[26]);
2401 accum.mul(ws[28], p[25]);
2402 accum.mul(ws[29], p[24]);
2403 accum.mul(ws[30], p[23]);
2404 accum.mul(ws[31], p[22]);
2405 accum.add(z[53]);
2406 ws[21] = accum.extract();
2407 accum.mul(ws[23], p[31]);
2408 accum.mul(ws[24], p[30]);
2409 accum.mul(ws[25], p[29]);
2410 accum.mul(ws[26], p[28]);
2411 accum.mul(ws[27], p[27]);
2412 accum.mul(ws[28], p[26]);
2413 accum.mul(ws[29], p[25]);
2414 accum.mul(ws[30], p[24]);
2415 accum.mul(ws[31], p[23]);
2416 accum.add(z[54]);
2417 ws[22] = accum.extract();
2418 accum.mul(ws[24], p[31]);
2419 accum.mul(ws[25], p[30]);
2420 accum.mul(ws[26], p[29]);
2421 accum.mul(ws[27], p[28]);
2422 accum.mul(ws[28], p[27]);
2423 accum.mul(ws[29], p[26]);
2424 accum.mul(ws[30], p[25]);
2425 accum.mul(ws[31], p[24]);
2426 accum.add(z[55]);
2427 ws[23] = accum.extract();
2428 accum.mul(ws[25], p[31]);
2429 accum.mul(ws[26], p[30]);
2430 accum.mul(ws[27], p[29]);
2431 accum.mul(ws[28], p[28]);
2432 accum.mul(ws[29], p[27]);
2433 accum.mul(ws[30], p[26]);
2434 accum.mul(ws[31], p[25]);
2435 accum.add(z[56]);
2436 ws[24] = accum.extract();
2437 accum.mul(ws[26], p[31]);
2438 accum.mul(ws[27], p[30]);
2439 accum.mul(ws[28], p[29]);
2440 accum.mul(ws[29], p[28]);
2441 accum.mul(ws[30], p[27]);
2442 accum.mul(ws[31], p[26]);
2443 accum.add(z[57]);
2444 ws[25] = accum.extract();
2445 accum.mul(ws[27], p[31]);
2446 accum.mul(ws[28], p[30]);
2447 accum.mul(ws[29], p[29]);
2448 accum.mul(ws[30], p[28]);
2449 accum.mul(ws[31], p[27]);
2450 accum.add(z[58]);
2451 ws[26] = accum.extract();
2452 accum.mul(ws[28], p[31]);
2453 accum.mul(ws[29], p[30]);
2454 accum.mul(ws[30], p[29]);
2455 accum.mul(ws[31], p[28]);
2456 accum.add(z[59]);
2457 ws[27] = accum.extract();
2458 accum.mul(ws[29], p[31]);
2459 accum.mul(ws[30], p[30]);
2460 accum.mul(ws[31], p[29]);
2461 accum.add(z[60]);
2462 ws[28] = accum.extract();
2463 accum.mul(ws[30], p[31]);
2464 accum.mul(ws[31], p[30]);
2465 accum.add(z[61]);
2466 ws[29] = accum.extract();
2467 accum.mul(ws[31], p[31]);
2468 accum.add(z[62]);
2469 ws[30] = accum.extract();
2470 accum.add(z[63]);
2471 ws[31] = accum.extract();
2472 const word w1 = accum.extract();
2473 bigint_monty_maybe_sub<32>(r, w1, ws, p);
2474}

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step(), and Botan::word3< W >::mul().

Referenced by bigint_monty_redc().

◆ bigint_monty_redc_4()

void Botan::bigint_monty_redc_4 ( word r[4],
const word z[8],
const word p[4],
word p_dash,
word ws[4] )

Definition at line 12 of file mp_monty_n.cpp.

12 {
13 word3<word> accum;
14 accum.add(z[0]);
15 ws[0] = accum.monty_step(p[0], p_dash);
16 accum.mul(ws[0], p[1]);
17 accum.add(z[1]);
18 ws[1] = accum.monty_step(p[0], p_dash);
19 accum.mul(ws[0], p[2]);
20 accum.mul(ws[1], p[1]);
21 accum.add(z[2]);
22 ws[2] = accum.monty_step(p[0], p_dash);
23 accum.mul(ws[0], p[3]);
24 accum.mul(ws[1], p[2]);
25 accum.mul(ws[2], p[1]);
26 accum.add(z[3]);
27 ws[3] = accum.monty_step(p[0], p_dash);
28 accum.mul(ws[1], p[3]);
29 accum.mul(ws[2], p[2]);
30 accum.mul(ws[3], p[1]);
31 accum.add(z[4]);
32 ws[0] = accum.extract();
33 accum.mul(ws[2], p[3]);
34 accum.mul(ws[3], p[2]);
35 accum.add(z[5]);
36 ws[1] = accum.extract();
37 accum.mul(ws[3], p[3]);
38 accum.add(z[6]);
39 ws[2] = accum.extract();
40 accum.add(z[7]);
41 ws[3] = accum.extract();
42 const word w1 = accum.extract();
43 bigint_monty_maybe_sub<4>(r, w1, ws, p);
44}

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step(), and Botan::word3< W >::mul().

Referenced by bigint_monty_redc(), and monty_redc().

◆ bigint_monty_redc_6()

void Botan::bigint_monty_redc_6 ( word r[6],
const word z[12],
const word p[6],
word p_dash,
word ws[6] )

Definition at line 46 of file mp_monty_n.cpp.

46 {
47 word3<word> accum;
48 accum.add(z[0]);
49 ws[0] = accum.monty_step(p[0], p_dash);
50 accum.mul(ws[0], p[1]);
51 accum.add(z[1]);
52 ws[1] = accum.monty_step(p[0], p_dash);
53 accum.mul(ws[0], p[2]);
54 accum.mul(ws[1], p[1]);
55 accum.add(z[2]);
56 ws[2] = accum.monty_step(p[0], p_dash);
57 accum.mul(ws[0], p[3]);
58 accum.mul(ws[1], p[2]);
59 accum.mul(ws[2], p[1]);
60 accum.add(z[3]);
61 ws[3] = accum.monty_step(p[0], p_dash);
62 accum.mul(ws[0], p[4]);
63 accum.mul(ws[1], p[3]);
64 accum.mul(ws[2], p[2]);
65 accum.mul(ws[3], p[1]);
66 accum.add(z[4]);
67 ws[4] = accum.monty_step(p[0], p_dash);
68 accum.mul(ws[0], p[5]);
69 accum.mul(ws[1], p[4]);
70 accum.mul(ws[2], p[3]);
71 accum.mul(ws[3], p[2]);
72 accum.mul(ws[4], p[1]);
73 accum.add(z[5]);
74 ws[5] = accum.monty_step(p[0], p_dash);
75 accum.mul(ws[1], p[5]);
76 accum.mul(ws[2], p[4]);
77 accum.mul(ws[3], p[3]);
78 accum.mul(ws[4], p[2]);
79 accum.mul(ws[5], p[1]);
80 accum.add(z[6]);
81 ws[0] = accum.extract();
82 accum.mul(ws[2], p[5]);
83 accum.mul(ws[3], p[4]);
84 accum.mul(ws[4], p[3]);
85 accum.mul(ws[5], p[2]);
86 accum.add(z[7]);
87 ws[1] = accum.extract();
88 accum.mul(ws[3], p[5]);
89 accum.mul(ws[4], p[4]);
90 accum.mul(ws[5], p[3]);
91 accum.add(z[8]);
92 ws[2] = accum.extract();
93 accum.mul(ws[4], p[5]);
94 accum.mul(ws[5], p[4]);
95 accum.add(z[9]);
96 ws[3] = accum.extract();
97 accum.mul(ws[5], p[5]);
98 accum.add(z[10]);
99 ws[4] = accum.extract();
100 accum.add(z[11]);
101 ws[5] = accum.extract();
102 const word w1 = accum.extract();
103 bigint_monty_maybe_sub<6>(r, w1, ws, p);
104}

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step(), and Botan::word3< W >::mul().

Referenced by bigint_monty_redc(), and monty_redc().

◆ bigint_monty_redc_8()

void Botan::bigint_monty_redc_8 ( word r[8],
const word z[16],
const word p[8],
word p_dash,
word ws[8] )

Definition at line 106 of file mp_monty_n.cpp.

106 {
107 word3<word> accum;
108 accum.add(z[0]);
109 ws[0] = accum.monty_step(p[0], p_dash);
110 accum.mul(ws[0], p[1]);
111 accum.add(z[1]);
112 ws[1] = accum.monty_step(p[0], p_dash);
113 accum.mul(ws[0], p[2]);
114 accum.mul(ws[1], p[1]);
115 accum.add(z[2]);
116 ws[2] = accum.monty_step(p[0], p_dash);
117 accum.mul(ws[0], p[3]);
118 accum.mul(ws[1], p[2]);
119 accum.mul(ws[2], p[1]);
120 accum.add(z[3]);
121 ws[3] = accum.monty_step(p[0], p_dash);
122 accum.mul(ws[0], p[4]);
123 accum.mul(ws[1], p[3]);
124 accum.mul(ws[2], p[2]);
125 accum.mul(ws[3], p[1]);
126 accum.add(z[4]);
127 ws[4] = accum.monty_step(p[0], p_dash);
128 accum.mul(ws[0], p[5]);
129 accum.mul(ws[1], p[4]);
130 accum.mul(ws[2], p[3]);
131 accum.mul(ws[3], p[2]);
132 accum.mul(ws[4], p[1]);
133 accum.add(z[5]);
134 ws[5] = accum.monty_step(p[0], p_dash);
135 accum.mul(ws[0], p[6]);
136 accum.mul(ws[1], p[5]);
137 accum.mul(ws[2], p[4]);
138 accum.mul(ws[3], p[3]);
139 accum.mul(ws[4], p[2]);
140 accum.mul(ws[5], p[1]);
141 accum.add(z[6]);
142 ws[6] = accum.monty_step(p[0], p_dash);
143 accum.mul(ws[0], p[7]);
144 accum.mul(ws[1], p[6]);
145 accum.mul(ws[2], p[5]);
146 accum.mul(ws[3], p[4]);
147 accum.mul(ws[4], p[3]);
148 accum.mul(ws[5], p[2]);
149 accum.mul(ws[6], p[1]);
150 accum.add(z[7]);
151 ws[7] = accum.monty_step(p[0], p_dash);
152 accum.mul(ws[1], p[7]);
153 accum.mul(ws[2], p[6]);
154 accum.mul(ws[3], p[5]);
155 accum.mul(ws[4], p[4]);
156 accum.mul(ws[5], p[3]);
157 accum.mul(ws[6], p[2]);
158 accum.mul(ws[7], p[1]);
159 accum.add(z[8]);
160 ws[0] = accum.extract();
161 accum.mul(ws[2], p[7]);
162 accum.mul(ws[3], p[6]);
163 accum.mul(ws[4], p[5]);
164 accum.mul(ws[5], p[4]);
165 accum.mul(ws[6], p[3]);
166 accum.mul(ws[7], p[2]);
167 accum.add(z[9]);
168 ws[1] = accum.extract();
169 accum.mul(ws[3], p[7]);
170 accum.mul(ws[4], p[6]);
171 accum.mul(ws[5], p[5]);
172 accum.mul(ws[6], p[4]);
173 accum.mul(ws[7], p[3]);
174 accum.add(z[10]);
175 ws[2] = accum.extract();
176 accum.mul(ws[4], p[7]);
177 accum.mul(ws[5], p[6]);
178 accum.mul(ws[6], p[5]);
179 accum.mul(ws[7], p[4]);
180 accum.add(z[11]);
181 ws[3] = accum.extract();
182 accum.mul(ws[5], p[7]);
183 accum.mul(ws[6], p[6]);
184 accum.mul(ws[7], p[5]);
185 accum.add(z[12]);
186 ws[4] = accum.extract();
187 accum.mul(ws[6], p[7]);
188 accum.mul(ws[7], p[6]);
189 accum.add(z[13]);
190 ws[5] = accum.extract();
191 accum.mul(ws[7], p[7]);
192 accum.add(z[14]);
193 ws[6] = accum.extract();
194 accum.add(z[15]);
195 ws[7] = accum.extract();
196 const word w1 = accum.extract();
197 bigint_monty_maybe_sub<8>(r, w1, ws, p);
198}

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step(), and Botan::word3< W >::mul().

Referenced by bigint_monty_redc(), and monty_redc().

◆ bigint_monty_redc_generic()

void Botan::bigint_monty_redc_generic ( word r[],
const word z[],
size_t z_size,
const word p[],
size_t p_size,
word p_dash,
word ws[] )

Definition at line 94 of file mp_monty.cpp.

95 {
96 BOTAN_ARG_CHECK(z_size >= 2 * p_size && p_size > 0, "Invalid sizes for bigint_monty_redc_generic");
97
98 word3<word> accum;
99
100 accum.add(z[0]);
101
102 ws[0] = accum.monty_step(p[0], p_dash);
103
104 for(size_t i = 1; i != p_size; ++i) {
105 mul_rev_range(accum, ws, p, i);
106 accum.add(z[i]);
107 ws[i] = accum.monty_step(p[0], p_dash);
108 }
109
110 for(size_t i = 0; i != p_size - 1; ++i) {
111 mul_rev_range(accum, &ws[i + 1], &p[i], p_size - (i + 1));
112 accum.add(z[p_size + i]);
113 ws[i] = accum.extract();
114 }
115
116 accum.add(z[2 * p_size - 1]);
117
118 ws[p_size - 1] = accum.extract();
119 // w1 is the final part, which is not stored in the workspace
120 const word w1 = accum.extract();
121
122 /*
123 * The result might need to be reduced mod p. To avoid a timing
124 * channel, always perform the subtraction. If in the computation
125 * of x - p a borrow is required then x was already < p.
126 *
127 * x starts at ws[0] and is p_size bytes long plus a possible high
128 * digit left over in w1.
129 *
130 * x - p starts at z[0] and is also p_size bytes long
131 *
132 * If borrow was set after the subtraction, then x was already less
133 * than p and the subtraction was not needed. In that case overwrite
134 * z[0:p_size] with the original x in ws[0:p_size].
135 *
136 * We only copy out p_size in the final step because we know
137 * the Montgomery result is < P
138 */
139
140 bigint_monty_maybe_sub(p_size, r, w1, ws, p);
141}

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), BOTAN_ARG_CHECK, Botan::word3< W >::extract(), and Botan::word3< W >::monty_step().

Referenced by bigint_monty_redc().

◆ bigint_monty_redc_inplace()

void Botan::bigint_monty_redc_inplace ( word z[],
const word p[],
size_t p_size,
word p_dash,
word ws[],
size_t ws_size )
inline

◆ bigint_monty_sqr()

void Botan::bigint_monty_sqr ( word z[],
const word x[],
const word p[],
size_t p_size,
word p_dash,
word ws[],
size_t ws_size )

Montgomery squaring

Computes z[0..p_size) = x*x/R mod p, where R = 2^(p_size * word bits), and x is p_size words and less than p. z may alias x.

ws must be at least 4*p_size words

Definition at line 159 of file mp_monty.cpp.

159 {
160 BOTAN_ARG_CHECK(ws_size >= 4 * p_size && p_size > 0, "Invalid workspace for Montgomery squaring");
161
162 word* prod = ws;
163
164#if defined(BOTAN_HAS_MP_MULX)
165 if(use_mulx_monty(p_size)) {
166 return bigint_mulx_monty_sqr(z, x, p, p_size, p_dash, ws);
167 }
168#endif
169
170 word* mul_ws = ws + 2 * p_size;
171 bigint_sqr(prod, 2 * p_size, x, p_size, p_size, mul_ws, 2 * p_size);
172 bigint_monty_redc(z, prod, p, p_size, p_dash, mul_ws, 2 * p_size);
173}
void bigint_sqr(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, word workspace[], size_t ws_size)
Definition mp_karat.cpp:327
void bigint_mulx_monty_sqr(word z[], const word x[], const word p[], size_t N, word p_dash, word ws[])

References bigint_monty_redc(), bigint_mulx_monty_sqr(), bigint_sqr(), BOTAN_ARG_CHECK, and use_mulx_monty().

Referenced by Botan::Montgomery_Int::square_this_n_times().

◆ bigint_mul()

void Botan::bigint_mul ( word z[],
size_t z_size,
const word x[],
size_t x_size,
size_t x_sw,
const word y[],
size_t y_size,
size_t y_sw,
word workspace[],
size_t ws_size )

Definition at line 283 of file mp_karat.cpp.

292 {
293 zeroize_buffer(z, z_size);
294
295 if(x_sw == 1) {
296 bigint_linmul3(z, y, y_sw, x[0]);
297 } else if(y_sw == 1) {
298 bigint_linmul3(z, x, x_sw, y[0]);
299 } else if(sized_for_comba_mul<4>(x_sw, x_size, y_sw, y_size, z_size)) {
300 bigint_comba_mul4(z, x, y);
301 } else if(sized_for_comba_mul<6>(x_sw, x_size, y_sw, y_size, z_size)) {
302 bigint_comba_mul6(z, x, y);
303 } else if(sized_for_comba_mul<8>(x_sw, x_size, y_sw, y_size, z_size)) {
304 bigint_comba_mul8(z, x, y);
305 } else if(sized_for_comba_mul<9>(x_sw, x_size, y_sw, y_size, z_size)) {
306 bigint_comba_mul9(z, x, y);
307 } else if(sized_for_comba_mul<16>(x_sw, x_size, y_sw, y_size, z_size)) {
308 bigint_comba_mul16(z, x, y);
309 } else if(sized_for_comba_mul<24>(x_sw, x_size, y_sw, y_size, z_size)) {
310 bigint_comba_mul24(z, x, y);
311 } else if(x_sw < KARATSUBA_MULTIPLY_THRESHOLD || y_sw < KARATSUBA_MULTIPLY_THRESHOLD || workspace == nullptr) {
312 basecase_mul(z, z_size, x, x_sw, y, y_sw);
313 } else {
314 const size_t N = karatsuba_size(z_size, x_size, x_sw, y_size, y_sw);
315
316 if(N > 0 && z_size >= 2 * N && ws_size >= 2 * N) {
317 karatsuba_mul(z, x, y, N, workspace);
318 } else {
319 basecase_mul(z, z_size, x, x_sw, y, y_sw);
320 }
321 }
322}
constexpr void bigint_linmul3(W z[], const W x[], size_t x_size, W y)
Definition mp_core.h:420
void bigint_comba_mul4(word z[8], const word x[4], const word y[4])
Definition mp_comba.cpp:54
void bigint_comba_mul16(word z[32], const word x[16], const word y[16])
Definition mp_comba.cpp:848
void bigint_comba_mul6(word z[12], const word x[6], const word y[6])
Definition mp_comba.cpp:139
void bigint_comba_mul9(word z[18], const word x[9], const word y[9])
Definition mp_comba.cpp:559
void bigint_comba_mul24(word z[48], const word x[24], const word y[24])
BOTAN_FUZZER_API void basecase_mul(word z[], size_t z_size, const word x[], size_t x_size, const word y[], size_t y_size)
Definition mp_karat.cpp:20
void bigint_comba_mul8(word z[16], const word x[8], const word y[8])
Definition mp_comba.cpp:388

References basecase_mul(), bigint_comba_mul16(), bigint_comba_mul24(), bigint_comba_mul4(), bigint_comba_mul6(), bigint_comba_mul8(), bigint_comba_mul9(), bigint_linmul3(), and zeroize_buffer().

Referenced by bigint_monty_mul(), Botan::BigInt::mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul_by(), Botan::Barrett_Reduction::multiply(), operator*(), Botan::Scalar448::operator*(), and srp6_client_agree().

◆ bigint_mulx_monty_mul()

void Botan::bigint_mulx_monty_mul ( word z[],
const word x[],
const word y[],
const word p[],
size_t N,
word p_dash,
word ws[] )

Fused Montgomery multiplication

Computes z[0..N) = x*y*2^(-64*N) mod p for x, y < p. z may alias x or y. ws must hold at least N + 3 words.

Definition at line 113 of file mp_monty_mulx.cpp.

113 {
114 // t[-1] receives the word shifted out by each reduction row
115 word* t = ws + 1;
116 clear_mem(ws, N + 3);
117
118 for(size_t i = 0; i != N; ++i) {
119 monty_row(t, t, x, N, y[i], 0);
120 const word m = t[0] * p_dash;
121 monty_row(t - 1, t, p, N, m, 0);
122 t[N + 1] = 0;
123 }
124
125 // The result is below 2p, with t[N] holding its top bit
126 bigint_monty_maybe_sub(N, z, t[N], t, p);
127}

References bigint_monty_maybe_sub(), and clear_mem().

Referenced by bigint_monty_mul().

◆ bigint_mulx_monty_redc()

void Botan::bigint_mulx_monty_redc ( word r[],
word z[],
const word p[],
size_t N,
word p_dash )

Montgomery reduction of a 2N word value z, which is destroyed

Computes r[0..N) = z*2^(-64*N) mod p for z < p*2^(64*N). The buffer z must have 2N+1 words.

Definition at line 183 of file mp_monty_mulx.cpp.

183 {
184 z[2 * N] = 0;
185
186 word c = 0;
187 for(size_t i = 0; i != N; ++i) {
188 const word m = z[i] * p_dash;
189 c = monty_row(z + i, z + i, p, N, m, c);
190 }
191
192 // The sum is below 2p * B^N, so the final carry is zero and the top bit is z[2N]
193 BOTAN_DEBUG_ASSERT(c == 0);
194 bigint_monty_maybe_sub(N, r, z[2 * N], z + N, p);
195}

References bigint_monty_maybe_sub(), and BOTAN_DEBUG_ASSERT.

Referenced by bigint_mulx_monty_sqr().

◆ bigint_mulx_monty_sqr()

void Botan::bigint_mulx_monty_sqr ( word z[],
const word x[],
const word p[],
size_t N,
word p_dash,
word ws[] )

Montgomery squaring

Computes z[0..N) = x*x*2^(-64*N) mod p for x < p. z may alias x. ws must hold at least 2N + 1 words.

Definition at line 129 of file mp_monty_mulx.cpp.

129 {
130 bigint_mulx_sqr(ws, x, N);
131 bigint_mulx_monty_redc(z, ws, p, N, p_dash);
132}
void bigint_mulx_monty_redc(word r[], word z[], const word p[], size_t N, word p_dash)
void bigint_mulx_sqr(word z[], const word x[], size_t N)

References bigint_mulx_monty_redc(), and bigint_mulx_sqr().

Referenced by bigint_monty_sqr().

◆ bigint_mulx_mul4()

void Botan::bigint_mulx_mul4 ( word z[8],
const word x[4],
const word y[4] )

Definition at line 122 of file mp_mulx.cpp.

122 {
123 // clang-format off
124 asm(
125 "xorl %%r8d, %%r8d\n\t"
126 "xorl %%r9d, %%r9d\n\t"
127 "xorl %%r10d, %%r10d\n\t"
128 "xorl %%r11d, %%r11d\n\t"
129
130 "movq 0(%[y]), %%rdx\n\t" // row 0: x * y[0]
131 "xorl %%eax, %%eax\n\t"
132 "mulx 0(%[x]), %%rax, %%rcx\n\t"
133 "adcx %%rax, %%r8\n\t"
134 "movq %%r8, 0(%[z])\n\t"
135 "mulx 8(%[x]), %%rax, %%r8\n\t"
136 "adox %%rcx, %%rax\n\t"
137 "adcx %%rax, %%r9\n\t"
138 "mulx 16(%[x]), %%rax, %%rcx\n\t"
139 "adox %%r8, %%rax\n\t"
140 "adcx %%rax, %%r10\n\t"
141 "mulx 24(%[x]), %%rax, %%r8\n\t"
142 "adox %%rcx, %%rax\n\t"
143 "adcx %%rax, %%r11\n\t"
144 "movl $0, %%eax\n\t"
145 "adox %%rax, %%r8\n\t"
146 "adcx %%rax, %%r8\n\t"
147
148 "movq 8(%[y]), %%rdx\n\t" // row 1: x * y[1]
149 "xorl %%eax, %%eax\n\t"
150 "mulx 0(%[x]), %%rax, %%rcx\n\t"
151 "adcx %%rax, %%r9\n\t"
152 "movq %%r9, 8(%[z])\n\t"
153 "mulx 8(%[x]), %%rax, %%r9\n\t"
154 "adox %%rcx, %%rax\n\t"
155 "adcx %%rax, %%r10\n\t"
156 "mulx 16(%[x]), %%rax, %%rcx\n\t"
157 "adox %%r9, %%rax\n\t"
158 "adcx %%rax, %%r11\n\t"
159 "mulx 24(%[x]), %%rax, %%r9\n\t"
160 "adox %%rcx, %%rax\n\t"
161 "adcx %%rax, %%r8\n\t"
162 "movl $0, %%eax\n\t"
163 "adox %%rax, %%r9\n\t"
164 "adcx %%rax, %%r9\n\t"
165
166 "movq 16(%[y]), %%rdx\n\t" // row 2: x * y[2]
167 "xorl %%eax, %%eax\n\t"
168 "mulx 0(%[x]), %%rax, %%rcx\n\t"
169 "adcx %%rax, %%r10\n\t"
170 "movq %%r10, 16(%[z])\n\t"
171 "mulx 8(%[x]), %%rax, %%r10\n\t"
172 "adox %%rcx, %%rax\n\t"
173 "adcx %%rax, %%r11\n\t"
174 "mulx 16(%[x]), %%rax, %%rcx\n\t"
175 "adox %%r10, %%rax\n\t"
176 "adcx %%rax, %%r8\n\t"
177 "mulx 24(%[x]), %%rax, %%r10\n\t"
178 "adox %%rcx, %%rax\n\t"
179 "adcx %%rax, %%r9\n\t"
180 "movl $0, %%eax\n\t"
181 "adox %%rax, %%r10\n\t"
182 "adcx %%rax, %%r10\n\t"
183
184 "movq 24(%[y]), %%rdx\n\t" // row 3: x * y[3]
185 "xorl %%eax, %%eax\n\t"
186 "mulx 0(%[x]), %%rax, %%rcx\n\t"
187 "adcx %%rax, %%r11\n\t"
188 "movq %%r11, 24(%[z])\n\t"
189 "mulx 8(%[x]), %%rax, %%r11\n\t"
190 "adox %%rcx, %%rax\n\t"
191 "adcx %%rax, %%r8\n\t"
192 "mulx 16(%[x]), %%rax, %%rcx\n\t"
193 "adox %%r11, %%rax\n\t"
194 "adcx %%rax, %%r9\n\t"
195 "mulx 24(%[x]), %%rax, %%r11\n\t"
196 "adox %%rcx, %%rax\n\t"
197 "adcx %%rax, %%r10\n\t"
198 "movl $0, %%eax\n\t"
199 "adox %%rax, %%r11\n\t"
200 "adcx %%rax, %%r11\n\t"
201
202 "movq %%r8, 32(%[z])\n\t"
203 "movq %%r9, 40(%[z])\n\t"
204 "movq %%r10, 48(%[z])\n\t"
205 "movq %%r11, 56(%[z])\n\t"
206 :
207 : [z] "r"(z), [x] "r"(x), [y] "r"(y)
208 : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "cc", "memory");
209 // clang-format on
211}
void unpoison_asm_output(const W *ptr)
Definition mp_asmi.h:101

References unpoison_asm_output().

Referenced by bigint_comba_mul4().

◆ bigint_mulx_mul6()

void Botan::bigint_mulx_mul6 ( word z[12],
const word x[6],
const word y[6] )

Definition at line 371 of file mp_mulx.cpp.

371 {
372 // clang-format off
373 asm(
374 "xorl %%r8d, %%r8d\n\t"
375 "xorl %%r9d, %%r9d\n\t"
376 "xorl %%r10d, %%r10d\n\t"
377 "xorl %%r11d, %%r11d\n\t"
378 "xorl %%r12d, %%r12d\n\t"
379 "xorl %%r13d, %%r13d\n\t"
380
381 "movq 0(%[y]), %%rdx\n\t" // row 0: x * y[0]
382 "xorl %%eax, %%eax\n\t"
383 "mulx 0(%[x]), %%rax, %%rcx\n\t"
384 "adcx %%rax, %%r8\n\t"
385 "movq %%r8, 0(%[z])\n\t"
386 "mulx 8(%[x]), %%rax, %%r8\n\t"
387 "adox %%rcx, %%rax\n\t"
388 "adcx %%rax, %%r9\n\t"
389 "mulx 16(%[x]), %%rax, %%rcx\n\t"
390 "adox %%r8, %%rax\n\t"
391 "adcx %%rax, %%r10\n\t"
392 "mulx 24(%[x]), %%rax, %%r8\n\t"
393 "adox %%rcx, %%rax\n\t"
394 "adcx %%rax, %%r11\n\t"
395 "mulx 32(%[x]), %%rax, %%rcx\n\t"
396 "adox %%r8, %%rax\n\t"
397 "adcx %%rax, %%r12\n\t"
398 "mulx 40(%[x]), %%rax, %%r8\n\t"
399 "adox %%rcx, %%rax\n\t"
400 "adcx %%rax, %%r13\n\t"
401 "movl $0, %%eax\n\t"
402 "adox %%rax, %%r8\n\t"
403 "adcx %%rax, %%r8\n\t"
404
405 "movq 8(%[y]), %%rdx\n\t" // row 1: x * y[1]
406 "xorl %%eax, %%eax\n\t"
407 "mulx 0(%[x]), %%rax, %%rcx\n\t"
408 "adcx %%rax, %%r9\n\t"
409 "movq %%r9, 8(%[z])\n\t"
410 "mulx 8(%[x]), %%rax, %%r9\n\t"
411 "adox %%rcx, %%rax\n\t"
412 "adcx %%rax, %%r10\n\t"
413 "mulx 16(%[x]), %%rax, %%rcx\n\t"
414 "adox %%r9, %%rax\n\t"
415 "adcx %%rax, %%r11\n\t"
416 "mulx 24(%[x]), %%rax, %%r9\n\t"
417 "adox %%rcx, %%rax\n\t"
418 "adcx %%rax, %%r12\n\t"
419 "mulx 32(%[x]), %%rax, %%rcx\n\t"
420 "adox %%r9, %%rax\n\t"
421 "adcx %%rax, %%r13\n\t"
422 "mulx 40(%[x]), %%rax, %%r9\n\t"
423 "adox %%rcx, %%rax\n\t"
424 "adcx %%rax, %%r8\n\t"
425 "movl $0, %%eax\n\t"
426 "adox %%rax, %%r9\n\t"
427 "adcx %%rax, %%r9\n\t"
428
429 "movq 16(%[y]), %%rdx\n\t" // row 2: x * y[2]
430 "xorl %%eax, %%eax\n\t"
431 "mulx 0(%[x]), %%rax, %%rcx\n\t"
432 "adcx %%rax, %%r10\n\t"
433 "movq %%r10, 16(%[z])\n\t"
434 "mulx 8(%[x]), %%rax, %%r10\n\t"
435 "adox %%rcx, %%rax\n\t"
436 "adcx %%rax, %%r11\n\t"
437 "mulx 16(%[x]), %%rax, %%rcx\n\t"
438 "adox %%r10, %%rax\n\t"
439 "adcx %%rax, %%r12\n\t"
440 "mulx 24(%[x]), %%rax, %%r10\n\t"
441 "adox %%rcx, %%rax\n\t"
442 "adcx %%rax, %%r13\n\t"
443 "mulx 32(%[x]), %%rax, %%rcx\n\t"
444 "adox %%r10, %%rax\n\t"
445 "adcx %%rax, %%r8\n\t"
446 "mulx 40(%[x]), %%rax, %%r10\n\t"
447 "adox %%rcx, %%rax\n\t"
448 "adcx %%rax, %%r9\n\t"
449 "movl $0, %%eax\n\t"
450 "adox %%rax, %%r10\n\t"
451 "adcx %%rax, %%r10\n\t"
452
453 "movq 24(%[y]), %%rdx\n\t" // row 3: x * y[3]
454 "xorl %%eax, %%eax\n\t"
455 "mulx 0(%[x]), %%rax, %%rcx\n\t"
456 "adcx %%rax, %%r11\n\t"
457 "movq %%r11, 24(%[z])\n\t"
458 "mulx 8(%[x]), %%rax, %%r11\n\t"
459 "adox %%rcx, %%rax\n\t"
460 "adcx %%rax, %%r12\n\t"
461 "mulx 16(%[x]), %%rax, %%rcx\n\t"
462 "adox %%r11, %%rax\n\t"
463 "adcx %%rax, %%r13\n\t"
464 "mulx 24(%[x]), %%rax, %%r11\n\t"
465 "adox %%rcx, %%rax\n\t"
466 "adcx %%rax, %%r8\n\t"
467 "mulx 32(%[x]), %%rax, %%rcx\n\t"
468 "adox %%r11, %%rax\n\t"
469 "adcx %%rax, %%r9\n\t"
470 "mulx 40(%[x]), %%rax, %%r11\n\t"
471 "adox %%rcx, %%rax\n\t"
472 "adcx %%rax, %%r10\n\t"
473 "movl $0, %%eax\n\t"
474 "adox %%rax, %%r11\n\t"
475 "adcx %%rax, %%r11\n\t"
476
477 "movq 32(%[y]), %%rdx\n\t" // row 4: x * y[4]
478 "xorl %%eax, %%eax\n\t"
479 "mulx 0(%[x]), %%rax, %%rcx\n\t"
480 "adcx %%rax, %%r12\n\t"
481 "movq %%r12, 32(%[z])\n\t"
482 "mulx 8(%[x]), %%rax, %%r12\n\t"
483 "adox %%rcx, %%rax\n\t"
484 "adcx %%rax, %%r13\n\t"
485 "mulx 16(%[x]), %%rax, %%rcx\n\t"
486 "adox %%r12, %%rax\n\t"
487 "adcx %%rax, %%r8\n\t"
488 "mulx 24(%[x]), %%rax, %%r12\n\t"
489 "adox %%rcx, %%rax\n\t"
490 "adcx %%rax, %%r9\n\t"
491 "mulx 32(%[x]), %%rax, %%rcx\n\t"
492 "adox %%r12, %%rax\n\t"
493 "adcx %%rax, %%r10\n\t"
494 "mulx 40(%[x]), %%rax, %%r12\n\t"
495 "adox %%rcx, %%rax\n\t"
496 "adcx %%rax, %%r11\n\t"
497 "movl $0, %%eax\n\t"
498 "adox %%rax, %%r12\n\t"
499 "adcx %%rax, %%r12\n\t"
500
501 "movq 40(%[y]), %%rdx\n\t" // row 5: x * y[5]
502 "xorl %%eax, %%eax\n\t"
503 "mulx 0(%[x]), %%rax, %%rcx\n\t"
504 "adcx %%rax, %%r13\n\t"
505 "movq %%r13, 40(%[z])\n\t"
506 "mulx 8(%[x]), %%rax, %%r13\n\t"
507 "adox %%rcx, %%rax\n\t"
508 "adcx %%rax, %%r8\n\t"
509 "mulx 16(%[x]), %%rax, %%rcx\n\t"
510 "adox %%r13, %%rax\n\t"
511 "adcx %%rax, %%r9\n\t"
512 "mulx 24(%[x]), %%rax, %%r13\n\t"
513 "adox %%rcx, %%rax\n\t"
514 "adcx %%rax, %%r10\n\t"
515 "mulx 32(%[x]), %%rax, %%rcx\n\t"
516 "adox %%r13, %%rax\n\t"
517 "adcx %%rax, %%r11\n\t"
518 "mulx 40(%[x]), %%rax, %%r13\n\t"
519 "adox %%rcx, %%rax\n\t"
520 "adcx %%rax, %%r12\n\t"
521 "movl $0, %%eax\n\t"
522 "adox %%rax, %%r13\n\t"
523 "adcx %%rax, %%r13\n\t"
524
525 "movq %%r8, 48(%[z])\n\t"
526 "movq %%r9, 56(%[z])\n\t"
527 "movq %%r10, 64(%[z])\n\t"
528 "movq %%r11, 72(%[z])\n\t"
529 "movq %%r12, 80(%[z])\n\t"
530 "movq %%r13, 88(%[z])\n\t"
531 :
532 : [z] "r"(z), [x] "r"(x), [y] "r"(y)
533 : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "cc", "memory");
534 // clang-format on
536}

References unpoison_asm_output().

Referenced by bigint_comba_mul6().

◆ bigint_mulx_mul8()

void Botan::bigint_mulx_mul8 ( word z[16],
const word x[8],
const word y[8] )

Definition at line 772 of file mp_mulx.cpp.

772 {
773 // clang-format off
774 asm(
775 "xorl %%r8d, %%r8d\n\t"
776 "xorl %%r9d, %%r9d\n\t"
777 "xorl %%r10d, %%r10d\n\t"
778 "xorl %%r11d, %%r11d\n\t"
779 "xorl %%r12d, %%r12d\n\t"
780 "xorl %%r13d, %%r13d\n\t"
781 "xorl %%r14d, %%r14d\n\t"
782 "xorl %%r15d, %%r15d\n\t"
783
784 "movq 0(%[y]), %%rdx\n\t" // row 0: x * y[0]
785 "xorl %%eax, %%eax\n\t"
786 "mulx 0(%[x]), %%rax, %%rcx\n\t"
787 "adcx %%rax, %%r8\n\t"
788 "movq %%r8, 0(%[z])\n\t"
789 "mulx 8(%[x]), %%rax, %%r8\n\t"
790 "adox %%rcx, %%rax\n\t"
791 "adcx %%rax, %%r9\n\t"
792 "mulx 16(%[x]), %%rax, %%rcx\n\t"
793 "adox %%r8, %%rax\n\t"
794 "adcx %%rax, %%r10\n\t"
795 "mulx 24(%[x]), %%rax, %%r8\n\t"
796 "adox %%rcx, %%rax\n\t"
797 "adcx %%rax, %%r11\n\t"
798 "mulx 32(%[x]), %%rax, %%rcx\n\t"
799 "adox %%r8, %%rax\n\t"
800 "adcx %%rax, %%r12\n\t"
801 "mulx 40(%[x]), %%rax, %%r8\n\t"
802 "adox %%rcx, %%rax\n\t"
803 "adcx %%rax, %%r13\n\t"
804 "mulx 48(%[x]), %%rax, %%rcx\n\t"
805 "adox %%r8, %%rax\n\t"
806 "adcx %%rax, %%r14\n\t"
807 "mulx 56(%[x]), %%rax, %%r8\n\t"
808 "adox %%rcx, %%rax\n\t"
809 "adcx %%rax, %%r15\n\t"
810 "movl $0, %%eax\n\t"
811 "adox %%rax, %%r8\n\t"
812 "adcx %%rax, %%r8\n\t"
813
814 "movq 8(%[y]), %%rdx\n\t" // row 1: x * y[1]
815 "xorl %%eax, %%eax\n\t"
816 "mulx 0(%[x]), %%rax, %%rcx\n\t"
817 "adcx %%rax, %%r9\n\t"
818 "movq %%r9, 8(%[z])\n\t"
819 "mulx 8(%[x]), %%rax, %%r9\n\t"
820 "adox %%rcx, %%rax\n\t"
821 "adcx %%rax, %%r10\n\t"
822 "mulx 16(%[x]), %%rax, %%rcx\n\t"
823 "adox %%r9, %%rax\n\t"
824 "adcx %%rax, %%r11\n\t"
825 "mulx 24(%[x]), %%rax, %%r9\n\t"
826 "adox %%rcx, %%rax\n\t"
827 "adcx %%rax, %%r12\n\t"
828 "mulx 32(%[x]), %%rax, %%rcx\n\t"
829 "adox %%r9, %%rax\n\t"
830 "adcx %%rax, %%r13\n\t"
831 "mulx 40(%[x]), %%rax, %%r9\n\t"
832 "adox %%rcx, %%rax\n\t"
833 "adcx %%rax, %%r14\n\t"
834 "mulx 48(%[x]), %%rax, %%rcx\n\t"
835 "adox %%r9, %%rax\n\t"
836 "adcx %%rax, %%r15\n\t"
837 "mulx 56(%[x]), %%rax, %%r9\n\t"
838 "adox %%rcx, %%rax\n\t"
839 "adcx %%rax, %%r8\n\t"
840 "movl $0, %%eax\n\t"
841 "adox %%rax, %%r9\n\t"
842 "adcx %%rax, %%r9\n\t"
843
844 "movq 16(%[y]), %%rdx\n\t" // row 2: x * y[2]
845 "xorl %%eax, %%eax\n\t"
846 "mulx 0(%[x]), %%rax, %%rcx\n\t"
847 "adcx %%rax, %%r10\n\t"
848 "movq %%r10, 16(%[z])\n\t"
849 "mulx 8(%[x]), %%rax, %%r10\n\t"
850 "adox %%rcx, %%rax\n\t"
851 "adcx %%rax, %%r11\n\t"
852 "mulx 16(%[x]), %%rax, %%rcx\n\t"
853 "adox %%r10, %%rax\n\t"
854 "adcx %%rax, %%r12\n\t"
855 "mulx 24(%[x]), %%rax, %%r10\n\t"
856 "adox %%rcx, %%rax\n\t"
857 "adcx %%rax, %%r13\n\t"
858 "mulx 32(%[x]), %%rax, %%rcx\n\t"
859 "adox %%r10, %%rax\n\t"
860 "adcx %%rax, %%r14\n\t"
861 "mulx 40(%[x]), %%rax, %%r10\n\t"
862 "adox %%rcx, %%rax\n\t"
863 "adcx %%rax, %%r15\n\t"
864 "mulx 48(%[x]), %%rax, %%rcx\n\t"
865 "adox %%r10, %%rax\n\t"
866 "adcx %%rax, %%r8\n\t"
867 "mulx 56(%[x]), %%rax, %%r10\n\t"
868 "adox %%rcx, %%rax\n\t"
869 "adcx %%rax, %%r9\n\t"
870 "movl $0, %%eax\n\t"
871 "adox %%rax, %%r10\n\t"
872 "adcx %%rax, %%r10\n\t"
873
874 "movq 24(%[y]), %%rdx\n\t" // row 3: x * y[3]
875 "xorl %%eax, %%eax\n\t"
876 "mulx 0(%[x]), %%rax, %%rcx\n\t"
877 "adcx %%rax, %%r11\n\t"
878 "movq %%r11, 24(%[z])\n\t"
879 "mulx 8(%[x]), %%rax, %%r11\n\t"
880 "adox %%rcx, %%rax\n\t"
881 "adcx %%rax, %%r12\n\t"
882 "mulx 16(%[x]), %%rax, %%rcx\n\t"
883 "adox %%r11, %%rax\n\t"
884 "adcx %%rax, %%r13\n\t"
885 "mulx 24(%[x]), %%rax, %%r11\n\t"
886 "adox %%rcx, %%rax\n\t"
887 "adcx %%rax, %%r14\n\t"
888 "mulx 32(%[x]), %%rax, %%rcx\n\t"
889 "adox %%r11, %%rax\n\t"
890 "adcx %%rax, %%r15\n\t"
891 "mulx 40(%[x]), %%rax, %%r11\n\t"
892 "adox %%rcx, %%rax\n\t"
893 "adcx %%rax, %%r8\n\t"
894 "mulx 48(%[x]), %%rax, %%rcx\n\t"
895 "adox %%r11, %%rax\n\t"
896 "adcx %%rax, %%r9\n\t"
897 "mulx 56(%[x]), %%rax, %%r11\n\t"
898 "adox %%rcx, %%rax\n\t"
899 "adcx %%rax, %%r10\n\t"
900 "movl $0, %%eax\n\t"
901 "adox %%rax, %%r11\n\t"
902 "adcx %%rax, %%r11\n\t"
903
904 "movq 32(%[y]), %%rdx\n\t" // row 4: x * y[4]
905 "xorl %%eax, %%eax\n\t"
906 "mulx 0(%[x]), %%rax, %%rcx\n\t"
907 "adcx %%rax, %%r12\n\t"
908 "movq %%r12, 32(%[z])\n\t"
909 "mulx 8(%[x]), %%rax, %%r12\n\t"
910 "adox %%rcx, %%rax\n\t"
911 "adcx %%rax, %%r13\n\t"
912 "mulx 16(%[x]), %%rax, %%rcx\n\t"
913 "adox %%r12, %%rax\n\t"
914 "adcx %%rax, %%r14\n\t"
915 "mulx 24(%[x]), %%rax, %%r12\n\t"
916 "adox %%rcx, %%rax\n\t"
917 "adcx %%rax, %%r15\n\t"
918 "mulx 32(%[x]), %%rax, %%rcx\n\t"
919 "adox %%r12, %%rax\n\t"
920 "adcx %%rax, %%r8\n\t"
921 "mulx 40(%[x]), %%rax, %%r12\n\t"
922 "adox %%rcx, %%rax\n\t"
923 "adcx %%rax, %%r9\n\t"
924 "mulx 48(%[x]), %%rax, %%rcx\n\t"
925 "adox %%r12, %%rax\n\t"
926 "adcx %%rax, %%r10\n\t"
927 "mulx 56(%[x]), %%rax, %%r12\n\t"
928 "adox %%rcx, %%rax\n\t"
929 "adcx %%rax, %%r11\n\t"
930 "movl $0, %%eax\n\t"
931 "adox %%rax, %%r12\n\t"
932 "adcx %%rax, %%r12\n\t"
933
934 "movq 40(%[y]), %%rdx\n\t" // row 5: x * y[5]
935 "xorl %%eax, %%eax\n\t"
936 "mulx 0(%[x]), %%rax, %%rcx\n\t"
937 "adcx %%rax, %%r13\n\t"
938 "movq %%r13, 40(%[z])\n\t"
939 "mulx 8(%[x]), %%rax, %%r13\n\t"
940 "adox %%rcx, %%rax\n\t"
941 "adcx %%rax, %%r14\n\t"
942 "mulx 16(%[x]), %%rax, %%rcx\n\t"
943 "adox %%r13, %%rax\n\t"
944 "adcx %%rax, %%r15\n\t"
945 "mulx 24(%[x]), %%rax, %%r13\n\t"
946 "adox %%rcx, %%rax\n\t"
947 "adcx %%rax, %%r8\n\t"
948 "mulx 32(%[x]), %%rax, %%rcx\n\t"
949 "adox %%r13, %%rax\n\t"
950 "adcx %%rax, %%r9\n\t"
951 "mulx 40(%[x]), %%rax, %%r13\n\t"
952 "adox %%rcx, %%rax\n\t"
953 "adcx %%rax, %%r10\n\t"
954 "mulx 48(%[x]), %%rax, %%rcx\n\t"
955 "adox %%r13, %%rax\n\t"
956 "adcx %%rax, %%r11\n\t"
957 "mulx 56(%[x]), %%rax, %%r13\n\t"
958 "adox %%rcx, %%rax\n\t"
959 "adcx %%rax, %%r12\n\t"
960 "movl $0, %%eax\n\t"
961 "adox %%rax, %%r13\n\t"
962 "adcx %%rax, %%r13\n\t"
963
964 "movq 48(%[y]), %%rdx\n\t" // row 6: x * y[6]
965 "xorl %%eax, %%eax\n\t"
966 "mulx 0(%[x]), %%rax, %%rcx\n\t"
967 "adcx %%rax, %%r14\n\t"
968 "movq %%r14, 48(%[z])\n\t"
969 "mulx 8(%[x]), %%rax, %%r14\n\t"
970 "adox %%rcx, %%rax\n\t"
971 "adcx %%rax, %%r15\n\t"
972 "mulx 16(%[x]), %%rax, %%rcx\n\t"
973 "adox %%r14, %%rax\n\t"
974 "adcx %%rax, %%r8\n\t"
975 "mulx 24(%[x]), %%rax, %%r14\n\t"
976 "adox %%rcx, %%rax\n\t"
977 "adcx %%rax, %%r9\n\t"
978 "mulx 32(%[x]), %%rax, %%rcx\n\t"
979 "adox %%r14, %%rax\n\t"
980 "adcx %%rax, %%r10\n\t"
981 "mulx 40(%[x]), %%rax, %%r14\n\t"
982 "adox %%rcx, %%rax\n\t"
983 "adcx %%rax, %%r11\n\t"
984 "mulx 48(%[x]), %%rax, %%rcx\n\t"
985 "adox %%r14, %%rax\n\t"
986 "adcx %%rax, %%r12\n\t"
987 "mulx 56(%[x]), %%rax, %%r14\n\t"
988 "adox %%rcx, %%rax\n\t"
989 "adcx %%rax, %%r13\n\t"
990 "movl $0, %%eax\n\t"
991 "adox %%rax, %%r14\n\t"
992 "adcx %%rax, %%r14\n\t"
993
994 "movq 56(%[y]), %%rdx\n\t" // row 7: x * y[7]
995 "xorl %%eax, %%eax\n\t"
996 "mulx 0(%[x]), %%rax, %%rcx\n\t"
997 "adcx %%rax, %%r15\n\t"
998 "movq %%r15, 56(%[z])\n\t"
999 "mulx 8(%[x]), %%rax, %%r15\n\t"
1000 "adox %%rcx, %%rax\n\t"
1001 "adcx %%rax, %%r8\n\t"
1002 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1003 "adox %%r15, %%rax\n\t"
1004 "adcx %%rax, %%r9\n\t"
1005 "mulx 24(%[x]), %%rax, %%r15\n\t"
1006 "adox %%rcx, %%rax\n\t"
1007 "adcx %%rax, %%r10\n\t"
1008 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1009 "adox %%r15, %%rax\n\t"
1010 "adcx %%rax, %%r11\n\t"
1011 "mulx 40(%[x]), %%rax, %%r15\n\t"
1012 "adox %%rcx, %%rax\n\t"
1013 "adcx %%rax, %%r12\n\t"
1014 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1015 "adox %%r15, %%rax\n\t"
1016 "adcx %%rax, %%r13\n\t"
1017 "mulx 56(%[x]), %%rax, %%r15\n\t"
1018 "adox %%rcx, %%rax\n\t"
1019 "adcx %%rax, %%r14\n\t"
1020 "movl $0, %%eax\n\t"
1021 "adox %%rax, %%r15\n\t"
1022 "adcx %%rax, %%r15\n\t"
1023
1024 "movq %%r8, 64(%[z])\n\t"
1025 "movq %%r9, 72(%[z])\n\t"
1026 "movq %%r10, 80(%[z])\n\t"
1027 "movq %%r11, 88(%[z])\n\t"
1028 "movq %%r12, 96(%[z])\n\t"
1029 "movq %%r13, 104(%[z])\n\t"
1030 "movq %%r14, 112(%[z])\n\t"
1031 "movq %%r15, 120(%[z])\n\t"
1032 :
1033 : [z] "r"(z), [x] "r"(x), [y] "r"(y)
1034 : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "cc", "memory");
1035 // clang-format on
1037}

References unpoison_asm_output().

Referenced by bigint_comba_mul8().

◆ bigint_mulx_mul9()

void Botan::bigint_mulx_mul9 ( word z[18],
const word x[9],
const word y[9] )

Definition at line 1315 of file mp_mulx.cpp.

1315 {
1316 copy_mem(z + 9, y, 9);
1317 // clang-format off
1318 asm(
1319 "xorl %%r8d, %%r8d\n\t"
1320 "xorl %%r9d, %%r9d\n\t"
1321 "xorl %%r10d, %%r10d\n\t"
1322 "xorl %%r11d, %%r11d\n\t"
1323 "xorl %%r12d, %%r12d\n\t"
1324 "xorl %%r13d, %%r13d\n\t"
1325 "xorl %%r14d, %%r14d\n\t"
1326 "xorl %%r15d, %%r15d\n\t"
1327 "xorl %%ebx, %%ebx\n\t"
1328
1329 "movq 72(%[z]), %%rdx\n\t" // row 0: x * y[0]
1330 "xorl %%eax, %%eax\n\t"
1331 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1332 "adcx %%rax, %%r8\n\t"
1333 "movq %%r8, 0(%[z])\n\t"
1334 "mulx 8(%[x]), %%rax, %%r8\n\t"
1335 "adox %%rcx, %%rax\n\t"
1336 "adcx %%rax, %%r9\n\t"
1337 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1338 "adox %%r8, %%rax\n\t"
1339 "adcx %%rax, %%r10\n\t"
1340 "mulx 24(%[x]), %%rax, %%r8\n\t"
1341 "adox %%rcx, %%rax\n\t"
1342 "adcx %%rax, %%r11\n\t"
1343 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1344 "adox %%r8, %%rax\n\t"
1345 "adcx %%rax, %%r12\n\t"
1346 "mulx 40(%[x]), %%rax, %%r8\n\t"
1347 "adox %%rcx, %%rax\n\t"
1348 "adcx %%rax, %%r13\n\t"
1349 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1350 "adox %%r8, %%rax\n\t"
1351 "adcx %%rax, %%r14\n\t"
1352 "mulx 56(%[x]), %%rax, %%r8\n\t"
1353 "adox %%rcx, %%rax\n\t"
1354 "adcx %%rax, %%r15\n\t"
1355 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1356 "adox %%r8, %%rax\n\t"
1357 "adcx %%rax, %%rbx\n\t"
1358 "movl $0, %%eax\n\t"
1359 "adox %%rax, %%rcx\n\t"
1360 "adcx %%rax, %%rcx\n\t"
1361 "movq %%rcx, %%r8\n\t"
1362
1363 "movq 80(%[z]), %%rdx\n\t" // row 1: x * y[1]
1364 "xorl %%eax, %%eax\n\t"
1365 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1366 "adcx %%rax, %%r9\n\t"
1367 "movq %%r9, 8(%[z])\n\t"
1368 "mulx 8(%[x]), %%rax, %%r9\n\t"
1369 "adox %%rcx, %%rax\n\t"
1370 "adcx %%rax, %%r10\n\t"
1371 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1372 "adox %%r9, %%rax\n\t"
1373 "adcx %%rax, %%r11\n\t"
1374 "mulx 24(%[x]), %%rax, %%r9\n\t"
1375 "adox %%rcx, %%rax\n\t"
1376 "adcx %%rax, %%r12\n\t"
1377 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1378 "adox %%r9, %%rax\n\t"
1379 "adcx %%rax, %%r13\n\t"
1380 "mulx 40(%[x]), %%rax, %%r9\n\t"
1381 "adox %%rcx, %%rax\n\t"
1382 "adcx %%rax, %%r14\n\t"
1383 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1384 "adox %%r9, %%rax\n\t"
1385 "adcx %%rax, %%r15\n\t"
1386 "mulx 56(%[x]), %%rax, %%r9\n\t"
1387 "adox %%rcx, %%rax\n\t"
1388 "adcx %%rax, %%rbx\n\t"
1389 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1390 "adox %%r9, %%rax\n\t"
1391 "adcx %%rax, %%r8\n\t"
1392 "movl $0, %%eax\n\t"
1393 "adox %%rax, %%rcx\n\t"
1394 "adcx %%rax, %%rcx\n\t"
1395 "movq %%rcx, %%r9\n\t"
1396
1397 "movq 88(%[z]), %%rdx\n\t" // row 2: x * y[2]
1398 "xorl %%eax, %%eax\n\t"
1399 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1400 "adcx %%rax, %%r10\n\t"
1401 "movq %%r10, 16(%[z])\n\t"
1402 "mulx 8(%[x]), %%rax, %%r10\n\t"
1403 "adox %%rcx, %%rax\n\t"
1404 "adcx %%rax, %%r11\n\t"
1405 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1406 "adox %%r10, %%rax\n\t"
1407 "adcx %%rax, %%r12\n\t"
1408 "mulx 24(%[x]), %%rax, %%r10\n\t"
1409 "adox %%rcx, %%rax\n\t"
1410 "adcx %%rax, %%r13\n\t"
1411 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1412 "adox %%r10, %%rax\n\t"
1413 "adcx %%rax, %%r14\n\t"
1414 "mulx 40(%[x]), %%rax, %%r10\n\t"
1415 "adox %%rcx, %%rax\n\t"
1416 "adcx %%rax, %%r15\n\t"
1417 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1418 "adox %%r10, %%rax\n\t"
1419 "adcx %%rax, %%rbx\n\t"
1420 "mulx 56(%[x]), %%rax, %%r10\n\t"
1421 "adox %%rcx, %%rax\n\t"
1422 "adcx %%rax, %%r8\n\t"
1423 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1424 "adox %%r10, %%rax\n\t"
1425 "adcx %%rax, %%r9\n\t"
1426 "movl $0, %%eax\n\t"
1427 "adox %%rax, %%rcx\n\t"
1428 "adcx %%rax, %%rcx\n\t"
1429 "movq %%rcx, %%r10\n\t"
1430
1431 "movq 96(%[z]), %%rdx\n\t" // row 3: x * y[3]
1432 "xorl %%eax, %%eax\n\t"
1433 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1434 "adcx %%rax, %%r11\n\t"
1435 "movq %%r11, 24(%[z])\n\t"
1436 "mulx 8(%[x]), %%rax, %%r11\n\t"
1437 "adox %%rcx, %%rax\n\t"
1438 "adcx %%rax, %%r12\n\t"
1439 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1440 "adox %%r11, %%rax\n\t"
1441 "adcx %%rax, %%r13\n\t"
1442 "mulx 24(%[x]), %%rax, %%r11\n\t"
1443 "adox %%rcx, %%rax\n\t"
1444 "adcx %%rax, %%r14\n\t"
1445 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1446 "adox %%r11, %%rax\n\t"
1447 "adcx %%rax, %%r15\n\t"
1448 "mulx 40(%[x]), %%rax, %%r11\n\t"
1449 "adox %%rcx, %%rax\n\t"
1450 "adcx %%rax, %%rbx\n\t"
1451 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1452 "adox %%r11, %%rax\n\t"
1453 "adcx %%rax, %%r8\n\t"
1454 "mulx 56(%[x]), %%rax, %%r11\n\t"
1455 "adox %%rcx, %%rax\n\t"
1456 "adcx %%rax, %%r9\n\t"
1457 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1458 "adox %%r11, %%rax\n\t"
1459 "adcx %%rax, %%r10\n\t"
1460 "movl $0, %%eax\n\t"
1461 "adox %%rax, %%rcx\n\t"
1462 "adcx %%rax, %%rcx\n\t"
1463 "movq %%rcx, %%r11\n\t"
1464
1465 "movq 104(%[z]), %%rdx\n\t" // row 4: x * y[4]
1466 "xorl %%eax, %%eax\n\t"
1467 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1468 "adcx %%rax, %%r12\n\t"
1469 "movq %%r12, 32(%[z])\n\t"
1470 "mulx 8(%[x]), %%rax, %%r12\n\t"
1471 "adox %%rcx, %%rax\n\t"
1472 "adcx %%rax, %%r13\n\t"
1473 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1474 "adox %%r12, %%rax\n\t"
1475 "adcx %%rax, %%r14\n\t"
1476 "mulx 24(%[x]), %%rax, %%r12\n\t"
1477 "adox %%rcx, %%rax\n\t"
1478 "adcx %%rax, %%r15\n\t"
1479 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1480 "adox %%r12, %%rax\n\t"
1481 "adcx %%rax, %%rbx\n\t"
1482 "mulx 40(%[x]), %%rax, %%r12\n\t"
1483 "adox %%rcx, %%rax\n\t"
1484 "adcx %%rax, %%r8\n\t"
1485 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1486 "adox %%r12, %%rax\n\t"
1487 "adcx %%rax, %%r9\n\t"
1488 "mulx 56(%[x]), %%rax, %%r12\n\t"
1489 "adox %%rcx, %%rax\n\t"
1490 "adcx %%rax, %%r10\n\t"
1491 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1492 "adox %%r12, %%rax\n\t"
1493 "adcx %%rax, %%r11\n\t"
1494 "movl $0, %%eax\n\t"
1495 "adox %%rax, %%rcx\n\t"
1496 "adcx %%rax, %%rcx\n\t"
1497 "movq %%rcx, %%r12\n\t"
1498
1499 "movq 112(%[z]), %%rdx\n\t" // row 5: x * y[5]
1500 "xorl %%eax, %%eax\n\t"
1501 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1502 "adcx %%rax, %%r13\n\t"
1503 "movq %%r13, 40(%[z])\n\t"
1504 "mulx 8(%[x]), %%rax, %%r13\n\t"
1505 "adox %%rcx, %%rax\n\t"
1506 "adcx %%rax, %%r14\n\t"
1507 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1508 "adox %%r13, %%rax\n\t"
1509 "adcx %%rax, %%r15\n\t"
1510 "mulx 24(%[x]), %%rax, %%r13\n\t"
1511 "adox %%rcx, %%rax\n\t"
1512 "adcx %%rax, %%rbx\n\t"
1513 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1514 "adox %%r13, %%rax\n\t"
1515 "adcx %%rax, %%r8\n\t"
1516 "mulx 40(%[x]), %%rax, %%r13\n\t"
1517 "adox %%rcx, %%rax\n\t"
1518 "adcx %%rax, %%r9\n\t"
1519 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1520 "adox %%r13, %%rax\n\t"
1521 "adcx %%rax, %%r10\n\t"
1522 "mulx 56(%[x]), %%rax, %%r13\n\t"
1523 "adox %%rcx, %%rax\n\t"
1524 "adcx %%rax, %%r11\n\t"
1525 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1526 "adox %%r13, %%rax\n\t"
1527 "adcx %%rax, %%r12\n\t"
1528 "movl $0, %%eax\n\t"
1529 "adox %%rax, %%rcx\n\t"
1530 "adcx %%rax, %%rcx\n\t"
1531 "movq %%rcx, %%r13\n\t"
1532
1533 "movq 120(%[z]), %%rdx\n\t" // row 6: x * y[6]
1534 "xorl %%eax, %%eax\n\t"
1535 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1536 "adcx %%rax, %%r14\n\t"
1537 "movq %%r14, 48(%[z])\n\t"
1538 "mulx 8(%[x]), %%rax, %%r14\n\t"
1539 "adox %%rcx, %%rax\n\t"
1540 "adcx %%rax, %%r15\n\t"
1541 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1542 "adox %%r14, %%rax\n\t"
1543 "adcx %%rax, %%rbx\n\t"
1544 "mulx 24(%[x]), %%rax, %%r14\n\t"
1545 "adox %%rcx, %%rax\n\t"
1546 "adcx %%rax, %%r8\n\t"
1547 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1548 "adox %%r14, %%rax\n\t"
1549 "adcx %%rax, %%r9\n\t"
1550 "mulx 40(%[x]), %%rax, %%r14\n\t"
1551 "adox %%rcx, %%rax\n\t"
1552 "adcx %%rax, %%r10\n\t"
1553 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1554 "adox %%r14, %%rax\n\t"
1555 "adcx %%rax, %%r11\n\t"
1556 "mulx 56(%[x]), %%rax, %%r14\n\t"
1557 "adox %%rcx, %%rax\n\t"
1558 "adcx %%rax, %%r12\n\t"
1559 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1560 "adox %%r14, %%rax\n\t"
1561 "adcx %%rax, %%r13\n\t"
1562 "movl $0, %%eax\n\t"
1563 "adox %%rax, %%rcx\n\t"
1564 "adcx %%rax, %%rcx\n\t"
1565 "movq %%rcx, %%r14\n\t"
1566
1567 "movq 128(%[z]), %%rdx\n\t" // row 7: x * y[7]
1568 "xorl %%eax, %%eax\n\t"
1569 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1570 "adcx %%rax, %%r15\n\t"
1571 "movq %%r15, 56(%[z])\n\t"
1572 "mulx 8(%[x]), %%rax, %%r15\n\t"
1573 "adox %%rcx, %%rax\n\t"
1574 "adcx %%rax, %%rbx\n\t"
1575 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1576 "adox %%r15, %%rax\n\t"
1577 "adcx %%rax, %%r8\n\t"
1578 "mulx 24(%[x]), %%rax, %%r15\n\t"
1579 "adox %%rcx, %%rax\n\t"
1580 "adcx %%rax, %%r9\n\t"
1581 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1582 "adox %%r15, %%rax\n\t"
1583 "adcx %%rax, %%r10\n\t"
1584 "mulx 40(%[x]), %%rax, %%r15\n\t"
1585 "adox %%rcx, %%rax\n\t"
1586 "adcx %%rax, %%r11\n\t"
1587 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1588 "adox %%r15, %%rax\n\t"
1589 "adcx %%rax, %%r12\n\t"
1590 "mulx 56(%[x]), %%rax, %%r15\n\t"
1591 "adox %%rcx, %%rax\n\t"
1592 "adcx %%rax, %%r13\n\t"
1593 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1594 "adox %%r15, %%rax\n\t"
1595 "adcx %%rax, %%r14\n\t"
1596 "movl $0, %%eax\n\t"
1597 "adox %%rax, %%rcx\n\t"
1598 "adcx %%rax, %%rcx\n\t"
1599 "movq %%rcx, %%r15\n\t"
1600
1601 "movq 136(%[z]), %%rdx\n\t" // row 8: x * y[8]
1602 "xorl %%eax, %%eax\n\t"
1603 "mulx 0(%[x]), %%rax, %%rcx\n\t"
1604 "adcx %%rax, %%rbx\n\t"
1605 "movq %%rbx, 64(%[z])\n\t"
1606 "mulx 8(%[x]), %%rax, %%rbx\n\t"
1607 "adox %%rcx, %%rax\n\t"
1608 "adcx %%rax, %%r8\n\t"
1609 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1610 "adox %%rbx, %%rax\n\t"
1611 "adcx %%rax, %%r9\n\t"
1612 "mulx 24(%[x]), %%rax, %%rbx\n\t"
1613 "adox %%rcx, %%rax\n\t"
1614 "adcx %%rax, %%r10\n\t"
1615 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1616 "adox %%rbx, %%rax\n\t"
1617 "adcx %%rax, %%r11\n\t"
1618 "mulx 40(%[x]), %%rax, %%rbx\n\t"
1619 "adox %%rcx, %%rax\n\t"
1620 "adcx %%rax, %%r12\n\t"
1621 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1622 "adox %%rbx, %%rax\n\t"
1623 "adcx %%rax, %%r13\n\t"
1624 "mulx 56(%[x]), %%rax, %%rbx\n\t"
1625 "adox %%rcx, %%rax\n\t"
1626 "adcx %%rax, %%r14\n\t"
1627 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1628 "adox %%rbx, %%rax\n\t"
1629 "adcx %%rax, %%r15\n\t"
1630 "movl $0, %%eax\n\t"
1631 "adox %%rax, %%rcx\n\t"
1632 "adcx %%rax, %%rcx\n\t"
1633 "movq %%rcx, %%rbx\n\t"
1634
1635 "movq %%r8, 72(%[z])\n\t"
1636 "movq %%r9, 80(%[z])\n\t"
1637 "movq %%r10, 88(%[z])\n\t"
1638 "movq %%r11, 96(%[z])\n\t"
1639 "movq %%r12, 104(%[z])\n\t"
1640 "movq %%r13, 112(%[z])\n\t"
1641 "movq %%r14, 120(%[z])\n\t"
1642 "movq %%r15, 128(%[z])\n\t"
1643 "movq %%rbx, 136(%[z])\n\t"
1644 :
1645 : [z] "r"(z), [x] "r"(x)
1646 : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "rbx", "cc", "memory");
1647 // clang-format on
1649}

References copy_mem(), and unpoison_asm_output().

Referenced by bigint_comba_mul9().

◆ bigint_mulx_sqr()

void Botan::bigint_mulx_sqr ( word z[],
const word x[],
size_t N )

Squaring for any size: z[0..2N) = x^2, with z[2N] cleared

The output z must not overlap x and must have 2N+1 words

Definition at line 134 of file mp_monty_mulx.cpp.

134 {
135 clear_mem(z, 2 * N + 1);
136
137 /*
138 * x is split into a leading block of N % 8 words followed by blocks of 8
139 * words. Rows from the leading block cover every product x[i]*x[j] with
140 * j > i; rows from the other blocks cover only products with x[j] in a
141 * later block, so their lengths are multiples of 8.
142 */
143 const size_t lead = N % 8;
144
145 for(size_t i = 0; i != lead; ++i) {
146 monty_row(z + 2 * i + 1, z + 2 * i + 1, x + i + 1, N - i - 1, x[i], 0);
147 }
148
149 for(size_t b = lead; b + 8 < N; b += 8) {
150 for(size_t i = b; i != b + 8; ++i) {
151 monty_row(z + i + b + 8, z + i + b + 8, x + b + 8, N - b - 8, x[i], 0);
152 }
153 }
154
155 // Double the products while adding the squares not yet included, which together cover z[0..2N)
156 word carry = 0;
157 word top = 0;
158 auto double_and_add = [&](size_t k, word s) {
159 const word w = z[k];
160 z[k] = word_add((w << 1) | top, s, &carry);
161 top = w >> (WordInfo<word>::bits - 1);
162 };
163
164 for(size_t i = 0; i != lead; ++i) {
165 word hi = 0;
166 const word lo = word_madd2(x[i], x[i], &hi);
167 double_and_add(2 * i, lo);
168 double_and_add(2 * i + 1, hi);
169 }
170
171 for(size_t b = lead; b != N; b += 8) {
172 std::array<word, 16> sq{};
173 bigint_mulx_sqr8(sq.data(), x + b);
174 for(size_t k = 0; k != 16; ++k) {
175 double_and_add(2 * b + k, sq[k]);
176 }
177 }
178
179 // The square fits in 2N words
180 BOTAN_DEBUG_ASSERT(carry == 0 && top == 0);
181}

References bigint_mulx_sqr8(), BOTAN_DEBUG_ASSERT, clear_mem(), word_add(), and word_madd2().

Referenced by bigint_mulx_monty_sqr().

◆ bigint_mulx_sqr4()

void Botan::bigint_mulx_sqr4 ( word z[8],
const word x[4] )

Definition at line 28 of file mp_mulx.cpp.

28 {
29 // clang-format off
30 asm(
31 "xorl %%r9d, %%r9d\n\t"
32 "xorl %%r10d, %%r10d\n\t"
33 "xorl %%r8d, %%r8d\n\t"
34
35 "movq 0(%[x]), %%rdx\n\t" // x[0] * x[1..3]
36 "xorl %%eax, %%eax\n\t"
37 "mulx 8(%[x]), %%rax, %%rcx\n\t"
38 "adcx %%rax, %%r9\n\t"
39 "movq %%r9, 8(%[z])\n\t"
40 "mulx 16(%[x]), %%rax, %%r9\n\t"
41 "adox %%rcx, %%rax\n\t"
42 "adcx %%rax, %%r10\n\t"
43 "mulx 24(%[x]), %%rax, %%rcx\n\t"
44 "adox %%r9, %%rax\n\t"
45 "adcx %%rax, %%r8\n\t"
46 "movl $0, %%eax\n\t"
47 "adox %%rax, %%rcx\n\t"
48 "adcx %%rax, %%rcx\n\t"
49 "movq %%rcx, %%r9\n\t"
50 "movq %%r10, 16(%[z])\n\t"
51
52 "movq 8(%[x]), %%rdx\n\t" // x[1] * x[2..3]
53 "xorl %%eax, %%eax\n\t"
54 "mulx 16(%[x]), %%rax, %%rcx\n\t"
55 "adcx %%rax, %%r8\n\t"
56 "movq %%r8, 24(%[z])\n\t"
57 "mulx 24(%[x]), %%rax, %%r10\n\t"
58 "adox %%rcx, %%rax\n\t"
59 "adcx %%rax, %%r9\n\t"
60 "movl $0, %%eax\n\t"
61 "adox %%rax, %%r10\n\t"
62 "adcx %%rax, %%r10\n\t"
63 "movq %%r9, 32(%[z])\n\t"
64
65 "movq 16(%[x]), %%rdx\n\t" // x[2] * x[3..3]
66 "xorl %%eax, %%eax\n\t"
67 "mulx 24(%[x]), %%rax, %%rcx\n\t"
68 "adcx %%rax, %%r10\n\t"
69 "movq %%r10, 40(%[z])\n\t"
70 "movl $0, %%eax\n\t"
71 "adox %%rax, %%rcx\n\t"
72 "adcx %%rax, %%rcx\n\t"
73 "movq %%rcx, %%r8\n\t"
74 "movq %%r8, 48(%[z])\n\t"
75
76 "movq $0, 56(%[z])\n\t"
77 "xorl %%eax, %%eax\n\t" // double the cross products and add the squares
78 "movq 0(%[x]), %%rdx\n\t"
79 "mulx %%rdx, %%rax, %%rcx\n\t"
80 "movq %%rax, 0(%[z])\n\t"
81 "movq 8(%[z]), %%r8\n\t"
82 "adcx %%r8, %%r8\n\t"
83 "adox %%rcx, %%r8\n\t"
84 "movq %%r8, 8(%[z])\n\t"
85 "movq 8(%[x]), %%rdx\n\t"
86 "mulx %%rdx, %%rax, %%rcx\n\t"
87 "movq 16(%[z]), %%r8\n\t"
88 "adcx %%r8, %%r8\n\t"
89 "adox %%rax, %%r8\n\t"
90 "movq %%r8, 16(%[z])\n\t"
91 "movq 24(%[z]), %%r8\n\t"
92 "adcx %%r8, %%r8\n\t"
93 "adox %%rcx, %%r8\n\t"
94 "movq %%r8, 24(%[z])\n\t"
95 "movq 16(%[x]), %%rdx\n\t"
96 "mulx %%rdx, %%rax, %%rcx\n\t"
97 "movq 32(%[z]), %%r8\n\t"
98 "adcx %%r8, %%r8\n\t"
99 "adox %%rax, %%r8\n\t"
100 "movq %%r8, 32(%[z])\n\t"
101 "movq 40(%[z]), %%r8\n\t"
102 "adcx %%r8, %%r8\n\t"
103 "adox %%rcx, %%r8\n\t"
104 "movq %%r8, 40(%[z])\n\t"
105 "movq 24(%[x]), %%rdx\n\t"
106 "mulx %%rdx, %%rax, %%rcx\n\t"
107 "movq 48(%[z]), %%r8\n\t"
108 "adcx %%r8, %%r8\n\t"
109 "adox %%rax, %%r8\n\t"
110 "movq %%r8, 48(%[z])\n\t"
111 "movq 56(%[z]), %%r8\n\t"
112 "adcx %%r8, %%r8\n\t"
113 "adox %%rcx, %%r8\n\t"
114 "movq %%r8, 56(%[z])\n\t"
115 :
116 : [z] "r"(z), [x] "r"(x)
117 : "rax", "rcx", "rdx", "r8", "r9", "r10", "cc", "memory");
118 // clang-format on
120}

References unpoison_asm_output().

Referenced by bigint_comba_sqr4().

◆ bigint_mulx_sqr6()

void Botan::bigint_mulx_sqr6 ( word z[12],
const word x[6] )

Definition at line 213 of file mp_mulx.cpp.

213 {
214 // clang-format off
215 asm(
216 "xorl %%r9d, %%r9d\n\t"
217 "xorl %%r10d, %%r10d\n\t"
218 "xorl %%r11d, %%r11d\n\t"
219 "xorl %%r12d, %%r12d\n\t"
220 "xorl %%r8d, %%r8d\n\t"
221
222 "movq 0(%[x]), %%rdx\n\t" // x[0] * x[1..5]
223 "xorl %%eax, %%eax\n\t"
224 "mulx 8(%[x]), %%rax, %%rcx\n\t"
225 "adcx %%rax, %%r9\n\t"
226 "movq %%r9, 8(%[z])\n\t"
227 "mulx 16(%[x]), %%rax, %%r9\n\t"
228 "adox %%rcx, %%rax\n\t"
229 "adcx %%rax, %%r10\n\t"
230 "mulx 24(%[x]), %%rax, %%rcx\n\t"
231 "adox %%r9, %%rax\n\t"
232 "adcx %%rax, %%r11\n\t"
233 "mulx 32(%[x]), %%rax, %%r9\n\t"
234 "adox %%rcx, %%rax\n\t"
235 "adcx %%rax, %%r12\n\t"
236 "mulx 40(%[x]), %%rax, %%rcx\n\t"
237 "adox %%r9, %%rax\n\t"
238 "adcx %%rax, %%r8\n\t"
239 "movl $0, %%eax\n\t"
240 "adox %%rax, %%rcx\n\t"
241 "adcx %%rax, %%rcx\n\t"
242 "movq %%rcx, %%r9\n\t"
243 "movq %%r10, 16(%[z])\n\t"
244
245 "movq 8(%[x]), %%rdx\n\t" // x[1] * x[2..5]
246 "xorl %%eax, %%eax\n\t"
247 "mulx 16(%[x]), %%rax, %%rcx\n\t"
248 "adcx %%rax, %%r11\n\t"
249 "movq %%r11, 24(%[z])\n\t"
250 "mulx 24(%[x]), %%rax, %%r10\n\t"
251 "adox %%rcx, %%rax\n\t"
252 "adcx %%rax, %%r12\n\t"
253 "mulx 32(%[x]), %%rax, %%rcx\n\t"
254 "adox %%r10, %%rax\n\t"
255 "adcx %%rax, %%r8\n\t"
256 "mulx 40(%[x]), %%rax, %%r10\n\t"
257 "adox %%rcx, %%rax\n\t"
258 "adcx %%rax, %%r9\n\t"
259 "movl $0, %%eax\n\t"
260 "adox %%rax, %%r10\n\t"
261 "adcx %%rax, %%r10\n\t"
262 "movq %%r12, 32(%[z])\n\t"
263
264 "movq 16(%[x]), %%rdx\n\t" // x[2] * x[3..5]
265 "xorl %%eax, %%eax\n\t"
266 "mulx 24(%[x]), %%rax, %%rcx\n\t"
267 "adcx %%rax, %%r8\n\t"
268 "movq %%r8, 40(%[z])\n\t"
269 "mulx 32(%[x]), %%rax, %%r11\n\t"
270 "adox %%rcx, %%rax\n\t"
271 "adcx %%rax, %%r9\n\t"
272 "mulx 40(%[x]), %%rax, %%rcx\n\t"
273 "adox %%r11, %%rax\n\t"
274 "adcx %%rax, %%r10\n\t"
275 "movl $0, %%eax\n\t"
276 "adox %%rax, %%rcx\n\t"
277 "adcx %%rax, %%rcx\n\t"
278 "movq %%rcx, %%r11\n\t"
279 "movq %%r9, 48(%[z])\n\t"
280
281 "movq 24(%[x]), %%rdx\n\t" // x[3] * x[4..5]
282 "xorl %%eax, %%eax\n\t"
283 "mulx 32(%[x]), %%rax, %%rcx\n\t"
284 "adcx %%rax, %%r10\n\t"
285 "movq %%r10, 56(%[z])\n\t"
286 "mulx 40(%[x]), %%rax, %%r12\n\t"
287 "adox %%rcx, %%rax\n\t"
288 "adcx %%rax, %%r11\n\t"
289 "movl $0, %%eax\n\t"
290 "adox %%rax, %%r12\n\t"
291 "adcx %%rax, %%r12\n\t"
292 "movq %%r11, 64(%[z])\n\t"
293
294 "movq 32(%[x]), %%rdx\n\t" // x[4] * x[5..5]
295 "xorl %%eax, %%eax\n\t"
296 "mulx 40(%[x]), %%rax, %%rcx\n\t"
297 "adcx %%rax, %%r12\n\t"
298 "movq %%r12, 72(%[z])\n\t"
299 "movl $0, %%eax\n\t"
300 "adox %%rax, %%rcx\n\t"
301 "adcx %%rax, %%rcx\n\t"
302 "movq %%rcx, %%r8\n\t"
303 "movq %%r8, 80(%[z])\n\t"
304
305 "movq $0, 88(%[z])\n\t"
306 "xorl %%eax, %%eax\n\t" // double the cross products and add the squares
307 "movq 0(%[x]), %%rdx\n\t"
308 "mulx %%rdx, %%rax, %%rcx\n\t"
309 "movq %%rax, 0(%[z])\n\t"
310 "movq 8(%[z]), %%r8\n\t"
311 "adcx %%r8, %%r8\n\t"
312 "adox %%rcx, %%r8\n\t"
313 "movq %%r8, 8(%[z])\n\t"
314 "movq 8(%[x]), %%rdx\n\t"
315 "mulx %%rdx, %%rax, %%rcx\n\t"
316 "movq 16(%[z]), %%r8\n\t"
317 "adcx %%r8, %%r8\n\t"
318 "adox %%rax, %%r8\n\t"
319 "movq %%r8, 16(%[z])\n\t"
320 "movq 24(%[z]), %%r8\n\t"
321 "adcx %%r8, %%r8\n\t"
322 "adox %%rcx, %%r8\n\t"
323 "movq %%r8, 24(%[z])\n\t"
324 "movq 16(%[x]), %%rdx\n\t"
325 "mulx %%rdx, %%rax, %%rcx\n\t"
326 "movq 32(%[z]), %%r8\n\t"
327 "adcx %%r8, %%r8\n\t"
328 "adox %%rax, %%r8\n\t"
329 "movq %%r8, 32(%[z])\n\t"
330 "movq 40(%[z]), %%r8\n\t"
331 "adcx %%r8, %%r8\n\t"
332 "adox %%rcx, %%r8\n\t"
333 "movq %%r8, 40(%[z])\n\t"
334 "movq 24(%[x]), %%rdx\n\t"
335 "mulx %%rdx, %%rax, %%rcx\n\t"
336 "movq 48(%[z]), %%r8\n\t"
337 "adcx %%r8, %%r8\n\t"
338 "adox %%rax, %%r8\n\t"
339 "movq %%r8, 48(%[z])\n\t"
340 "movq 56(%[z]), %%r8\n\t"
341 "adcx %%r8, %%r8\n\t"
342 "adox %%rcx, %%r8\n\t"
343 "movq %%r8, 56(%[z])\n\t"
344 "movq 32(%[x]), %%rdx\n\t"
345 "mulx %%rdx, %%rax, %%rcx\n\t"
346 "movq 64(%[z]), %%r8\n\t"
347 "adcx %%r8, %%r8\n\t"
348 "adox %%rax, %%r8\n\t"
349 "movq %%r8, 64(%[z])\n\t"
350 "movq 72(%[z]), %%r8\n\t"
351 "adcx %%r8, %%r8\n\t"
352 "adox %%rcx, %%r8\n\t"
353 "movq %%r8, 72(%[z])\n\t"
354 "movq 40(%[x]), %%rdx\n\t"
355 "mulx %%rdx, %%rax, %%rcx\n\t"
356 "movq 80(%[z]), %%r8\n\t"
357 "adcx %%r8, %%r8\n\t"
358 "adox %%rax, %%r8\n\t"
359 "movq %%r8, 80(%[z])\n\t"
360 "movq 88(%[z]), %%r8\n\t"
361 "adcx %%r8, %%r8\n\t"
362 "adox %%rcx, %%r8\n\t"
363 "movq %%r8, 88(%[z])\n\t"
364 :
365 : [z] "r"(z), [x] "r"(x)
366 : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "r12", "cc", "memory");
367 // clang-format on
369}

References unpoison_asm_output().

Referenced by bigint_comba_sqr6().

◆ bigint_mulx_sqr8()

void Botan::bigint_mulx_sqr8 ( word z[16],
const word x[8] )

Definition at line 538 of file mp_mulx.cpp.

538 {
539 // clang-format off
540 asm(
541 "xorl %%r9d, %%r9d\n\t"
542 "xorl %%r10d, %%r10d\n\t"
543 "xorl %%r11d, %%r11d\n\t"
544 "xorl %%r12d, %%r12d\n\t"
545 "xorl %%r13d, %%r13d\n\t"
546 "xorl %%r14d, %%r14d\n\t"
547 "xorl %%r8d, %%r8d\n\t"
548
549 "movq 0(%[x]), %%rdx\n\t" // x[0] * x[1..7]
550 "xorl %%eax, %%eax\n\t"
551 "mulx 8(%[x]), %%rax, %%rcx\n\t"
552 "adcx %%rax, %%r9\n\t"
553 "movq %%r9, 8(%[z])\n\t"
554 "mulx 16(%[x]), %%rax, %%r9\n\t"
555 "adox %%rcx, %%rax\n\t"
556 "adcx %%rax, %%r10\n\t"
557 "mulx 24(%[x]), %%rax, %%rcx\n\t"
558 "adox %%r9, %%rax\n\t"
559 "adcx %%rax, %%r11\n\t"
560 "mulx 32(%[x]), %%rax, %%r9\n\t"
561 "adox %%rcx, %%rax\n\t"
562 "adcx %%rax, %%r12\n\t"
563 "mulx 40(%[x]), %%rax, %%rcx\n\t"
564 "adox %%r9, %%rax\n\t"
565 "adcx %%rax, %%r13\n\t"
566 "mulx 48(%[x]), %%rax, %%r9\n\t"
567 "adox %%rcx, %%rax\n\t"
568 "adcx %%rax, %%r14\n\t"
569 "mulx 56(%[x]), %%rax, %%rcx\n\t"
570 "adox %%r9, %%rax\n\t"
571 "adcx %%rax, %%r8\n\t"
572 "movl $0, %%eax\n\t"
573 "adox %%rax, %%rcx\n\t"
574 "adcx %%rax, %%rcx\n\t"
575 "movq %%rcx, %%r9\n\t"
576 "movq %%r10, 16(%[z])\n\t"
577
578 "movq 8(%[x]), %%rdx\n\t" // x[1] * x[2..7]
579 "xorl %%eax, %%eax\n\t"
580 "mulx 16(%[x]), %%rax, %%rcx\n\t"
581 "adcx %%rax, %%r11\n\t"
582 "movq %%r11, 24(%[z])\n\t"
583 "mulx 24(%[x]), %%rax, %%r10\n\t"
584 "adox %%rcx, %%rax\n\t"
585 "adcx %%rax, %%r12\n\t"
586 "mulx 32(%[x]), %%rax, %%rcx\n\t"
587 "adox %%r10, %%rax\n\t"
588 "adcx %%rax, %%r13\n\t"
589 "mulx 40(%[x]), %%rax, %%r10\n\t"
590 "adox %%rcx, %%rax\n\t"
591 "adcx %%rax, %%r14\n\t"
592 "mulx 48(%[x]), %%rax, %%rcx\n\t"
593 "adox %%r10, %%rax\n\t"
594 "adcx %%rax, %%r8\n\t"
595 "mulx 56(%[x]), %%rax, %%r10\n\t"
596 "adox %%rcx, %%rax\n\t"
597 "adcx %%rax, %%r9\n\t"
598 "movl $0, %%eax\n\t"
599 "adox %%rax, %%r10\n\t"
600 "adcx %%rax, %%r10\n\t"
601 "movq %%r12, 32(%[z])\n\t"
602
603 "movq 16(%[x]), %%rdx\n\t" // x[2] * x[3..7]
604 "xorl %%eax, %%eax\n\t"
605 "mulx 24(%[x]), %%rax, %%rcx\n\t"
606 "adcx %%rax, %%r13\n\t"
607 "movq %%r13, 40(%[z])\n\t"
608 "mulx 32(%[x]), %%rax, %%r11\n\t"
609 "adox %%rcx, %%rax\n\t"
610 "adcx %%rax, %%r14\n\t"
611 "mulx 40(%[x]), %%rax, %%rcx\n\t"
612 "adox %%r11, %%rax\n\t"
613 "adcx %%rax, %%r8\n\t"
614 "mulx 48(%[x]), %%rax, %%r11\n\t"
615 "adox %%rcx, %%rax\n\t"
616 "adcx %%rax, %%r9\n\t"
617 "mulx 56(%[x]), %%rax, %%rcx\n\t"
618 "adox %%r11, %%rax\n\t"
619 "adcx %%rax, %%r10\n\t"
620 "movl $0, %%eax\n\t"
621 "adox %%rax, %%rcx\n\t"
622 "adcx %%rax, %%rcx\n\t"
623 "movq %%rcx, %%r11\n\t"
624 "movq %%r14, 48(%[z])\n\t"
625
626 "movq 24(%[x]), %%rdx\n\t" // x[3] * x[4..7]
627 "xorl %%eax, %%eax\n\t"
628 "mulx 32(%[x]), %%rax, %%rcx\n\t"
629 "adcx %%rax, %%r8\n\t"
630 "movq %%r8, 56(%[z])\n\t"
631 "mulx 40(%[x]), %%rax, %%r12\n\t"
632 "adox %%rcx, %%rax\n\t"
633 "adcx %%rax, %%r9\n\t"
634 "mulx 48(%[x]), %%rax, %%rcx\n\t"
635 "adox %%r12, %%rax\n\t"
636 "adcx %%rax, %%r10\n\t"
637 "mulx 56(%[x]), %%rax, %%r12\n\t"
638 "adox %%rcx, %%rax\n\t"
639 "adcx %%rax, %%r11\n\t"
640 "movl $0, %%eax\n\t"
641 "adox %%rax, %%r12\n\t"
642 "adcx %%rax, %%r12\n\t"
643 "movq %%r9, 64(%[z])\n\t"
644
645 "movq 32(%[x]), %%rdx\n\t" // x[4] * x[5..7]
646 "xorl %%eax, %%eax\n\t"
647 "mulx 40(%[x]), %%rax, %%rcx\n\t"
648 "adcx %%rax, %%r10\n\t"
649 "movq %%r10, 72(%[z])\n\t"
650 "mulx 48(%[x]), %%rax, %%r13\n\t"
651 "adox %%rcx, %%rax\n\t"
652 "adcx %%rax, %%r11\n\t"
653 "mulx 56(%[x]), %%rax, %%rcx\n\t"
654 "adox %%r13, %%rax\n\t"
655 "adcx %%rax, %%r12\n\t"
656 "movl $0, %%eax\n\t"
657 "adox %%rax, %%rcx\n\t"
658 "adcx %%rax, %%rcx\n\t"
659 "movq %%rcx, %%r13\n\t"
660 "movq %%r11, 80(%[z])\n\t"
661
662 "movq 40(%[x]), %%rdx\n\t" // x[5] * x[6..7]
663 "xorl %%eax, %%eax\n\t"
664 "mulx 48(%[x]), %%rax, %%rcx\n\t"
665 "adcx %%rax, %%r12\n\t"
666 "movq %%r12, 88(%[z])\n\t"
667 "mulx 56(%[x]), %%rax, %%r14\n\t"
668 "adox %%rcx, %%rax\n\t"
669 "adcx %%rax, %%r13\n\t"
670 "movl $0, %%eax\n\t"
671 "adox %%rax, %%r14\n\t"
672 "adcx %%rax, %%r14\n\t"
673 "movq %%r13, 96(%[z])\n\t"
674
675 "movq 48(%[x]), %%rdx\n\t" // x[6] * x[7..7]
676 "xorl %%eax, %%eax\n\t"
677 "mulx 56(%[x]), %%rax, %%rcx\n\t"
678 "adcx %%rax, %%r14\n\t"
679 "movq %%r14, 104(%[z])\n\t"
680 "movl $0, %%eax\n\t"
681 "adox %%rax, %%rcx\n\t"
682 "adcx %%rax, %%rcx\n\t"
683 "movq %%rcx, %%r8\n\t"
684 "movq %%r8, 112(%[z])\n\t"
685
686 "movq $0, 120(%[z])\n\t"
687 "xorl %%eax, %%eax\n\t" // double the cross products and add the squares
688 "movq 0(%[x]), %%rdx\n\t"
689 "mulx %%rdx, %%rax, %%rcx\n\t"
690 "movq %%rax, 0(%[z])\n\t"
691 "movq 8(%[z]), %%r8\n\t"
692 "adcx %%r8, %%r8\n\t"
693 "adox %%rcx, %%r8\n\t"
694 "movq %%r8, 8(%[z])\n\t"
695 "movq 8(%[x]), %%rdx\n\t"
696 "mulx %%rdx, %%rax, %%rcx\n\t"
697 "movq 16(%[z]), %%r8\n\t"
698 "adcx %%r8, %%r8\n\t"
699 "adox %%rax, %%r8\n\t"
700 "movq %%r8, 16(%[z])\n\t"
701 "movq 24(%[z]), %%r8\n\t"
702 "adcx %%r8, %%r8\n\t"
703 "adox %%rcx, %%r8\n\t"
704 "movq %%r8, 24(%[z])\n\t"
705 "movq 16(%[x]), %%rdx\n\t"
706 "mulx %%rdx, %%rax, %%rcx\n\t"
707 "movq 32(%[z]), %%r8\n\t"
708 "adcx %%r8, %%r8\n\t"
709 "adox %%rax, %%r8\n\t"
710 "movq %%r8, 32(%[z])\n\t"
711 "movq 40(%[z]), %%r8\n\t"
712 "adcx %%r8, %%r8\n\t"
713 "adox %%rcx, %%r8\n\t"
714 "movq %%r8, 40(%[z])\n\t"
715 "movq 24(%[x]), %%rdx\n\t"
716 "mulx %%rdx, %%rax, %%rcx\n\t"
717 "movq 48(%[z]), %%r8\n\t"
718 "adcx %%r8, %%r8\n\t"
719 "adox %%rax, %%r8\n\t"
720 "movq %%r8, 48(%[z])\n\t"
721 "movq 56(%[z]), %%r8\n\t"
722 "adcx %%r8, %%r8\n\t"
723 "adox %%rcx, %%r8\n\t"
724 "movq %%r8, 56(%[z])\n\t"
725 "movq 32(%[x]), %%rdx\n\t"
726 "mulx %%rdx, %%rax, %%rcx\n\t"
727 "movq 64(%[z]), %%r8\n\t"
728 "adcx %%r8, %%r8\n\t"
729 "adox %%rax, %%r8\n\t"
730 "movq %%r8, 64(%[z])\n\t"
731 "movq 72(%[z]), %%r8\n\t"
732 "adcx %%r8, %%r8\n\t"
733 "adox %%rcx, %%r8\n\t"
734 "movq %%r8, 72(%[z])\n\t"
735 "movq 40(%[x]), %%rdx\n\t"
736 "mulx %%rdx, %%rax, %%rcx\n\t"
737 "movq 80(%[z]), %%r8\n\t"
738 "adcx %%r8, %%r8\n\t"
739 "adox %%rax, %%r8\n\t"
740 "movq %%r8, 80(%[z])\n\t"
741 "movq 88(%[z]), %%r8\n\t"
742 "adcx %%r8, %%r8\n\t"
743 "adox %%rcx, %%r8\n\t"
744 "movq %%r8, 88(%[z])\n\t"
745 "movq 48(%[x]), %%rdx\n\t"
746 "mulx %%rdx, %%rax, %%rcx\n\t"
747 "movq 96(%[z]), %%r8\n\t"
748 "adcx %%r8, %%r8\n\t"
749 "adox %%rax, %%r8\n\t"
750 "movq %%r8, 96(%[z])\n\t"
751 "movq 104(%[z]), %%r8\n\t"
752 "adcx %%r8, %%r8\n\t"
753 "adox %%rcx, %%r8\n\t"
754 "movq %%r8, 104(%[z])\n\t"
755 "movq 56(%[x]), %%rdx\n\t"
756 "mulx %%rdx, %%rax, %%rcx\n\t"
757 "movq 112(%[z]), %%r8\n\t"
758 "adcx %%r8, %%r8\n\t"
759 "adox %%rax, %%r8\n\t"
760 "movq %%r8, 112(%[z])\n\t"
761 "movq 120(%[z]), %%r8\n\t"
762 "adcx %%r8, %%r8\n\t"
763 "adox %%rcx, %%r8\n\t"
764 "movq %%r8, 120(%[z])\n\t"
765 :
766 : [z] "r"(z), [x] "r"(x)
767 : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "cc", "memory");
768 // clang-format on
770}

References unpoison_asm_output().

Referenced by bigint_comba_sqr8(), and bigint_mulx_sqr().

◆ bigint_mulx_sqr9()

void Botan::bigint_mulx_sqr9 ( word z[18],
const word x[9] )

Definition at line 1039 of file mp_mulx.cpp.

1039 {
1040 // clang-format off
1041 asm(
1042 "xorl %%r9d, %%r9d\n\t"
1043 "xorl %%r10d, %%r10d\n\t"
1044 "xorl %%r11d, %%r11d\n\t"
1045 "xorl %%r12d, %%r12d\n\t"
1046 "xorl %%r13d, %%r13d\n\t"
1047 "xorl %%r14d, %%r14d\n\t"
1048 "xorl %%r15d, %%r15d\n\t"
1049 "xorl %%r8d, %%r8d\n\t"
1050
1051 "movq 0(%[x]), %%rdx\n\t" // x[0] * x[1..8]
1052 "xorl %%eax, %%eax\n\t"
1053 "mulx 8(%[x]), %%rax, %%rcx\n\t"
1054 "adcx %%rax, %%r9\n\t"
1055 "movq %%r9, 8(%[z])\n\t"
1056 "mulx 16(%[x]), %%rax, %%r9\n\t"
1057 "adox %%rcx, %%rax\n\t"
1058 "adcx %%rax, %%r10\n\t"
1059 "mulx 24(%[x]), %%rax, %%rcx\n\t"
1060 "adox %%r9, %%rax\n\t"
1061 "adcx %%rax, %%r11\n\t"
1062 "mulx 32(%[x]), %%rax, %%r9\n\t"
1063 "adox %%rcx, %%rax\n\t"
1064 "adcx %%rax, %%r12\n\t"
1065 "mulx 40(%[x]), %%rax, %%rcx\n\t"
1066 "adox %%r9, %%rax\n\t"
1067 "adcx %%rax, %%r13\n\t"
1068 "mulx 48(%[x]), %%rax, %%r9\n\t"
1069 "adox %%rcx, %%rax\n\t"
1070 "adcx %%rax, %%r14\n\t"
1071 "mulx 56(%[x]), %%rax, %%rcx\n\t"
1072 "adox %%r9, %%rax\n\t"
1073 "adcx %%rax, %%r15\n\t"
1074 "mulx 64(%[x]), %%rax, %%r9\n\t"
1075 "adox %%rcx, %%rax\n\t"
1076 "adcx %%rax, %%r8\n\t"
1077 "movl $0, %%eax\n\t"
1078 "adox %%rax, %%r9\n\t"
1079 "adcx %%rax, %%r9\n\t"
1080 "movq %%r10, 16(%[z])\n\t"
1081
1082 "movq 8(%[x]), %%rdx\n\t" // x[1] * x[2..8]
1083 "xorl %%eax, %%eax\n\t"
1084 "mulx 16(%[x]), %%rax, %%rcx\n\t"
1085 "adcx %%rax, %%r11\n\t"
1086 "movq %%r11, 24(%[z])\n\t"
1087 "mulx 24(%[x]), %%rax, %%r10\n\t"
1088 "adox %%rcx, %%rax\n\t"
1089 "adcx %%rax, %%r12\n\t"
1090 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1091 "adox %%r10, %%rax\n\t"
1092 "adcx %%rax, %%r13\n\t"
1093 "mulx 40(%[x]), %%rax, %%r10\n\t"
1094 "adox %%rcx, %%rax\n\t"
1095 "adcx %%rax, %%r14\n\t"
1096 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1097 "adox %%r10, %%rax\n\t"
1098 "adcx %%rax, %%r15\n\t"
1099 "mulx 56(%[x]), %%rax, %%r10\n\t"
1100 "adox %%rcx, %%rax\n\t"
1101 "adcx %%rax, %%r8\n\t"
1102 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1103 "adox %%r10, %%rax\n\t"
1104 "adcx %%rax, %%r9\n\t"
1105 "movl $0, %%eax\n\t"
1106 "adox %%rax, %%rcx\n\t"
1107 "adcx %%rax, %%rcx\n\t"
1108 "movq %%rcx, %%r10\n\t"
1109 "movq %%r12, 32(%[z])\n\t"
1110
1111 "movq 16(%[x]), %%rdx\n\t" // x[2] * x[3..8]
1112 "xorl %%eax, %%eax\n\t"
1113 "mulx 24(%[x]), %%rax, %%rcx\n\t"
1114 "adcx %%rax, %%r13\n\t"
1115 "movq %%r13, 40(%[z])\n\t"
1116 "mulx 32(%[x]), %%rax, %%r11\n\t"
1117 "adox %%rcx, %%rax\n\t"
1118 "adcx %%rax, %%r14\n\t"
1119 "mulx 40(%[x]), %%rax, %%rcx\n\t"
1120 "adox %%r11, %%rax\n\t"
1121 "adcx %%rax, %%r15\n\t"
1122 "mulx 48(%[x]), %%rax, %%r11\n\t"
1123 "adox %%rcx, %%rax\n\t"
1124 "adcx %%rax, %%r8\n\t"
1125 "mulx 56(%[x]), %%rax, %%rcx\n\t"
1126 "adox %%r11, %%rax\n\t"
1127 "adcx %%rax, %%r9\n\t"
1128 "mulx 64(%[x]), %%rax, %%r11\n\t"
1129 "adox %%rcx, %%rax\n\t"
1130 "adcx %%rax, %%r10\n\t"
1131 "movl $0, %%eax\n\t"
1132 "adox %%rax, %%r11\n\t"
1133 "adcx %%rax, %%r11\n\t"
1134 "movq %%r14, 48(%[z])\n\t"
1135
1136 "movq 24(%[x]), %%rdx\n\t" // x[3] * x[4..8]
1137 "xorl %%eax, %%eax\n\t"
1138 "mulx 32(%[x]), %%rax, %%rcx\n\t"
1139 "adcx %%rax, %%r15\n\t"
1140 "movq %%r15, 56(%[z])\n\t"
1141 "mulx 40(%[x]), %%rax, %%r12\n\t"
1142 "adox %%rcx, %%rax\n\t"
1143 "adcx %%rax, %%r8\n\t"
1144 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1145 "adox %%r12, %%rax\n\t"
1146 "adcx %%rax, %%r9\n\t"
1147 "mulx 56(%[x]), %%rax, %%r12\n\t"
1148 "adox %%rcx, %%rax\n\t"
1149 "adcx %%rax, %%r10\n\t"
1150 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1151 "adox %%r12, %%rax\n\t"
1152 "adcx %%rax, %%r11\n\t"
1153 "movl $0, %%eax\n\t"
1154 "adox %%rax, %%rcx\n\t"
1155 "adcx %%rax, %%rcx\n\t"
1156 "movq %%rcx, %%r12\n\t"
1157 "movq %%r8, 64(%[z])\n\t"
1158
1159 "movq 32(%[x]), %%rdx\n\t" // x[4] * x[5..8]
1160 "xorl %%eax, %%eax\n\t"
1161 "mulx 40(%[x]), %%rax, %%rcx\n\t"
1162 "adcx %%rax, %%r9\n\t"
1163 "movq %%r9, 72(%[z])\n\t"
1164 "mulx 48(%[x]), %%rax, %%r13\n\t"
1165 "adox %%rcx, %%rax\n\t"
1166 "adcx %%rax, %%r10\n\t"
1167 "mulx 56(%[x]), %%rax, %%rcx\n\t"
1168 "adox %%r13, %%rax\n\t"
1169 "adcx %%rax, %%r11\n\t"
1170 "mulx 64(%[x]), %%rax, %%r13\n\t"
1171 "adox %%rcx, %%rax\n\t"
1172 "adcx %%rax, %%r12\n\t"
1173 "movl $0, %%eax\n\t"
1174 "adox %%rax, %%r13\n\t"
1175 "adcx %%rax, %%r13\n\t"
1176 "movq %%r10, 80(%[z])\n\t"
1177
1178 "movq 40(%[x]), %%rdx\n\t" // x[5] * x[6..8]
1179 "xorl %%eax, %%eax\n\t"
1180 "mulx 48(%[x]), %%rax, %%rcx\n\t"
1181 "adcx %%rax, %%r11\n\t"
1182 "movq %%r11, 88(%[z])\n\t"
1183 "mulx 56(%[x]), %%rax, %%r14\n\t"
1184 "adox %%rcx, %%rax\n\t"
1185 "adcx %%rax, %%r12\n\t"
1186 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1187 "adox %%r14, %%rax\n\t"
1188 "adcx %%rax, %%r13\n\t"
1189 "movl $0, %%eax\n\t"
1190 "adox %%rax, %%rcx\n\t"
1191 "adcx %%rax, %%rcx\n\t"
1192 "movq %%rcx, %%r14\n\t"
1193 "movq %%r12, 96(%[z])\n\t"
1194
1195 "movq 48(%[x]), %%rdx\n\t" // x[6] * x[7..8]
1196 "xorl %%eax, %%eax\n\t"
1197 "mulx 56(%[x]), %%rax, %%rcx\n\t"
1198 "adcx %%rax, %%r13\n\t"
1199 "movq %%r13, 104(%[z])\n\t"
1200 "mulx 64(%[x]), %%rax, %%r15\n\t"
1201 "adox %%rcx, %%rax\n\t"
1202 "adcx %%rax, %%r14\n\t"
1203 "movl $0, %%eax\n\t"
1204 "adox %%rax, %%r15\n\t"
1205 "adcx %%rax, %%r15\n\t"
1206 "movq %%r14, 112(%[z])\n\t"
1207
1208 "movq 56(%[x]), %%rdx\n\t" // x[7] * x[8..8]
1209 "xorl %%eax, %%eax\n\t"
1210 "mulx 64(%[x]), %%rax, %%rcx\n\t"
1211 "adcx %%rax, %%r15\n\t"
1212 "movq %%r15, 120(%[z])\n\t"
1213 "movl $0, %%eax\n\t"
1214 "adox %%rax, %%rcx\n\t"
1215 "adcx %%rax, %%rcx\n\t"
1216 "movq %%rcx, %%r8\n\t"
1217 "movq %%r8, 128(%[z])\n\t"
1218
1219 "movq $0, 136(%[z])\n\t"
1220 "xorl %%eax, %%eax\n\t" // double the cross products and add the squares
1221 "movq 0(%[x]), %%rdx\n\t"
1222 "mulx %%rdx, %%rax, %%rcx\n\t"
1223 "movq %%rax, 0(%[z])\n\t"
1224 "movq 8(%[z]), %%r8\n\t"
1225 "adcx %%r8, %%r8\n\t"
1226 "adox %%rcx, %%r8\n\t"
1227 "movq %%r8, 8(%[z])\n\t"
1228 "movq 8(%[x]), %%rdx\n\t"
1229 "mulx %%rdx, %%rax, %%rcx\n\t"
1230 "movq 16(%[z]), %%r8\n\t"
1231 "adcx %%r8, %%r8\n\t"
1232 "adox %%rax, %%r8\n\t"
1233 "movq %%r8, 16(%[z])\n\t"
1234 "movq 24(%[z]), %%r8\n\t"
1235 "adcx %%r8, %%r8\n\t"
1236 "adox %%rcx, %%r8\n\t"
1237 "movq %%r8, 24(%[z])\n\t"
1238 "movq 16(%[x]), %%rdx\n\t"
1239 "mulx %%rdx, %%rax, %%rcx\n\t"
1240 "movq 32(%[z]), %%r8\n\t"
1241 "adcx %%r8, %%r8\n\t"
1242 "adox %%rax, %%r8\n\t"
1243 "movq %%r8, 32(%[z])\n\t"
1244 "movq 40(%[z]), %%r8\n\t"
1245 "adcx %%r8, %%r8\n\t"
1246 "adox %%rcx, %%r8\n\t"
1247 "movq %%r8, 40(%[z])\n\t"
1248 "movq 24(%[x]), %%rdx\n\t"
1249 "mulx %%rdx, %%rax, %%rcx\n\t"
1250 "movq 48(%[z]), %%r8\n\t"
1251 "adcx %%r8, %%r8\n\t"
1252 "adox %%rax, %%r8\n\t"
1253 "movq %%r8, 48(%[z])\n\t"
1254 "movq 56(%[z]), %%r8\n\t"
1255 "adcx %%r8, %%r8\n\t"
1256 "adox %%rcx, %%r8\n\t"
1257 "movq %%r8, 56(%[z])\n\t"
1258 "movq 32(%[x]), %%rdx\n\t"
1259 "mulx %%rdx, %%rax, %%rcx\n\t"
1260 "movq 64(%[z]), %%r8\n\t"
1261 "adcx %%r8, %%r8\n\t"
1262 "adox %%rax, %%r8\n\t"
1263 "movq %%r8, 64(%[z])\n\t"
1264 "movq 72(%[z]), %%r8\n\t"
1265 "adcx %%r8, %%r8\n\t"
1266 "adox %%rcx, %%r8\n\t"
1267 "movq %%r8, 72(%[z])\n\t"
1268 "movq 40(%[x]), %%rdx\n\t"
1269 "mulx %%rdx, %%rax, %%rcx\n\t"
1270 "movq 80(%[z]), %%r8\n\t"
1271 "adcx %%r8, %%r8\n\t"
1272 "adox %%rax, %%r8\n\t"
1273 "movq %%r8, 80(%[z])\n\t"
1274 "movq 88(%[z]), %%r8\n\t"
1275 "adcx %%r8, %%r8\n\t"
1276 "adox %%rcx, %%r8\n\t"
1277 "movq %%r8, 88(%[z])\n\t"
1278 "movq 48(%[x]), %%rdx\n\t"
1279 "mulx %%rdx, %%rax, %%rcx\n\t"
1280 "movq 96(%[z]), %%r8\n\t"
1281 "adcx %%r8, %%r8\n\t"
1282 "adox %%rax, %%r8\n\t"
1283 "movq %%r8, 96(%[z])\n\t"
1284 "movq 104(%[z]), %%r8\n\t"
1285 "adcx %%r8, %%r8\n\t"
1286 "adox %%rcx, %%r8\n\t"
1287 "movq %%r8, 104(%[z])\n\t"
1288 "movq 56(%[x]), %%rdx\n\t"
1289 "mulx %%rdx, %%rax, %%rcx\n\t"
1290 "movq 112(%[z]), %%r8\n\t"
1291 "adcx %%r8, %%r8\n\t"
1292 "adox %%rax, %%r8\n\t"
1293 "movq %%r8, 112(%[z])\n\t"
1294 "movq 120(%[z]), %%r8\n\t"
1295 "adcx %%r8, %%r8\n\t"
1296 "adox %%rcx, %%r8\n\t"
1297 "movq %%r8, 120(%[z])\n\t"
1298 "movq 64(%[x]), %%rdx\n\t"
1299 "mulx %%rdx, %%rax, %%rcx\n\t"
1300 "movq 128(%[z]), %%r8\n\t"
1301 "adcx %%r8, %%r8\n\t"
1302 "adox %%rax, %%r8\n\t"
1303 "movq %%r8, 128(%[z])\n\t"
1304 "movq 136(%[z]), %%r8\n\t"
1305 "adcx %%r8, %%r8\n\t"
1306 "adox %%rcx, %%r8\n\t"
1307 "movq %%r8, 136(%[z])\n\t"
1308 :
1309 : [z] "r"(z), [x] "r"(x)
1310 : "rax", "rcx", "rdx", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "cc", "memory");
1311 // clang-format on
1313}

References unpoison_asm_output().

Referenced by bigint_comba_sqr9().

◆ bigint_shl1()

template<WordType W>
void Botan::bigint_shl1 ( W x[],
size_t x_size,
size_t x_words,
size_t shift )
inlineconstexpr

Definition at line 313 of file mp_core.h.

313 {
314 const size_t word_shift = shift / WordInfo<W>::bits;
315 const size_t bit_shift = shift % WordInfo<W>::bits;
316
317 BOTAN_ASSERT_NOMSG(word_shift <= x_size);
318 BOTAN_ASSERT_NOMSG(x_words <= x_size - word_shift);
319
320 unchecked_copy_memory(x + word_shift, x, x_words);
321 zeroize_buffer(x, word_shift);
322
323 const auto carry_mask = CT::Mask<W>::expand(bit_shift);
324 const W carry_shift = carry_mask.if_set_return(WordInfo<W>::bits - bit_shift);
325
326 W carry = 0;
327 for(size_t i = word_shift; i != x_size; ++i) {
328 const W w = x[i];
329 x[i] = (w << bit_shift) | carry;
330 carry = carry_mask.if_set_return(w >> carry_shift);
331 }
332}
constexpr uint64_t carry_shift(const donna128 &a, size_t shift)
Definition donna128.h:129
void unchecked_copy_memory(T *out, const T *in, size_t n)
Definition mem_utils.h:44

References BOTAN_ASSERT_NOMSG, carry_shift(), Botan::CT::Mask< T >::expand(), unchecked_copy_memory(), and zeroize_buffer().

Referenced by is_perfect_square(), and Botan::BigInt::operator<<=().

◆ bigint_shl2()

template<WordType W>
void Botan::bigint_shl2 ( W y[],
size_t y_size,
const W x[],
size_t x_size,
size_t shift )
inlineconstexpr

Definition at line 359 of file mp_core.h.

359 {
360 const size_t word_shift = shift / WordInfo<W>::bits;
361 const size_t bit_shift = shift % WordInfo<W>::bits;
362
363 BOTAN_ASSERT_NOMSG(word_shift <= y_size);
364 BOTAN_ASSERT_NOMSG(x_size < y_size - word_shift);
365
366 unchecked_copy_memory(y + word_shift, x, x_size);
367 zeroize_buffer(y, word_shift);
368 zeroize_buffer(y + word_shift + x_size, y_size - word_shift - x_size);
369
370 const auto carry_mask = CT::Mask<W>::expand(bit_shift);
371 const W carry_shift = carry_mask.if_set_return(WordInfo<W>::bits - bit_shift);
372
373 W carry = 0;
374 for(size_t i = word_shift; i != x_size + word_shift + 1; ++i) {
375 const W w = y[i];
376 y[i] = (w << bit_shift) | carry;
377 carry = carry_mask.if_set_return(w >> carry_shift);
378 }
379}

References BOTAN_ASSERT_NOMSG, carry_shift(), Botan::CT::Mask< T >::expand(), unchecked_copy_memory(), and zeroize_buffer().

Referenced by Botan::BigInt::ct_shift_left(), and operator<<().

◆ bigint_shr1()

template<WordType W>
void Botan::bigint_shr1 ( W x[],
size_t x_size,
size_t shift )
inlineconstexpr

Definition at line 335 of file mp_core.h.

335 {
336 const size_t word_shift = shift / WordInfo<W>::bits;
337 const size_t bit_shift = shift % WordInfo<W>::bits;
338
339 const size_t top = x_size >= word_shift ? (x_size - word_shift) : 0;
340
341 if(top > 0) {
342 unchecked_copy_memory(x, x + word_shift, top);
343 }
344 zeroize_buffer(x + top, std::min(word_shift, x_size));
345
346 const auto carry_mask = CT::Mask<W>::expand(bit_shift);
347 const W carry_shift = carry_mask.if_set_return(WordInfo<W>::bits - bit_shift);
348
349 W carry = 0;
350
351 for(size_t i = 0; i != top; ++i) {
352 const W w = x[top - i - 1];
353 x[top - i - 1] = (w >> bit_shift) | carry;
354 carry = carry_mask.if_set_return(w << carry_shift);
355 }
356}

References carry_shift(), Botan::CT::Mask< T >::expand(), unchecked_copy_memory(), and zeroize_buffer().

Referenced by Botan::BigInt::operator>>=().

◆ bigint_shr2()

template<WordType W>
void Botan::bigint_shr2 ( W y[],
size_t y_size,
const W x[],
size_t x_size,
size_t shift )
inlineconstexpr

Definition at line 382 of file mp_core.h.

382 {
383 const size_t word_shift = shift / WordInfo<W>::bits;
384 const size_t bit_shift = shift % WordInfo<W>::bits;
385 const size_t new_size = x_size < word_shift ? 0 : (x_size - word_shift);
386
387 BOTAN_ASSERT_NOMSG(new_size <= y_size);
388
389 if(new_size > 0) {
390 unchecked_copy_memory(y, x + word_shift, new_size);
391 }
392 zeroize_buffer(y + new_size, y_size - new_size);
393
394 const auto carry_mask = CT::Mask<W>::expand(bit_shift);
395 const W carry_shift = carry_mask.if_set_return(WordInfo<W>::bits - bit_shift);
396
397 W carry = 0;
398 for(size_t i = new_size; i > 0; --i) {
399 W w = y[i - 1];
400 y[i - 1] = (w >> bit_shift) | carry;
401 carry = carry_mask.if_set_return(w << carry_shift);
402 }
403}

References BOTAN_ASSERT_NOMSG, carry_shift(), Botan::CT::Mask< T >::expand(), unchecked_copy_memory(), and zeroize_buffer().

Referenced by gcd(), and operator>>().

◆ bigint_sqr()

void Botan::bigint_sqr ( word z[],
size_t z_size,
const word x[],
size_t x_size,
size_t x_sw,
word workspace[],
size_t ws_size )

Definition at line 327 of file mp_karat.cpp.

327 {
328 zeroize_buffer(z, z_size);
329
330 BOTAN_ASSERT(z_size / 2 >= x_sw, "Output size is sufficient");
331
332 if(x_sw == 1) {
333 bigint_linmul3(z, x, x_sw, x[0]);
334 } else if(sized_for_comba_sqr<4>(x_sw, x_size, z_size)) {
335 bigint_comba_sqr4(z, x);
336 } else if(sized_for_comba_sqr<6>(x_sw, x_size, z_size)) {
337 bigint_comba_sqr6(z, x);
338 } else if(sized_for_comba_sqr<8>(x_sw, x_size, z_size)) {
339 bigint_comba_sqr8(z, x);
340 } else if(sized_for_comba_sqr<9>(x_sw, x_size, z_size)) {
341 bigint_comba_sqr9(z, x);
342 } else if(sized_for_comba_sqr<16>(x_sw, x_size, z_size)) {
343 bigint_comba_sqr16(z, x);
344 } else if(sized_for_comba_sqr<24>(x_sw, x_size, z_size)) {
345 bigint_comba_sqr24(z, x);
346 } else if(x_size < KARATSUBA_SQUARE_THRESHOLD || workspace == nullptr) {
347 basecase_sqr(z, z_size, x, x_sw);
348 } else {
349 const size_t N = karatsuba_size(z_size, x_size, x_sw);
350
351 if(N > 0 && z_size >= 2 * N && ws_size >= 2 * N) {
352 karatsuba_sqr(z, x, N, workspace);
353 } else {
354 basecase_sqr(z, z_size, x, x_sw);
355 }
356 }
357}
BOTAN_FUZZER_API void basecase_sqr(word z[], size_t z_size, const word x[], size_t x_size)
Definition mp_karat.cpp:46
void bigint_comba_sqr4(word z[8], const word x[4])
Definition mp_comba.cpp:22
void bigint_comba_sqr6(word z[12], const word x[6])
Definition mp_comba.cpp:92
void bigint_comba_sqr8(word z[16], const word x[8])
Definition mp_comba.cpp:322
void bigint_comba_sqr16(word z[32], const word x[16])
Definition mp_comba.cpp:672
void bigint_comba_sqr9(word z[18], const word x[9])
Definition mp_comba.cpp:482
void bigint_comba_sqr24(word z[48], const word x[24])

References basecase_sqr(), bigint_comba_sqr16(), bigint_comba_sqr24(), bigint_comba_sqr4(), bigint_comba_sqr6(), bigint_comba_sqr8(), bigint_comba_sqr9(), bigint_linmul3(), BOTAN_ASSERT, and zeroize_buffer().

Referenced by bigint_monty_sqr(), Botan::Montgomery_Params::sqr(), Botan::Barrett_Reduction::square(), and Botan::BigInt::square().

◆ bigint_sub2()

template<WordType W>
auto Botan::bigint_sub2 ( W x[],
size_t x_size,
const W y[],
size_t y_size ) -> W
inlineconstexpr

Two operand subtraction

Definition at line 152 of file mp_core.h.

152 {
153 W borrow = 0;
154
155 BOTAN_ASSERT(x_size >= y_size, "Expected sizes");
156
157 const size_t blocks = y_size - (y_size % 8);
158
159 for(size_t i = 0; i != blocks; i += 8) {
160 borrow = word8_sub2(x + i, y + i, borrow);
161 }
162
163 for(size_t i = blocks; i != y_size; ++i) {
164 x[i] = word_sub(x[i], y[i], &borrow);
165 }
166
167 for(size_t i = y_size; i != x_size; ++i) {
168 x[i] = word_sub(x[i], static_cast<W>(0), &borrow);
169 }
170
171 return borrow;
172}
constexpr auto word8_sub2(W x[8], const W y[8], W carry) -> W
Definition mp_asmi.h:380

References BOTAN_ASSERT, word8_sub2(), and word_sub().

Referenced by Botan::BigInt::add(), and Botan::Montgomery_Int::operator-=().

◆ bigint_sub2_rev()

template<WordType W>
void Botan::bigint_sub2_rev ( W x[],
const W y[],
size_t y_size )
inlineconstexpr

Two operand subtraction, x = y - x; assumes y >= x

Definition at line 178 of file mp_core.h.

178 {
179 W borrow = 0;
180
181 for(size_t i = 0; i != y_size; ++i) {
182 x[i] = word_sub(y[i], x[i], &borrow);
183 }
184
185 BOTAN_ASSERT(borrow == 0, "y must be greater than x");
186}

References BOTAN_ASSERT, and word_sub().

Referenced by Botan::BigInt::add().

◆ bigint_sub3()

template<WordType W>
auto Botan::bigint_sub3 ( W z[],
const W x[],
size_t x_size,
const W y[],
size_t y_size ) -> W
inlineconstexpr

Three operand subtraction

Expects that x_size >= y_size

Writes to z[0:x_size] and returns borrow

Definition at line 196 of file mp_core.h.

196 {
197 W borrow = 0;
198
199 BOTAN_ASSERT(x_size >= y_size, "Expected sizes");
200
201 const size_t blocks = y_size - (y_size % 8);
202
203 for(size_t i = 0; i != blocks; i += 8) {
204 borrow = word8_sub3(z + i, x + i, y + i, borrow);
205 }
206
207 for(size_t i = blocks; i != y_size; ++i) {
208 z[i] = word_sub(x[i], y[i], &borrow);
209 }
210
211 for(size_t i = y_size; i != x_size; ++i) {
212 z[i] = word_sub(x[i], static_cast<W>(0), &borrow);
213 }
214
215 return borrow;
216}

References BOTAN_ASSERT, word8_sub3(), and word_sub().

Referenced by Botan::BigInt::add2(), Botan::Montgomery_Int::ct_cond_negate(), Botan::BigInt::ct_reduce_below(), Botan::IntMod< MontgomeryRep< ScalarParams > >::invert_vartime(), is_perfect_square(), Botan::BigInt::mod_add(), Botan::BigInt::mod_sub(), Botan::BLS12_381::FieldElement::negate(), Botan::BLS12_381::Scalar::negate(), Botan::Montgomery_Int::operator-(), p_minus(), p_minus_1_over_2(), Botan::BigInt::reduce_below(), and reduce_mod().

◆ bigint_sub_abs()

template<WordType W>
auto Botan::bigint_sub_abs ( W z[],
const W x[],
const W y[],
size_t N,
W ws[] ) -> CT::Mask< W >
inlineconstexpr

Return abs(x-y), ie if x >= y, then compute z = x - y Otherwise compute z = y - x No borrow is possible since the result is always >= 0

Returns a Mask: |1| if x < y or |0| if x >= y

Parameters
zoutput array of at least N words
xinput array of N words
yinput array of N words
Nlength of x and y
wsarray of at least 2*N words

Definition at line 283 of file mp_core.h.

283 {
284 // Subtract in both direction then conditional copy out the result
285
286 W* ws0 = ws;
287 W* ws1 = ws + N;
288
289 W borrow0 = 0;
290 W borrow1 = 0;
291
292 const size_t blocks = N - (N % 8);
293
294 for(size_t i = 0; i != blocks; i += 8) {
295 borrow0 = word8_sub3(ws0 + i, x + i, y + i, borrow0);
296 borrow1 = word8_sub3(ws1 + i, y + i, x + i, borrow1);
297 }
298
299 for(size_t i = blocks; i != N; ++i) {
300 ws0[i] = word_sub(x[i], y[i], &borrow0);
301 ws1[i] = word_sub(y[i], x[i], &borrow1);
302 }
303
304 return CT::conditional_copy_mem(borrow0, z, ws1, ws0, N);
305}
constexpr Mask< T > conditional_copy_mem(Mask< T > mask, T *dest, const T *if_set, const T *if_unset, size_t elems)
Definition ct_utils.h:737

References Botan::CT::conditional_copy_mem(), word8_sub3(), and word_sub().

Referenced by gcd().

◆ bigint_submul()

template<WordType W>
auto Botan::bigint_submul ( W z[],
const W y[],
size_t N,
W q ) -> W
inlineconstexpr

Compute z[0:N] = z[0:N] - q * y[0:N]

Returns the borrow out, a full word value which the caller must subtract from z[N]

Definition at line 443 of file mp_core.h.

443 {
444 W mul_carry = 0;
445 W borrow = 0;
446
447 for(size_t i = 0; i != N; ++i) {
448 const W t = word_madd2(y[i], q, &mul_carry);
449 z[i] = word_sub(z[i], t, &borrow);
450 }
451
452 // Both mul_carry <= W_max - 1 and borrow <= 1, so this cannot overflow
453 return mul_carry + borrow;
454}

References word_madd2(), and word_sub().

Referenced by Botan::Montgomery_Int::mul_by_word().

◆ bit_permute_step()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::bit_permute_step ( T x,
T mask,
size_t shift )
constexpr

Definition at line 193 of file bit_ops.h.

193 {
194 /*
195 See https://reflectionsonsecurity.wordpress.com/2014/05/11/efficient-bit-permutation-using-delta-swaps/
196 and http://programming.sirrida.de/bit_perm.html
197 */
198 const T swap = ((x >> shift) ^ x) & mask;
199 return (x ^ swap) ^ (swap << shift);
200}

References BOTAN_FORCE_INLINE.

◆ bit_size_to_32bit_size()

size_t Botan::bit_size_to_32bit_size ( size_t bit_size)
inline

Definition at line 46 of file code_based_util.h.

46 {
47 return (bit_size - 1) / 32 + 1;
48}

Referenced by generate_mceliece_key(), mceliece_decrypt(), and mceliece_validate_key_params().

◆ bit_size_to_byte_size()

size_t Botan::bit_size_to_byte_size ( size_t bit_size)
inline

Definition at line 42 of file code_based_util.h.

42 {
43 return (bit_size - 1) / 8 + 1;
44}

Referenced by mceliece_decrypt().

◆ bitlen()

auto Botan::bitlen ( size_t x)
constexpr

Definition at line 101 of file pqcrystals_helpers.h.

101 {
102 return ceil_log2(x + 1);
103}
constexpr uint8_t ceil_log2(T x)
Definition bit_ops.h:140

References ceil_log2().

Referenced by Botan::DilithiumConstants::DilithiumConstants(), Botan::KyberConstants::KyberConstants(), and Botan::bitvector_base< secure_allocator >::subvector().

◆ booth_full_windows()

size_t Botan::booth_full_windows ( size_t sb,
size_t wb )
constexpr

Definition at line 1648 of file pcurves_impl.h.

1648 {
1649 if(sb % wb == 0) {
1650 return (sb - 1) / wb;
1651 } else {
1652 return sb / wb;
1653 }
1654}

Referenced by varpoint_mul().

◆ booth_initial_shift()

size_t Botan::booth_initial_shift ( size_t sb,
size_t wb )
constexpr

Definition at line 1656 of file pcurves_impl.h.

1656 {
1657 if(sb % wb == 0) {
1658 return wb;
1659 } else {
1660 return sb - (sb / wb) * wb;
1661 }
1662}

Referenced by varpoint_mul().

◆ booth_recode() [1/2]

std::pair< size_t, CT::Choice > Botan::booth_recode ( size_t x,
size_t window_bits )
inlineconstexpr

Booth signed digit recoding of a (window_bits + 1) bit window value, in constant time. Returns the digit, in [0, 2^(window_bits-1)], and a Choice which is set if the digit is to be negated.

Definition at line 1312 of file mp_core.h.

1312 {
1313 const auto sign = CT::Mask<size_t>::expand(x >> window_bits);
1314 const size_t neg_x = (static_cast<size_t>(1) << (window_bits + 1)) - x - 1;
1315 size_t digit = sign.select(neg_x, x);
1316 digit = (digit >> 1) + (digit & 1);
1317 return {digit, sign.as_choice()};
1318}

References Botan::CT::Mask< T >::expand().

Referenced by basemul_booth_exec(), basemul_booth_exec_vartime(), booth_recode(), Botan::BLS12_381::scalar_booth_window(), and varpoint_mul().

◆ booth_recode() [2/2]

template<size_t WindowBits, std::unsigned_integral T>
std::pair< size_t, CT::Choice > Botan::booth_recode ( T x)
constexpr

Definition at line 1321 of file mp_core.h.

1321 {
1322 static_assert(WindowBits >= 1 && WindowBits <= 16);
1323 return booth_recode(static_cast<size_t>(x), WindowBits);
1324}

References booth_recode().

◆ buffer_insert() [1/2]

template<typename T, typename Alloc, typename Alloc2>
size_t Botan::buffer_insert ( std::vector< T, Alloc > & buf,
size_t buf_offset,
const std::vector< T, Alloc2 > & input )

Copy into a buffer at an offset, truncating to the space available

Parameters
bufthe buffer to write into
buf_offsetthe offset in buf to write at
inputthe elements to copy
Returns
the number of elements actually copied

Definition at line 387 of file mem_ops.h.

387 {
388 BOTAN_ASSERT_NOMSG(buf_offset <= buf.size());
389 const size_t to_copy = std::min(input.size(), buf.size() - buf_offset);
390 if(to_copy > 0) {
391 copy_mem(&buf[buf_offset], input.data(), to_copy);
392 }
393 return to_copy;
394}

References BOTAN_ASSERT_NOMSG, buffer_insert(), and copy_mem().

◆ buffer_insert() [2/2]

template<typename T, typename Alloc>
size_t Botan::buffer_insert ( std::vector< T, Alloc > & buf,
size_t buf_offset,
const T input[],
size_t input_length )

Copy into a buffer at an offset, truncating to the space available

Parameters
bufthe buffer to write into
buf_offsetthe offset in buf to write at
inputthe elements to copy
input_lengththe number of elements in input
Returns
the number of elements actually copied

Definition at line 369 of file mem_ops.h.

369 {
370 BOTAN_ASSERT_NOMSG(buf_offset <= buf.size());
371 const size_t to_copy = std::min(input_length, buf.size() - buf_offset);
372 if(to_copy > 0) {
373 copy_mem(&buf[buf_offset], input, to_copy);
374 }
375 return to_copy;
376}

References BOTAN_ASSERT_NOMSG, buffer_insert(), and copy_mem().

Referenced by buffer_insert(), and buffer_insert().

◆ bytes_to_string()

std::string Botan::bytes_to_string ( std::span< const uint8_t > bytes)
inline

Definition at line 76 of file mem_utils.h.

76 {
77 return std::string(reinterpret_cast<const char*>(bytes.data()), bytes.size());
78}

Referenced by Botan::CryptoBox::decrypt(), Botan::PSK_Database::get_str(), Botan::TLS::TLS_Data_Reader::get_string(), Botan::TLS::PskIdentity::identity_as_string(), Botan::Encrypted_PSK_Database::list_names(), and Botan::ASN1::to_string().

◆ bytes_to_words()

template<WordType W, size_t N, size_t L>
auto Botan::bytes_to_words ( std::span< const uint8_t, L > bytes)
inlineconstexpr

Definition at line 1255 of file mp_core.h.

1255 {
1256 static_assert(L <= WordInfo<W>::bytes * N);
1257
1258 std::array<W, N> r = {};
1259
1260 constexpr size_t full_words = L / WordInfo<W>::bytes;
1261 constexpr size_t extra_bytes = L % WordInfo<W>::bytes;
1262
1263 static_assert(full_words + (extra_bytes ? 1 : 0) <= N);
1264
1265 for(size_t i = 0; i != full_words; ++i) {
1266 r[i] = load_be<W>(bytes.data(), full_words - 1 - i);
1267 }
1268
1269 if constexpr(extra_bytes > 0) {
1270 constexpr size_t shift = extra_bytes * 8;
1272
1273 for(size_t i = 0; i != extra_bytes; ++i) {
1274 const W b0 = bytes[WordInfo<W>::bytes * full_words + i];
1275 r[0] |= (b0 << (8 * (extra_bytes - 1 - i)));
1276 }
1277 }
1278
1279 return r;
1280}
constexpr W shift_left(std::array< W, N > &x)
Definition mp_core.h:888

References load_be(), and shift_left().

Referenced by Botan::Scalar448::bytes_are_reduced(), Botan::BLS12_381::FieldElement::deserialize(), Botan::BLS12_381::Scalar::deserialize(), Botan::IntMod< MontgomeryRep< ScalarParams > >::deserialize(), Botan::BLS12_381::FieldElement::from_bytes_wide(), Botan::BLS12_381::Scalar::from_bytes_wide(), Botan::IntMod< MontgomeryRep< ScalarParams > >::from_wide_bytes(), Botan::IntMod< MontgomeryRep< ScalarParams > >::from_wide_bytes_varlen(), and Botan::Scalar448::Scalar448().

◆ carry_shift()

uint64_t Botan::carry_shift ( const donna128 & a,
size_t shift )
inlineconstexpr

Definition at line 129 of file donna128.h.

129 {
130 return (a >> shift).lo();
131}

Referenced by bigint_shl1(), bigint_shl2(), bigint_shr1(), bigint_shr2(), and Botan::X25519_FE::mul_a24().

◆ cast_char_ptr_to_uint8() [1/2]

uint8_t * Botan::cast_char_ptr_to_uint8 ( char * s)
inline

Cast a char pointer to a uint8_t pointer

Parameters
sthe pointer to cast
Returns
s viewed as a byte pointer

Definition at line 313 of file mem_ops.h.

313 {
314 return reinterpret_cast<uint8_t*>(s);
315}

◆ cast_char_ptr_to_uint8() [2/2]

const uint8_t * Botan::cast_char_ptr_to_uint8 ( const char * s)
inline

Cast a char pointer to a uint8_t pointer

Parameters
sthe pointer to cast
Returns
s viewed as a byte pointer

Definition at line 304 of file mem_ops.h.

304 {
305 return reinterpret_cast<const uint8_t*>(s);
306}

◆ cast_uint8_ptr_to_char() [1/2]

const char * Botan::cast_uint8_ptr_to_char ( const uint8_t * b)
inline

◆ cast_uint8_ptr_to_char() [2/2]

char * Botan::cast_uint8_ptr_to_char ( uint8_t * b)
inline

Cast a uint8_t pointer to a char pointer

Parameters
bthe pointer to cast
Returns
b viewed as a char pointer

Definition at line 332 of file mem_ops.h.

332 {
333 return reinterpret_cast<char*>(b);
334}

◆ ceil_division()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::ceil_division ( T a,
T b )
constexpr

Ceil of an unsigned integer division. b must not be zero.

Parameters
adivident
bdivisor
Returns
ceil(a/b)

Definition at line 167 of file bit_ops.h.

167 {
168 // Same as `(a + b - 1) / b` but avoids possible overflow
169 return a / b + ((a % b != 0) ? 1 : 0);
170}

References BOTAN_FORCE_INLINE.

Referenced by Botan::EC_Point_Base_Point_Precompute::EC_Point_Base_Point_Precompute(), Botan::Classic_McEliece_Parameters::encode_out_size(), monty_multi_exp(), Botan::EC_Point_Base_Point_Precompute::mul(), Botan::EC_Point_Var_Point_Precompute::mul(), Botan::EC_Point_Multi_Point_Precompute::multi_exp(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::output_length(), pbkdf2(), and Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::set_associated_data_n().

◆ ceil_log2()

template<std::unsigned_integral T>
requires (sizeof(T) < 32)
uint8_t Botan::ceil_log2 ( T x)
constexpr

Definition at line 140 of file bit_ops.h.

142{
143 if(x >> (sizeof(T) * 8 - 1)) {
144 return sizeof(T) * 8;
145 }
146
147 uint8_t result = 0;
148 T compare = 1;
149
150 while(compare < x) {
151 compare <<= 1;
152 result++;
153 }
154
155 return result;
156}

Referenced by bitlen(), Botan::BigInt::ct_shift_left(), mceliece_validate_key_params(), mceliece_work_factor(), and Botan::McEliece_PublicKeyInternal::message_word_bit_length().

◆ ceil_tobytes()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::ceil_tobytes ( T bits)
constexpr

◆ chain_lengths()

BOTAN_TEST_API std::vector< WotsHashIndex > Botan::chain_lengths ( const SphincsTreeNode & msg,
const Sphincs_Parameters & params )

Given a msg construct the lengths (amount of hashes for signature) for each WOTS+ chain, including the checksum.

Corresponds to FIPS 205, Algorithm 7 or 8, Step 1-7

Definition at line 69 of file sp_wots.cpp.

69 {
70 std::vector<WotsHashIndex> result(params.wots_len_1() + params.wots_len_2());
71
72 const auto msg_base_w = std::span(result).first(params.wots_len_1());
73 const auto checksum_base_w = std::span(result).last(params.wots_len_2());
74
75 base_2_b(msg_base_w, msg.get(), params);
76 wots_checksum(checksum_base_w, msg_base_w, params);
77
78 return result;
79}
uint32_t wots_len_2() const
uint32_t wots_len_1() const
constexpr T & get() &
Definition strong_type.h:81

References Botan::detail::Strong_Base< T >::get(), Botan::Sphincs_Parameters::wots_len_1(), and Botan::Sphincs_Parameters::wots_len_2().

Referenced by wots_public_key_from_signature(), and xmss_sign_and_pkgen().

◆ check_bcrypt()

bool Botan::check_bcrypt ( std::string_view password,
std::string_view hash )

Check a previously created password hash

Takes a password and a bcrypt hash and returns true if the password is the same as the one that was used to generate the bcrypt hash.

Parameters
passwordthe password to check against
Hashesthe stored hash to check against

Definition at line 163 of file bcrypt.cpp.

163 {
164 if(hash.size() != 60 || hash[0] != '$' || hash[1] != '2' || hash[3] != '$' || hash[6] != '$') {
165 return false;
166 }
167
168 const char bcrypt_version = hash[2];
169
170 if(bcrypt_version != 'a' && bcrypt_version != 'b' && bcrypt_version != 'y') {
171 return false;
172 }
173
174 // bcrypt workfactor spec is always two characters
175 const auto workfactor = parse_u16(hash.substr(4, 2));
176
177 // bcrypt does support larger range of workfactors, this is what make_bcrypt allows
178 if(!workfactor.has_value() || *workfactor < 4 || *workfactor > 18) {
179 return false;
180 }
181
182 const std::vector<uint8_t> salt = bcrypt_base64_decode(hash.substr(7, 22));
183 if(salt.size() != 16) {
184 return false;
185 }
186
187 const std::string compare = make_bcrypt(pass, salt, *workfactor, bcrypt_version);
188
189 return CT::is_equal(as_span_of_bytes(hash), as_span_of_bytes(compare)).as_bool();
190}
std::optional< uint16_t > parse_u16(std::string_view input, bool require_canonical)
Definition parsing.cpp:59

References as_span_of_bytes(), Botan::CT::is_equal(), and parse_u16().

Referenced by botan_bcrypt_is_valid().

◆ check_passhash9()

bool Botan::check_passhash9 ( std::string_view password,
std::string_view hash )

Check a previously created password hash

Parameters
passwordthe password to check against
Hashesthe stored hash to check against

Definition at line 76 of file passhash9.cpp.

76 {
77 const size_t BINARY_LENGTH = ALGID_BYTES + WORKFACTOR_BYTES + PASSHASH9_PBKDF_OUTPUT_LEN + SALT_BYTES;
78
79 const size_t BASE64_LENGTH = MAGIC_PREFIX.size() + (BINARY_LENGTH * 8) / 6;
80
81 if(hash.size() != BASE64_LENGTH) {
82 return false;
83 }
84
85 for(size_t i = 0; i != MAGIC_PREFIX.size(); ++i) {
86 if(hash[i] != MAGIC_PREFIX[i]) {
87 return false;
88 }
89 }
90
91 secure_vector<uint8_t> bin = base64_decode(hash.substr(MAGIC_PREFIX.size()));
92
93 if(bin.size() != BINARY_LENGTH) {
94 return false;
95 }
96
97 const uint8_t alg_id = bin[0];
98
99 const size_t work_factor = load_be<uint16_t>(&bin[ALGID_BYTES], 0);
100
101 // Bug in the format, bad states shouldn't be representable, but are...
102 if(work_factor == 0) {
103 return false;
104 }
105
106 if(work_factor > 512) {
107 throw Invalid_Argument("Requested passhash9 work factor " + std::to_string(work_factor) + " is too large");
108 }
109
110 const size_t kdf_iterations = WORK_FACTOR_SCALE * work_factor;
111
112 auto pbkdf_prf = get_pbkdf_prf(alg_id);
113
114 if(!pbkdf_prf) {
115 return false; // unknown algorithm, reject
116 }
117
118 const PKCS5_PBKDF2 kdf(std::move(pbkdf_prf));
119
121 kdf.derive_key(PASSHASH9_PBKDF_OUTPUT_LEN, pass, &bin[ALGID_BYTES + WORKFACTOR_BYTES], SALT_BYTES, kdf_iterations)
122 .bits_of();
123
124 const uint8_t* hashbytes = &bin[ALGID_BYTES + WORKFACTOR_BYTES + SALT_BYTES];
125
126 return CT::is_equal(cmp.data(), hashbytes, PASSHASH9_PBKDF_OUTPUT_LEN).as_bool();
127}

References base64_decode(), Botan::OctetString::bits_of(), Botan::PBKDF::derive_key(), Botan::CT::is_equal(), and load_be().

◆ checked_add() [1/2]

template<std::unsigned_integral T>
std::optional< T > Botan::checked_add ( T a,
T b )
inlineconstexpr

Definition at line 19 of file int_utils.h.

19 {
20 const T r = a + b;
21 if(r < a || r < b) {
22 return {};
23 }
24 return r;
25}

Referenced by add_or_throw(), Botan::MDx_MB_Engine< W >::batch_hash(), checked_add(), Botan::AlternativeName::count(), Botan::OID::encode_into(), and wildcard_intersects_excluded_dns_subtree().

◆ checked_add() [2/2]

template<std::unsigned_integral T, std::unsigned_integral... Ts>
std::optional< T > Botan::checked_add ( T a,
T b,
Ts... rest )
inlineconstexpr

Definition at line 37 of file int_utils.h.

37 {
38 if(auto r = checked_add(a, b)) {
39 return checked_add(r.value(), rest...);
40 } else {
41 return {};
42 }
43}

References checked_add().

◆ checked_cast_to()

template<typename RT, typename AT>
RT Botan::checked_cast_to ( AT i)
constexpr

◆ checked_cast_to_or_throw()

template<typename RT, typename ExceptionType, typename AT>
RT Botan::checked_cast_to_or_throw ( AT i,
std::string_view error_msg_on_fail )
constexpr

Definition at line 91 of file int_utils.h.

91 {
92 const auto unwrapped_input = unwrap_strong_type(i);
93
94 const auto unwrapped_result = static_cast<strong_type_wrapped_type<RT>>(unwrapped_input);
95 if(unwrapped_input != static_cast<strong_type_wrapped_type<AT>>(unwrapped_result)) [[unlikely]] {
96 throw ExceptionType(error_msg_on_fail);
97 }
98
99 return wrap_strong_type<RT>(unwrapped_result);
100}
constexpr decltype(auto) unwrap_strong_type(T &&t)
Generically unwraps a strong type to its underlying type.
typename detail::wrapped_type_helper< std::remove_cvref_t< T > >::type strong_type_wrapped_type
Extracts the wrapped type from a strong type.
constexpr decltype(auto) wrap_strong_type(ParamT &&t)
Wraps a value into a caller-defined (strong) type.

References unwrap_strong_type(), and wrap_strong_type().

Referenced by checked_cast_to(), and Botan::HSS_LMS_Params::HSS_LMS_Params().

◆ checked_mul()

template<std::unsigned_integral T>
std::optional< T > Botan::checked_mul ( T a,
T b )
inlineconstexpr

Definition at line 46 of file int_utils.h.

46 {
47 // Multiplication by 1U is a hack to work around C's insane
48 // integer promotion rules.
49 // https://stackoverflow.com/questions/24795651
50 const T r = (1U * a) * b;
51 // If a == 0 then the multiply certainly did not overflow
52 // Otherwise r / a == b unless overflow occurred
53 if(a != 0 && r / a != b) {
54 return {};
55 }
56 return r;
57}

Referenced by Botan::mlock_allocator::allocate(), allocate_memory(), Botan::mlock_allocator::deallocate(), and mul_or_throw().

◆ checked_sub()

template<std::unsigned_integral T>
std::optional< T > Botan::checked_sub ( T a,
T b )
constexpr

Definition at line 28 of file int_utils.h.

28 {
29 if(b > a) {
30 return {};
31 }
32 return a - b;
33}

◆ choose()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::choose ( T mask,
T a,
T b )
constexpr

◆ clear_bytes()

void Botan::clear_bytes ( void * ptr,
size_t bytes )
inlineconstexpr

Zero out some bytes. Warning: use secure_scrub_memory instead if the memory is about to be freed or otherwise the compiler thinks it can elide the writes.

Parameters
ptra pointer to memory to zero
bytesthe number of bytes to zero in ptr

Definition at line 101 of file mem_ops.h.

101 {
102 if(bytes > 0) {
103 std::memset(ptr, 0, bytes);
104 }
105}

Referenced by clear_mem(), clear_mem(), Botan::TPM2::init_with_size(), and Botan::Memory_Pool::Memory_Pool().

◆ clear_mem() [1/2]

template<ranges::contiguous_output_range R>
requires std::is_trivially_copyable_v<std::ranges::range_value_t<R>>
void Botan::clear_mem ( R && mem)
inlineconstexpr

Zero memory before use. This simply calls memset and should not be used in cases where the compiler cannot see the call as a side-effecting operation.

Parameters
mema contiguous range of Ts to zero

Definition at line 130 of file mem_ops.h.

132{
133 clear_bytes(std::ranges::data(mem), ranges::size_bytes(mem));
134}
constexpr size_t size_bytes(const spanable_range auto &r)
constexpr void clear_bytes(void *ptr, size_t bytes)
Definition mem_ops.h:101

References clear_bytes(), and Botan::ranges::size_bytes().

◆ clear_mem() [2/2]

template<typename T>
void Botan::clear_mem ( T * ptr,
size_t n )
inlineconstexpr

Zero memory before use. This simply calls memset and should not be used in cases where the compiler cannot see the call as a side-effecting operation (for example, if calling clear_mem before deallocating memory, the compiler would be allowed to omit the call to memset entirely under the as-if rule.)

Parameters
ptra pointer to an array of Ts to zero
nthe number of Ts pointed to by ptr

Definition at line 118 of file mem_ops.h.

118 {
119 clear_bytes(ptr, sizeof(T) * n);
120}

References clear_bytes().

Referenced by base_decode(), Botan::MDx_MB_Engine< W >::batch_hash(), bigint_mulx_monty_mul(), bigint_mulx_sqr(), Botan_FFI::botan_view_bin_bounce_fn(), Botan::CT::copy_output(), Botan::Sodium::crypto_secretbox_xsalsa20poly1305(), Botan::Sodium::crypto_secretbox_xsalsa20poly1305_open(), Botan::BigInt::ct_reduce_below(), Botan::Bcrypt_PBKDF::derive_key(), Botan::BigInt::encode_words(), Botan::StreamCipher::generate_keystream(), Botan::Gf448Elem::Gf448Elem(), hex_decode(), Botan::BLAKE2b::key_schedule(), Botan::EC_Point_Var_Point_Precompute::mul(), Botan::FrodoMatrix::pack(), pbkdf2(), Botan::CRYSTALS::Trait_Base< ConstantsT, DerivedT >::polyvec_pointwise_acc_montgomery(), Botan::BigInt::reduce_below(), Botan::polyn_gf2m::set_to_zero(), Botan::polyn_gf2m::sqmod_init(), Botan::bitvector_base< secure_allocator >::to_bytes(), Botan::Zlib_Style_Stream< Stream, ByteType, StreamLenType >::Zlib_Style_Stream(), and Botan::Zlib_Style_Stream< Stream, ByteType, StreamLenType >::~Zlib_Style_Stream().

◆ clmul()

template<int M>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_CLMUL SIMD_4x32 Botan::clmul ( const SIMD_4x32 & H,
const SIMD_4x32 & x )

Definition at line 21 of file polyval_fn.h.

21 {
22 static_assert(M == 0x00 || M == 0x01 || M == 0x10 || M == 0x11, "Valid clmul mode");
23
24#if defined(BOTAN_SIMD_USE_SSSE3)
25 return SIMD_4x32(_mm_clmulepi64_si128(x.raw(), H.raw(), M));
26#elif defined(BOTAN_SIMD_USE_NEON)
27 const uint64_t a = vgetq_lane_u64(vreinterpretq_u64_u32(x.raw()), M & 0x01);
28 const uint64_t b = vgetq_lane_u64(vreinterpretq_u64_u32(H.raw()), (M & 0x10) >> 4);
29
30 #if defined(BOTAN_BUILD_COMPILER_IS_MSVC)
31 __n64 a1 = {a}, b1 = {b};
32 return SIMD_4x32(vmull_p64(a1, b1));
33 #else
34 return SIMD_4x32(reinterpret_cast<uint32x4_t>(vmull_p64(a, b)));
35 #endif
36
37#elif defined(BOTAN_SIMD_USE_VSX)
38 const SIMD_4x32 mask_lo = SIMD_4x32(0, 0, 0xFFFFFFFF, 0xFFFFFFFF);
39 constexpr uint8_t flip = (std::endian::native == std::endian::big) ? 0x11 : 0x00;
40
41 SIMD_4x32 i1 = x;
42 SIMD_4x32 i2 = H;
43
44 if constexpr(std::endian::native == std::endian::big) {
45 i1 = i1.reverse_all_bytes().bswap();
46 i2 = i2.reverse_all_bytes().bswap();
47 }
48
49 if constexpr(M == (0x11 ^ flip)) {
50 i1 &= mask_lo;
51 i2 &= mask_lo;
52 } else if constexpr(M == (0x10 ^ flip)) {
53 i1 = i1.shift_elems_left<2>();
54 } else if constexpr(M == (0x01 ^ flip)) {
55 i2 = i2.shift_elems_left<2>();
56 } else if constexpr(M == (0x00 ^ flip)) {
57 i1 = mask_lo.andc(i1);
58 i2 = mask_lo.andc(i2);
59 }
60
61 auto i1v = reinterpret_cast<__vector unsigned long long>(i1.raw());
62 auto i2v = reinterpret_cast<__vector unsigned long long>(i2.raw());
63
64 #if BOTAN_COMPILER_HAS_BUILTIN(__builtin_crypto_vpmsumd)
65 auto rv = __builtin_crypto_vpmsumd(i1v, i2v);
66 #else
67 auto rv = __builtin_altivec_crypto_vpmsumd(i1v, i2v);
68 #endif
69
70 auto z = SIMD_4x32(reinterpret_cast<__vector unsigned int>(rv));
71
72 if constexpr(std::endian::native == std::endian::big) {
73 z = z.reverse_all_bytes().bswap();
74 }
75
76 return z;
77#endif
78}
native_simd_type BOTAN_FN_ISA_SIMD_4X32 raw() const noexcept
Definition simd_4x32.h:964

References Botan::SIMD_4x32::andc(), BOTAN_FORCE_INLINE, Botan::SIMD_4x32::bswap(), Botan::SIMD_4x32::raw(), Botan::SIMD_4x32::reverse_all_bytes(), and Botan::SIMD_4x32::shift_elems_left().

Referenced by polyval_multiply(), and polyval_reduce().

◆ comba_mul()

template<size_t N, WordType W>
void Botan::comba_mul ( W z[2 *N],
const W x[N],
const W y[N] )
inlineconstexpr

Definition at line 981 of file mp_core.h.

981 {
982 if(!std::is_constant_evaluated()) {
983 if constexpr(std::same_as<W, word> && N == 4) {
984 return bigint_comba_mul4(z, x, y);
985 }
986 if constexpr(std::same_as<W, word> && N == 6) {
987 return bigint_comba_mul6(z, x, y);
988 }
989 if constexpr(std::same_as<W, word> && N == 7) {
990 return bigint_comba_mul7(z, x, y);
991 }
992 if constexpr(std::same_as<W, word> && N == 8) {
993 return bigint_comba_mul8(z, x, y);
994 }
995 if constexpr(std::same_as<W, word> && N == 9) {
996 return bigint_comba_mul9(z, x, y);
997 }
998 if constexpr(std::same_as<W, word> && N == 16) {
999 return bigint_comba_mul16(z, x, y);
1000 }
1001 }
1002
1003 word3<W> accum;
1004
1005 for(size_t i = 0; i != 2 * N; ++i) {
1006 const size_t start = i + 1 < N ? 0 : i + 1 - N;
1007 const size_t end = std::min(N, i + 1);
1008
1009 for(size_t j = start; j != end; ++j) {
1010 accum.mul(x[j], y[i - j]);
1011 }
1012 z[i] = accum.extract();
1013 }
1014}
void bigint_comba_mul7(word z[14], const word x[7], const word y[7])
Definition mp_comba.cpp:251

References bigint_comba_mul16(), bigint_comba_mul4(), bigint_comba_mul6(), bigint_comba_mul7(), bigint_comba_mul8(), bigint_comba_mul9(), Botan::word3< W >::extract(), and Botan::word3< W >::mul().

Referenced by Botan::BlindedScalarBits< C, WindowBits+1 >::BlindedScalarBits(), Botan::BLS12_381::FieldElement::mul(), Botan::BLS12_381::Scalar::mul(), Botan::Ed25519_FieldElement::mul(), mul_mod(), Botan::IntMod< MontgomeryRep< ScalarParams > >::operator*, Botan::IntMod< MontgomeryRep< ScalarParams > >::operator*=(), Botan::MontgomeryRep< Params >::to_rep(), and Botan::MontgomeryRep< Params >::wide_to_rep().

◆ comba_sqr()

template<size_t N, WordType W>
void Botan::comba_sqr ( W z[2 *N],
const W x[N] )
inlineconstexpr

Definition at line 1017 of file mp_core.h.

1017 {
1018 if(!std::is_constant_evaluated()) {
1019 if constexpr(std::same_as<W, word> && N == 4) {
1020 return bigint_comba_sqr4(z, x);
1021 }
1022 if constexpr(std::same_as<W, word> && N == 6) {
1023 return bigint_comba_sqr6(z, x);
1024 }
1025 if constexpr(std::same_as<W, word> && N == 7) {
1026 return bigint_comba_sqr7(z, x);
1027 }
1028 if constexpr(std::same_as<W, word> && N == 8) {
1029 return bigint_comba_sqr8(z, x);
1030 }
1031 if constexpr(std::same_as<W, word> && N == 9) {
1032 return bigint_comba_sqr9(z, x);
1033 }
1034 if constexpr(std::same_as<W, word> && N == 16) {
1035 return bigint_comba_sqr16(z, x);
1036 }
1037 }
1038
1039 word3<W> accum;
1040
1041 for(size_t i = 0; i != 2 * N; ++i) {
1042 const size_t start = i + 1 < N ? 0 : i + 1 - N;
1043 const size_t end = std::min(N, i + 1);
1044
1045 for(size_t j = start; j != end; ++j) {
1046 accum.mul(x[j], x[i - j]);
1047 }
1048 z[i] = accum.extract();
1049 }
1050}
void bigint_comba_sqr7(word z[14], const word x[7])
Definition mp_comba.cpp:201

References bigint_comba_sqr16(), bigint_comba_sqr4(), bigint_comba_sqr6(), bigint_comba_sqr7(), bigint_comba_sqr8(), bigint_comba_sqr9(), Botan::word3< W >::extract(), and Botan::word3< W >::mul().

Referenced by Botan::Ed25519_FieldElement::sqr(), Botan::Ed25519_FieldElement::sqr_iter(), Botan::BLS12_381::FieldElement::square(), Botan::BLS12_381::Scalar::square(), Botan::IntMod< MontgomeryRep< ScalarParams > >::square(), and Botan::IntMod< MontgomeryRep< ScalarParams > >::square_n().

◆ combine_lower()

uint64_t Botan::combine_lower ( const donna128 & a,
size_t s1,
const donna128 & b,
size_t s2 )
inlineconstexpr

Definition at line 133 of file donna128.h.

133 {
134 const donna128 z = (a >> s1) | (b << s2);
135 return z.lo();
136}
constexpr uint64_t lo() const
Definition donna128.h:83

References Botan::donna128::lo().

Referenced by Botan::X25519_FE::encode().

◆ commoncrypto_adjust_key_size()

void Botan::commoncrypto_adjust_key_size ( const uint8_t key[],
size_t length,
const CommonCryptor_Opts & opts,
secure_vector< uint8_t > & full_key )

Definition at line 143 of file commoncrypto_utils.cpp.

146 {
147 if(opts.algo == kCCAlgorithmBlowfish && length < 8) {
148 size_t repeat;
149 switch(length) {
150 case 1:
151 repeat = 8;
152 break;
153 case 2:
154 repeat = 4;
155 break;
156 case 3:
157 repeat = 3;
158 break;
159 default:
160 repeat = 2;
161 break;
162 }
163
164 full_key.resize(length * repeat);
165 for(size_t i = 0; i < repeat; i++) {
166 copy_mem(full_key.data() + i * length, key, length);
167 }
168 } else if(opts.algo == kCCAlgorithm3DES && length == 16) {
169 full_key += std::make_pair(key, 8);
170 }
171}

References Botan::CommonCryptor_Opts::algo, and copy_mem().

◆ commoncrypto_opts_from_algo()

CommonCryptor_Opts Botan::commoncrypto_opts_from_algo ( std::string_view algo)

Definition at line 95 of file commoncrypto_utils.cpp.

95 {
97
98 std::string_view algo_name = spec.head();
99 std::string_view cipher_mode;
100 std::string_view cipher_mode_padding;
101
102 //TODO add CFB and XTS support
103 if(auto m = spec.match("*({cipher},{padding:str?})")) {
104 algo_name = m->str("cipher");
105 cipher_mode = m->head();
106 if(m->has("padding")) {
107 cipher_mode_padding = m->str("padding");
108 }
109 } else if(spec.arg_count() != 0) {
110 throw CommonCrypto_Error("Unsupported cipher mode!");
111 }
112
114
115 if(cipher_mode.empty() || cipher_mode == "ECB") {
116 opts.mode = kCCModeECB;
117 } else if(cipher_mode == "CBC") {
118 opts.mode = kCCModeCBC;
119 } else if(cipher_mode == "CTR") {
120 opts.mode = kCCModeCTR;
121 } else if(cipher_mode == "OFB") {
122 opts.mode = kCCModeOFB;
123 } else {
124 throw CommonCrypto_Error("Unsupported cipher mode!");
125 }
126
127 if(cipher_mode_padding == "NoPadding") {
128 opts.padding = ccNoPadding;
129 }
130 /*
131 else if(cipher_mode_padding.empty() || cipher_mode_padding == "PKCS7")
132 {
133 opts.padding = ccPKCS7Padding;
134 }
135 */
136 else {
137 throw CommonCrypto_Error("Unsupported cipher mode padding!");
138 }
139
140 return opts;
141}
CommonCryptor_Opts commoncrypto_opts_from_algo_name(std::string_view algo_name)

References Botan::AlgorithmSpec::arg_count(), Botan::AlgorithmSpec::CipherMode, commoncrypto_opts_from_algo_name(), Botan::AlgorithmSpec::head(), Botan::AlgorithmSpec::match(), Botan::CommonCryptor_Opts::mode, and Botan::CommonCryptor_Opts::padding.

Referenced by make_commoncrypto_cipher_mode().

◆ commoncrypto_opts_from_algo_name()

CommonCryptor_Opts Botan::commoncrypto_opts_from_algo_name ( std::string_view algo_name)

Definition at line 55 of file commoncrypto_utils.cpp.

55 {
57
58 if(algo_name.compare(0, 3, "AES") == 0) {
59 opts.algo = kCCAlgorithmAES;
60 opts.block_size = kCCBlockSizeAES128;
61 if(algo_name == "AES-128") {
62 opts.key_spec = Key_Length_Specification(kCCKeySizeAES128);
63 } else if(algo_name == "AES-192") {
64 opts.key_spec = Key_Length_Specification(kCCKeySizeAES192);
65 } else if(algo_name == "AES-256") {
66 opts.key_spec = Key_Length_Specification(kCCKeySizeAES256);
67 } else {
68 throw CommonCrypto_Error("Unknown AES algorithm");
69 }
70 } else if(algo_name == "DES") {
71 opts.algo = kCCAlgorithmDES;
72 opts.block_size = kCCBlockSizeDES;
73 opts.key_spec = Key_Length_Specification(kCCKeySizeDES);
74 } else if(algo_name == "TripleDES") {
75 opts.algo = kCCAlgorithm3DES;
76 opts.block_size = kCCBlockSize3DES;
77 opts.key_spec = Key_Length_Specification(16, kCCKeySize3DES, 8);
78 } else if(algo_name == "Blowfish") {
79 opts.algo = kCCAlgorithmBlowfish;
80 opts.block_size = kCCBlockSizeBlowfish;
81 opts.key_spec = Key_Length_Specification(1, kCCKeySizeMaxBlowfish, 1);
82 } else if(algo_name == "CAST-128") {
83 opts.algo = kCCAlgorithmCAST;
84 opts.block_size = kCCBlockSizeCAST;
85 // Botan's base implementation of CAST does not support shorter keys
86 // so we limit its minimum key size to 11 here.
87 opts.key_spec = Key_Length_Specification(11, kCCKeySizeMaxCAST, 1);
88 } else {
89 throw CommonCrypto_Error("Unsupported cipher");
90 }
91
92 return opts;
93}
Key_Length_Specification key_spec

References Botan::CommonCryptor_Opts::algo, Botan::CommonCryptor_Opts::block_size, and Botan::CommonCryptor_Opts::key_spec.

Referenced by commoncrypto_opts_from_algo(), and make_commoncrypto_block_cipher().

◆ compute_root() [1/2]

BOTAN_TEST_API void Botan::compute_root ( StrongSpan< SphincsTreeNode > out,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hashes,
const SphincsTreeNode & leaf,
TreeNodeIndex leaf_idx,
uint32_t idx_offset,
StrongSpan< const SphincsAuthenticationPath > authentication_path,
uint32_t tree_height,
Sphincs_Address & tree_address )

Using a leaf node and the authentication path (neighbor nodes on the way from leaf to root), computes the the root node of the respective tree. This function is generic and used by FORS and XMSS in the SLH-DSA verification logic.

Definition at line 113 of file sp_treehash.cpp.

121 {
122 BOTAN_ASSERT_NOMSG(out.size() == params.n());
123 BOTAN_ASSERT_NOMSG(authentication_path.size() == params.n() * total_tree_height);
124 BOTAN_ASSERT_NOMSG(leaf.size() == params.n());
125
126 // Use the `out` parameter as intermediate buffer for left/right nodes
127 // while traversing the tree.
128 copy_mem(out, leaf);
129
130 // Views into either `auth_path` or `out` depending on the tree location.
133
134 BufferSlicer auth_path(authentication_path);
135
136 // The leaf is put in the left or right buffer, depending on its indexes parity.
137 // Same for the first node of the authentication path
138
139 for(TreeLayerIndex i(0); i < total_tree_height; i++) {
140 // The input of the hash function takes the current node and the node
141 // given in the authentication path. If the current node is a right node
142 // in the tree (i.e. its leaf index is uneven) the hash function inputs
143 // must be swapped.
144 left = out;
145 right = auth_path.take<SphincsTreeNode>(params.n());
146
147 if((leaf_idx & 1) == 1U) {
148 std::swap(left, right);
149 }
150
151 leaf_idx /= 2;
152 idx_offset /= 2;
153 tree_address.set_tree_height(i + 1).set_tree_index(leaf_idx + idx_offset);
154
155 hashes.T(out, tree_address, left, right);
156 }
157
158 BOTAN_ASSERT_NOMSG(auth_path.empty());
159}
Sphincs_Address & set_tree_height(TreeLayerIndex tree_height)
Definition sp_address.h:86
Sphincs_Address & set_tree_index(TreeNodeIndex tree_index)
Definition sp_address.h:96
void T(std::span< uint8_t > out, const Sphincs_Address &address, const BufferTs &... in)
Definition sp_hash.h:59
decltype(auto) size() const noexcept(noexcept(this->m_span.size()))
size_type size() const noexcept(noexcept(this->get().size()))
Strong< std::vector< uint8_t >, struct SphincsTreeNode_ > SphincsTreeNode
Either an XMSS or FORS tree node or leaf.
Definition sp_types.h:70
Strong< uint32_t, struct TreeLayerIndex_, EnableArithmeticWithPlainNumber > TreeLayerIndex
Index of the layer within a FORS/XMSS tree.
Definition sp_types.h:83

References BOTAN_ASSERT_NOMSG, copy_mem(), Botan::BufferSlicer::empty(), Botan::Sphincs_Parameters::n(), Botan::Sphincs_Address::set_tree_height(), Botan::Sphincs_Address::set_tree_index(), Botan::detail::Container_Strong_Adapter_Base< T >::size(), Botan::StrongSpan< T >::size(), Botan::Sphincs_Hash_Functions::T(), and Botan::BufferSlicer::take().

Referenced by fors_public_key_from_signature(), and ht_verify().

◆ compute_root() [2/2]

template<concepts::contiguous_strong_type TreeNode, concepts::strong_span AuthPathSS, concepts::tree_node_index TreeNodeIndex, concepts::tree_layer_index TreeLayerIndex, typename Address>
void Botan::compute_root ( StrongSpan< TreeNode > out_root,
AuthPathSS authentication_path,
TreeNodeIndex leaf_idx,
StrongSpan< const TreeNode > leaf,
size_t node_size,
TreeLayerIndex total_tree_height,
uint32_t idx_offset,
concepts::tree_hash_node_pair< TreeNodeIndex, TreeLayerIndex, Address, StrongSpan< TreeNode > > auto node_pair_hash,
Address & tree_address )
inline

Uses an authentication path and a leaf node to reconstruct the root node of a merkle tree.

Parameters
out_rootA output buffer for the root node of the merkle tree.
authentication_pathThe authentication path in one buffer (concatenated nodes).
leaf_idxThe index of the leaf used to sig in the bottom layer beginning with 0.
leafThe leaf node used to sig.
node_sizeThe size of each node in the tree.
total_tree_heightThe height of the merkle tree to construct.
idx_offsetIf we compute a subtree this marks the index of the leftmost leaf node in the bottom layer.
node_pair_hashThe function to process two child nodes to compute their parent node.
tree_addressThe address that is passed to node_pair hash. This function will update the address accordings to the currently processed node. This object may contain further algorithm specific information, like the position of this merkle tree in a hypertree.

Definition at line 223 of file tree_hash.h.

232 {
233 BOTAN_ASSERT_NOMSG(out_root.size() == node_size);
234 BOTAN_ASSERT_NOMSG(authentication_path.size() == node_size * static_cast<size_t>(total_tree_height.get()));
235 BOTAN_ASSERT_NOMSG(leaf.size() == node_size);
236
237 // Use the `out` parameter as intermediate buffer for left/right nodes
238 // while traversing the tree.
239 copy_mem(out_root, leaf);
240
241 // Views into either `auth_path` or `out` depending on the tree location.
244
245 BufferSlicer auth_path(authentication_path);
246
247 // The leaf is put in the left or right buffer, depending on its indexes parity.
248 // Same for the first node of the authentication path
249
250 for(TreeLayerIndex i(0); i < total_tree_height; i++) {
251 // The input of the hash function takes the current node and the node
252 // given in the authentication path. If the current node is a right node
253 // in the tree (i.e. its leaf index is uneven) the hash function inputs
254 // must be swapped.
255 left = out_root;
256 right = auth_path.take<TreeNode>(node_size);
257
258 if((leaf_idx & 1) == 1U) {
259 std::swap(left, right);
260 }
261
262 leaf_idx /= 2;
263 idx_offset /= 2;
264 tree_address.set_address(i + 1, leaf_idx + idx_offset);
265
266 node_pair_hash(out_root, tree_address, left, right);
267 }
268
269 BOTAN_ASSERT_NOMSG(auth_path.empty());
270}

References BOTAN_ASSERT_NOMSG, copy_mem(), Botan::BufferSlicer::empty(), Botan::detail::Strong_Base< T >::get(), Botan::StrongSpan< T >::size(), and Botan::BufferSlicer::take().

◆ compute_rsa_secret_exponent()

std::optional< BigInt > BOTAN_TEST_API Botan::compute_rsa_secret_exponent ( const BigInt & e,
const BigInt & phi_n,
const BigInt & p,
const BigInt & q )

Compute the RSA private exponent d

This algorithm is constant time with respect to phi_n, p, and q, aside from leaking their lengths. It may leak the public exponent e.

Parameters
ethe public exponent
phi_nis lcm(p-1, q-1)
pis the first secret prime
qis the second secret prime
Returns
d inverse of e modulo phi_n, or nullopt if gcd(e, phi_n) != 1

Throws Invalid_Argument if e or phi_n are not positive

Definition at line 337 of file mod_inv.cpp.

340 {
341 BOTAN_ARG_CHECK(e > 0 && phi_n > 0, "RSA exponent and lcm(p-1, q-1) must be positive");
342
343 // TODO possibly do something else taking advantage of the special structure here
344 BOTAN_UNUSED(p, q);
345
346 if(e == 65537) {
347 /*
348 Arazi's algorithm for inversion of prime x modulo a non-prime
349
350 "GCD-Free Algorithms for Computing Modular Inverses"
351 Marc Joye and Pascal Paillier, CHES 2003 (LNCS 2779)
352 https://marcjoye.github.io/papers/JP03gcdfree.pdf
353
354 This could be extended to cover other cases such as e=3 or e=17 but
355 these days 65537 is the standard RSA public exponent
356 */
357
358 constexpr word e_w = 65537;
359
360 const word phi_mod_e = ct_mod_word(phi_n, e_w);
361
362 // If e divides phi_n there is no inverse, which the general path below reports
363 if(CT::driveby_unpoison(phi_mod_e != 0)) {
364 const word inv_phi_mod_e = inverse_mod_65537(phi_mod_e);
365 BOTAN_DEBUG_ASSERT((inv_phi_mod_e * phi_mod_e) % e_w == 1);
366 const word neg_inv_phi_mod_e = (e_w - inv_phi_mod_e);
367 return ct_divide_word((phi_n * neg_inv_phi_mod_e) + 1, e_w);
368 }
369 }
370
371 // inverse_mod_general requires its argument to be reduced
372 const BigInt e_mod_phi = ct_modulo(e, phi_n);
373
374 if(e_mod_phi.is_zero()) {
375 return std::nullopt;
376 }
377
378 CT::unpoison_all(e_mod_phi, phi_n);
379 return inverse_mod_general(e_mod_phi, phi_n);
380}
constexpr decltype(auto) driveby_unpoison(T &&v)
Definition ct_utils.h:243
constexpr void unpoison_all(const Ts &... ts)
Definition ct_utils.h:207
word ct_mod_word(const BigInt &x, word y)
Definition divide.cpp:247
BigInt ct_modulo(const BigInt &x, const BigInt &y)
Definition divide.cpp:262
void ct_divide_word(const BigInt &x, word y, BigInt &q_out, word &r_out)
Definition divide.cpp:205
std::optional< BigInt > inverse_mod_general(const BigInt &x, const BigInt &mod)
Definition mod_inv.cpp:175

References BOTAN_ARG_CHECK, BOTAN_DEBUG_ASSERT, BOTAN_UNUSED, ct_divide_word(), ct_mod_word(), ct_modulo(), Botan::CT::driveby_unpoison(), inverse_mod_general(), Botan::BigInt::is_zero(), and Botan::CT::unpoison_all().

Referenced by Botan::RSA_PrivateKey::RSA_PrivateKey(), and Botan::RSA_PrivateKey::RSA_PrivateKey().

◆ concat()

template<typename OutR = detail::AutoDetect, ranges::spanable_range... Rs>
requires (all_same_v<std::ranges::range_value_t<Rs>...>)
auto Botan::concat ( Rs &&... ranges)
constexpr

Concatenate an arbitrary number of buffers. Performs range-checks as needed.

The output type can be auto-detected based on the input ranges, or explicitly specified by the caller. If all input ranges have a static extent, the total size is calculated at compile time and a statically sized std::array<> is used. Otherwise this tries to use the type of the first input range as output type.

Alternatively, the output container type can be specified explicitly.

Definition at line 95 of file concat_util.h.

97{
98 if constexpr(std::same_as<detail::AutoDetect, OutR>) {
99 // Try to auto-detect a reasonable output type given the input ranges
100 static_assert(sizeof...(Rs) > 0, "Cannot auto-detect the output type if not a single input range is provided.");
101 using candidate_result_t = std::remove_cvref_t<std::tuple_element_t<0, std::tuple<Rs...>>>;
102 using result_range_value_t = std::remove_cvref_t<std::ranges::range_value_t<candidate_result_t>>;
103
104 if constexpr((ranges::statically_spanable_range<Rs> && ...)) {
105 // If all input ranges have a static extent, we can calculate the total size at compile time
106 // and therefore can use a statically sized output container. This is constexpr.
107 constexpr size_t total_size = (decltype(std::span{ranges})::extent + ... + 0);
108 using out_array_t = std::array<result_range_value_t, total_size>;
109 return detail::concatenate<out_array_t>(std::forward<Rs>(ranges)...);
110 } else {
111 // If at least one input range has a dynamic extent, we must use a dynamically allocated output container.
112 // We assume that the user wants to use the first input range's container type as output type.
113 static_assert(
115 "First input range has static extent, but a dynamically allocated output range is required. Please explicitly specify a dynamically allocatable output type.");
116 return detail::concatenate<candidate_result_t>(std::forward<Rs>(ranges)...);
117 }
118 } else {
119 // The caller has explicitly specified the output type
120 return detail::concatenate<OutR>(std::forward<Rs>(ranges)...);
121 }
122}
constexpr OutR concatenate(Rs &&... ranges)
Definition concat_util.h:34

References Botan::detail::concatenate().

Referenced by Botan::Classic_McEliece_Polynomial_Ring::compute_minimal_polynomial(), Botan::XMSS_Common_Ops::create_l_trees(), Botan::TLS::PSKImporter::derive_imported_psk(), Botan::GeneralName::encode_into(), Botan::Expanded_Keypair_Codec::encode_keypair(), Botan::Seed_Expanding_Keypair_Codec::encode_keypair(), hkdf_expand_label(), Botan::TLS::Cipher_State::hkdf_expand_label(), Botan::TLS::Channel_Impl_12::key_material_export(), Botan::Kyber_PublicKeyInternal::Kyber_PublicKeyInternal(), Botan::HPKE::labeled_expand(), Botan::HPKE::labeled_extract(), Botan::SphincsPlus_PrivateKey::private_key_bits(), Botan::SPAKE2p::VerifierContext::process_message(), Botan::FrodoKEM_PrivateKey::raw_private_key_bits(), Botan::FrodoKEM_PublicKey::raw_public_key_bits(), Botan::Hybrid_PublicKey::raw_public_key_bits(), Botan::TLS::Hybrid_KEM_PublicKey::raw_public_key_bits(), Botan::Kyber_Algos::PolynomialSampler< SeedT >::sample_polynomial_vector_and_poly_cbd_eta2(), Botan::Kyber_Algos::PolynomialSampler< SeedT >::sample_polynomial_vector_pair_cbd_eta1(), Botan::TLS::Channel_Impl_12::secure_renegotiation_data_for_server_hello(), Botan::Classic_McEliece_PrivateKeyInternal::serialize(), Botan::SPAKE2p::RegistrationRecord::serialize(), Botan::TLS::Record_TLS::serialize_header(), Botan::Ascon_AEAD128_Mode::start_msg(), Botan::HSS_LMS_PublicKeyInternal::to_bytes(), and Botan::LMS_PublicKey::to_bytes().

◆ constant_time_compare() [1/2]

bool Botan::constant_time_compare ( const uint8_t x[],
const uint8_t y[],
size_t len )
inline

Memory comparison, input insensitive

Parameters
xa pointer to an array
ya pointer to another array
lenthe number of Ts in x and y
Returns
true iff x[i] == y[i] forall i in [0...n)

Definition at line 88 of file mem_ops.h.

88 {
89 // simply assumes that *x and *y point to len allocated bytes at least
90 return constant_time_compare({x, len}, {y, len});
91}
bool constant_time_compare(std::span< const uint8_t > x, std::span< const uint8_t > y)
Definition mem_ops.cpp:17

References constant_time_compare().

◆ constant_time_compare() [2/2]

bool Botan::constant_time_compare ( std::span< const uint8_t > x,
std::span< const uint8_t > y )

Memory comparison, input insensitive

Parameters
xa range of bytes
yanother range of bytes
Returns
true iff x and y have equal lengths and x[i] == y[i] forall i in [0...n)

Definition at line 17 of file mem_ops.cpp.

17 {
18 const auto min_size = CT::Mask<size_t>::is_lte(x.size(), y.size()).select(x.size(), y.size());
19 const auto equal_size = CT::Mask<size_t>::is_equal(x.size(), y.size());
20 const auto equal_content = CT::Mask<size_t>::expand(CT::is_equal(x.data(), y.data(), min_size));
21 return (equal_content & equal_size).as_bool();
22}
static constexpr Mask< T > is_lte(T x, T y)
Definition ct_utils.h:468

References Botan::CT::Mask< T >::expand(), Botan::CT::is_equal(), Botan::CT::Mask< T >::is_equal(), and Botan::CT::Mask< T >::is_lte().

Referenced by constant_time_compare(), Botan::Expanded_Keypair_Codec::decode_keypair(), decode_ml_kem_private_key(), Botan::SPAKE2p::ProverContext::process_message(), Botan::PKCS1v15_Raw_SignaturePaddingScheme::verify(), Botan::PKCS1v15_SignaturePaddingScheme::verify(), and Botan::SPAKE2p::VerifierContext::verify_confirmation().

◆ copy_mem() [1/2]

template<ranges::contiguous_output_range OutR, ranges::contiguous_range InR>
void Botan::copy_mem ( OutR && out,
const InR & in )
inlineconstexpr

Copy memory

Parameters
outthe destination array
inthe source array

Definition at line 160 of file mem_ops.h.

160 {
162 if(std::is_constant_evaluated()) {
163 std::copy(std::ranges::begin(in), std::ranges::end(in), std::ranges::begin(out));
164 } else if(ranges::size_bytes(out) > 0) {
165 std::memmove(std::ranges::data(out), std::ranges::data(in), ranges::size_bytes(out));
166 }
167}
constexpr void assert_equal_byte_lengths(const R0 &r0, const Rs &... rs)

References Botan::ranges::assert_equal_byte_lengths(), and Botan::ranges::size_bytes().

◆ copy_mem() [2/2]

template<typename T>
void Botan::copy_mem ( T * out,
const T * in,
size_t n )
inlineconstexpr

Copy memory

Parameters
outthe destination array
inthe source array
nthe number of elements of in/out

Definition at line 144 of file mem_ops.h.

144 {
145 BOTAN_ASSERT_IMPLICATION(n > 0, in != nullptr && out != nullptr, "If n > 0 then args are not null");
146
147 if(in != nullptr && out != nullptr && n > 0) {
148 std::memmove(out, in, sizeof(T) * n);
149 }
150}
#define BOTAN_ASSERT_IMPLICATION(expr1, expr2, msg)
Definition assert.h:108

References BOTAN_ASSERT_IMPLICATION.

Referenced by Botan::TLS::Connection_Cipher_State::aead_nonce(), Botan::TLS::Connection_Cipher_State::aead_nonce(), append(), base58_check_encode(), base58_decode(), Botan::MDx_MB_Engine< W >::batch_hash(), bigint_mulx_mul9(), Botan::Argon2::blamka(), Botan::BlindingRandomness< BlindedScalar, Scalars >::BlindingRandomness(), botan_cipher_update(), botan_privkey_ed25519_get_privkey(), botan_privkey_ed448_get_privkey(), botan_privkey_x25519_get_privkey(), botan_privkey_x448_get_privkey(), botan_pubkey_ed25519_get_pubkey(), botan_pubkey_ed448_get_pubkey(), botan_pubkey_x25519_get_pubkey(), botan_pubkey_x448_get_pubkey(), Botan_FFI::botan_view_bin_bounce_fn(), buffer_insert(), buffer_insert(), Botan::CRYSTALS::Polynomial< DilithiumPolyTraits, Botan::CRYSTALS::Domain::NTT >::clone(), Botan::CRYSTALS::PolynomialVector< DilithiumPolyTraits, Botan::CRYSTALS::Domain::NTT >::clone(), commoncrypto_adjust_key_size(), Botan::Streebog::compress_64(), compute_root(), compute_root(), Botan::TPM2::copy_into(), Botan::TPM2::copy_into(), Botan::XMSS_Common_Ops::create_l_tree(), Botan::XMSS_Common_Ops::create_l_trees(), Botan::Sodium::crypto_auth_hmacsha512256(), Botan::Sodium::crypto_box_curve25519xsalsa20poly1305_seed_keypair(), Botan::GCM_SIV_Mode::ctr_xor(), Botan::BLS12_381::GroupOps< Group >::deserialize_unchecked(), ed25519_gen_keypair(), ed25519_sign(), Botan::Ed448_PublicKey::Ed448_PublicKey(), Botan::ML_KEM_Encryptor::encapsulate(), Botan::BigInt::encode_words(), Botan::CryptoBox::encrypt(), expand_message_xmd(), Botan::Polyval::final(), Botan::RawHashFunction::final_result(), Botan::TLS::Stream_Handshake_IO::format(), Botan::CCM_Mode::format_b0(), Botan::CCM_Mode::format_c0(), Botan::MontgomeryRep< Params >::from_rep(), Botan::IntMod< MontgomeryRep< ScalarParams > >::from_wide_bytes(), Botan::IntMod< MontgomeryRep< ScalarParams > >::from_wide_bytes_varlen(), Botan::IntMod< MontgomeryRep< ScalarParams > >::from_words(), Botan::TPM_Context::gen_random(), Botan::Salsa20::generate_keystream(), Botan::Gf448Elem::Gf448Elem(), Botan::BLS12_381::Scalar::hash(), is_perfect_square(), Botan::BLAKE2b::key_schedule(), lmots_compute_pubkey_from_sig(), Botan::LMOTS_Public_Key::LMOTS_Public_Key(), Botan::TLS::Cipher_State::marshall_and_protect(), mceliece_decrypt(), Botan::Montgomery_Int::Montgomery_Int(), Botan::Montgomery_Params::mul_by(), nist_key_unwrap(), nist_key_unwrap_padded(), nist_key_wrap(), nist_key_wrap_padded(), operator^(), Botan::DataSource_Memory::peek(), Botan::PseudorandomKeyGeneration::PseudorandomKeyGeneration(), Botan::DataSource_Memory::read(), reduce_mod(), Botan::Blowfish::salted_set_key(), Botan::Scalar448::Scalar448(), Botan::CTR_BE::seek(), Botan::IntMod< MontgomeryRep< ScalarParams > >::serialize_to(), Botan::EC_AffinePoint_Data_PC::serialize_uncompressed_to(), Botan::EC_AffinePoint_Data_BN::serialize_x_to(), Botan::EC_AffinePoint_Data_PC::serialize_x_to(), Botan::EC_AffinePoint_Data_BN::serialize_xy_to(), Botan::EC_AffinePoint_Data_PC::serialize_xy_to(), Botan::EC_AffinePoint_Data_BN::serialize_y_to(), Botan::EC_AffinePoint_Data_PC::serialize_y_to(), Botan::TLS::Session_Keys::Session_Keys(), Botan::CFB_Mode::shift_register(), Botan::HSS_LMS_PrivateKeyInternal::sign(), Botan::LMOTS_Private_Key::sign(), Botan::RTSS_Share::split(), Botan::polyn_gf2m::sqmod_init(), Botan::GHASH::start(), Botan::bitvector_base< secure_allocator >::subvector(), Botan::XMSS_Tree_Builder::tree_hash(), treehash(), treehash(), Botan::XTS_Mode::update_tweak(), wots_sign_and_pkgen(), Botan::Base64_Decoder::write(), Botan::Base64_Encoder::write(), Botan::Buffered_Filter::write(), Botan::Hex_Decoder::write(), Botan::Hex_Encoder::write(), Botan::X448_PublicKey::X448_PublicKey(), and Botan::XMSS_WOTS_PrivateKey::XMSS_WOTS_PrivateKey().

◆ copy_out_be()

template<ranges::spanable_range InR>
void Botan::copy_out_be ( std::span< uint8_t > out,
const InR & in )
inline

Partially copy a subset of in into out using big-endian byte order.

Definition at line 773 of file loadstor.h.

773 {
774 using T = std::ranges::range_value_t<InR>;
775 std::span<const T> in_s{in};
776 const auto remaining_bytes = detail::copy_out_any_word_aligned_portion<std::endian::big>(out, in_s);
777
778 // copy remaining bytes as a partial word
779 for(size_t i = 0; i < remaining_bytes; ++i) {
780 out[i] = get_byte_var(i, in_s.front());
781 }
782}
size_t copy_out_any_word_aligned_portion(std::span< uint8_t > &out, std::span< const T > &in)
Definition loadstor.h:752
constexpr uint8_t get_byte_var(size_t byte_num, T input)
Definition loadstor.h:69

References Botan::detail::copy_out_any_word_aligned_portion(), and get_byte_var().

◆ copy_out_le()

template<ranges::spanable_range InR>
void Botan::copy_out_le ( std::span< uint8_t > out,
const InR & in )
inline

Partially copy a subset of in into out using little-endian byte order.

Definition at line 789 of file loadstor.h.

789 {
790 using T = std::ranges::range_value_t<InR>;
791 std::span<const T> in_s{in};
792 const auto remaining_bytes = detail::copy_out_any_word_aligned_portion<std::endian::little>(out, in_s);
793
794 // copy remaining bytes as a partial word
795 for(size_t i = 0; i < remaining_bytes; ++i) {
796 out[i] = get_byte_var(sizeof(T) - 1 - i, in_s.front());
797 }
798}

References Botan::detail::copy_out_any_word_aligned_portion(), and get_byte_var().

Referenced by Botan::BLAKE2b::final_result(), and xts_compute_tweak_block().

◆ count_bits()

template<WordType W, size_t N>
size_t Botan::count_bits ( const std::array< W, N > & p)
inlineconsteval

Definition at line 269 of file pcurves_util.h.

269 {
270 const auto get_bit = [&](size_t i) {
271 const size_t w = i / WordInfo<W>::bits;
272 const size_t b = i % WordInfo<W>::bits;
273 return static_cast<uint8_t>((p[w] >> b) & 0x01);
274 };
275
276 size_t b = WordInfo<W>::bits * N;
277
278 // Conditional ok: this function is consteval
279 while(get_bit(b - 1) == 0) {
280 b -= 1;
281 }
282
283 return b;
284}

◆ create_aes_row_generator()

auto Botan::create_aes_row_generator ( const FrodoKEMConstants & constants,
StrongSpan< const FrodoSeedA > seed_a )
inline

Definition at line 22 of file frodo_aes_generator.h.

22 {
23 BOTAN_ASSERT_NOMSG(constants.mode().is_aes());
24
25 const auto setup_aes = [](StrongSpan<const FrodoSeedA> seed) {
26 AES_128 aes;
27 aes.set_key(seed);
28 return aes;
29 };
30
31 return [n = static_cast<uint16_t>(constants.n()), aes = setup_aes(seed_a)](
32 std::span<uint8_t> out, uint16_t first_row, size_t nrows) {
33 BOTAN_DEBUG_ASSERT(out.size() == nrows * (n / (AES_128::BLOCK_SIZE / 2)) * AES_128::BLOCK_SIZE);
34
35 // Set up the to-be-encrypted 'b' values for in-place encryption:
36 // each block is le16(i) || le16(j) || 0000...
37 auto p = std::span{out};
38 for(size_t r = 0; r != nrows; ++r) {
39 const uint16_t i = static_cast<uint16_t>(first_row + r);
40 for(uint16_t j = 0; j < n; j += AES_128::BLOCK_SIZE / 2) {
41 constexpr uint16_t zero = 0;
42 store_le(p.first<AES_128::BLOCK_SIZE>(), i, j, zero, zero, zero, zero, zero, zero);
43 p = p.subspan(AES_128::BLOCK_SIZE);
44 }
45 }
46
47 aes.encrypt(out);
48 };
49}
void encrypt(const uint8_t in[], uint8_t out[]) const
FrodoKEMMode mode() const
bool is_aes() const
Definition frodo_mode.h:61
void set_key(const OctetString &key)
Definition sym_algo.cpp:14

References Botan::Block_Cipher_Fixed_Params< 16, 16 >::BLOCK_SIZE, BOTAN_ASSERT_NOMSG, BOTAN_DEBUG_ASSERT, Botan::FrodoKEMMode::is_aes(), Botan::FrodoKEMConstants::mode(), Botan::FrodoKEMConstants::n(), Botan::SymmetricAlgorithm::set_key(), and store_le().

◆ create_ec_private_key()

std::unique_ptr< Private_Key > Botan::create_ec_private_key ( std::string_view algo_name,
const EC_Group & group,
RandomNumberGenerator & rng )

Create a new ECC key

Definition at line 464 of file pk_algs.cpp.

466 {
467 // Potentially unused if all EC algorithms are disabled
468 BOTAN_UNUSED(alg_name, ec_group, rng);
469
470#if defined(BOTAN_HAS_ECDSA)
471 if(alg_name == "ECDSA") {
472 return std::make_unique<ECDSA_PrivateKey>(rng, ec_group);
473 }
474#endif
475
476#if defined(BOTAN_HAS_ECDH)
477 if(alg_name == "ECDH") {
478 return std::make_unique<ECDH_PrivateKey>(rng, ec_group);
479 }
480#endif
481
482#if defined(BOTAN_HAS_ECKCDSA)
483 if(alg_name == "ECKCDSA") {
484 return std::make_unique<ECKCDSA_PrivateKey>(rng, ec_group);
485 }
486#endif
487
488#if defined(BOTAN_HAS_GOST_34_10_2001)
489 if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
490 return std::make_unique<GOST_3410_PrivateKey>(rng, ec_group);
491 }
492#endif
493
494#if defined(BOTAN_HAS_SM2)
495 if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
496 return std::make_unique<SM2_PrivateKey>(rng, ec_group);
497 }
498#endif
499
500#if defined(BOTAN_HAS_ECGDSA)
501 if(alg_name == "ECGDSA") {
502 return std::make_unique<ECGDSA_PrivateKey>(rng, ec_group);
503 }
504#endif
505
506 return nullptr;
507}

References BOTAN_UNUSED.

Referenced by botan_ec_privkey_create(), and create_private_key().

◆ create_hex_fingerprint() [1/2]

std::string Botan::create_hex_fingerprint ( const uint8_t bits[],
size_t len,
std::string_view hash_name )
inline

Old interface for create_hex_fingerprint added in 2.4 pre-span

Definition at line 572 of file pk_keys.h.

572 {
573 return create_hex_fingerprint({bits, len}, hash_name);
574}
std::string create_hex_fingerprint(std::span< const uint8_t > bits, std::string_view hash_name)
Definition pk_keys.cpp:40

References create_hex_fingerprint().

◆ create_hex_fingerprint() [2/2]

std::string Botan::create_hex_fingerprint ( std::span< const uint8_t > bits,
std::string_view hash_name )

Hash the input then format that hash using format_hex_fingerprint

Definition at line 40 of file pk_keys.cpp.

40 {
41 auto hash_fn = HashFunction::create_or_throw(hash_name);
42 hash_fn->update(bits);
43 auto digest = hash_fn->final_stdvec();
44 return format_hex_fingerprint(digest);
45}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311
std::string format_hex_fingerprint(std::span< const uint8_t > bits)
Definition pk_keys.cpp:47

References Botan::HashFunction::create_or_throw(), and format_hex_fingerprint().

Referenced by create_hex_fingerprint(), Botan::X509_Certificate::fingerprint(), Botan::Private_Key::fingerprint_private(), and Botan::Public_Key::fingerprint_public().

◆ create_keccak_mb_engine()

std::unique_ptr< Hash_Engine > Botan::create_keccak_mb_engine ( std::string_view hash_fn,
std::span< const uint8_t > common_prefix,
std::string_view provider )

Create a multi-buffer Keccak (SHAKE-128/256, SHA-3) Hash_Engine

Returns nullptr if the hash is not Keccak based, if the requested provider does not match, or if no SIMD implementation is usable on this CPU.

Definition at line 239 of file hash_engine_keccak.cpp.

241 {
242#if defined(BOTAN_HASH_ENGINE_KECCAK_HAS_IMPL)
243 size_t output_length = 0;
244 size_t rate = 0;
245 uint8_t suffix = 0;
246 std::string name;
247
248 const AlgorithmSpec req(hash_fn);
249 if(auto shake = req.match("SHAKE-128|SHAKE-256({bits:int})")) {
250 const size_t bits = shake->integer("bits");
251 if(bits == 0 || bits % 8 != 0) {
252 return nullptr;
253 }
254 output_length = bits / 8;
255 rate = (shake->head() == "SHAKE-128") ? 168 : 136;
256 suffix = 0x1F;
257 name = fmt("{}({})", shake->head(), bits);
258 } else if(auto sha3 = req.match("SHA-3({bits:int=512})")) {
259 const size_t bits = sha3->integer("bits");
260 if(bits != 224 && bits != 256 && bits != 384 && bits != 512) {
261 return nullptr;
262 }
263 output_length = bits / 8;
264 rate = 200 - 2 * output_length;
265 suffix = 0x06;
266 name = fmt("SHA-3({})", bits);
267 } else {
268 return nullptr;
269 }
270
271 #if defined(BOTAN_HAS_HASH_ENGINE_KECCAK_AVX512)
272 if(auto feat = CPUID::check(CPUID::Feature::AVX512)) {
273 if(provider.empty() || provider == *feat) {
274 return std::make_unique<Keccak_MB_Engine>(
275 name, output_length, rate, suffix, common_prefix, *feat, 8, keccak_mb_permute_x8, keccak_mb_absorb_x8);
276 }
277 }
278 #endif
279
280 #if defined(BOTAN_HAS_HASH_ENGINE_KECCAK_AVX2)
281 if(auto feat = CPUID::check(CPUID::Feature::AVX2)) {
282 if(provider.empty() || provider == *feat) {
283 return std::make_unique<Keccak_MB_Engine>(
284 name, output_length, rate, suffix, common_prefix, *feat, 4, keccak_mb_permute_x4, keccak_mb_absorb_x4);
285 }
286 }
287 #endif
288
289 return nullptr;
290#else
291 BOTAN_UNUSED(hash_fn, common_prefix, provider);
292 return nullptr;
293#endif
294}
static std::optional< std::string > check(CPUID::Feature feat)
Definition cpuid.h:66
const char * name
Definition ffi_tls.h:59
BOTAN_FN_ISA_SIMD_8X64 void keccak_mb_absorb_x8(uint64_t *states, const uint8_t *const *blocks, size_t rate_words, size_t nblocks)
BOTAN_FN_ISA_SIMD_4X64 void keccak_mb_absorb_x4(uint64_t *states, const uint8_t *const *blocks, size_t rate_words, size_t nblocks)
BOTAN_FN_ISA_SIMD_4X64 void keccak_mb_permute_x4(uint64_t *states)
BOTAN_FN_ISA_SIMD_8X64 void keccak_mb_permute_x8(uint64_t *states)

References Botan::CPUFeature::AVX2, Botan::CPUFeature::AVX512, BOTAN_UNUSED, Botan::CPUID::check(), fmt(), keccak_mb_absorb_x4(), keccak_mb_absorb_x8(), keccak_mb_permute_x4(), keccak_mb_permute_x8(), Botan::AlgorithmSpec::match(), and name.

◆ create_pk_from_sk()

BOTAN_TEST_API std::array< uint8_t, ED448_LEN > Botan::create_pk_from_sk ( std::span< const uint8_t, ED448_LEN > sk)

Create a public key point from a secret key (RFC 8032 5.2.5).

Definition at line 374 of file ed448_internal.cpp.

374 {
375 // 5.2.5. Key Generation
376 // The 57-byte public key is generated by the following steps:
377 auto shake_xof = XOF::create_or_throw("SHAKE-256");
378 shake_xof->update(sk);
379
380 const Scalar448 s = scalar_from_xof(*shake_xof);
381 // 3. Interpret the buffer as the little-endian integer, forming a
382 // secret scalar s. Perform a known-base-point scalar
383 // multiplication [s]B.
385}
static Ed448Point base_point_mul(const Scalar448 &scalar)
Fixed base point scalar multiplication (precomputed table, no doublings).
std::array< uint8_t, ED448_LEN > encode() const
Encode the point to its 57-byte representation (RFC 8032 5.2.2).
Representation of a scalar for X448.
static std::unique_ptr< XOF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:52

References Botan::Ed448Point::base_point_mul(), Botan::XOF::create_or_throw(), and Botan::Ed448Point::encode().

Referenced by Botan::Ed448_PrivateKey::check_key(), Botan::Ed448_PrivateKey::Ed448_PrivateKey(), and Botan::Ed448_PrivateKey::Ed448_PrivateKey().

◆ create_private_key()

std::unique_ptr< Private_Key > Botan::create_private_key ( std::string_view algo_name,
RandomNumberGenerator & rng,
std::string_view algo_params = "",
std::string_view provider = "" )

Create a new key For ECC keys, algo_params specifies EC group (eg, "secp256r1") For DH/DSA/ElGamal keys, algo_params is DL group (eg, "modp/ietf/2048") For RSA, algo_params is integer keylength For McEliece, algo_params is n,t If algo_params is left empty, suitable default parameters are chosen.

Definition at line 509 of file pk_algs.cpp.

512 {
513 /*
514 * Default parameters are chosen for work factor > 2**128 where possible
515 */
516
517#if defined(BOTAN_HAS_X25519)
518 if(alg_name == "X25519" || alg_name == "Curve25519") {
519 return std::make_unique<X25519_PrivateKey>(rng);
520 }
521#endif
522
523#if defined(BOTAN_HAS_X448)
524 if(alg_name == "X448") {
525 return std::make_unique<X448_PrivateKey>(rng);
526 }
527#endif
528
529#if defined(BOTAN_HAS_RSA)
530 if(alg_name == "RSA") {
531 const size_t modulus_bits = params.empty() ? 3072 : to_u32bit(params);
532 return std::make_unique<RSA_PrivateKey>(rng, modulus_bits);
533 }
534#endif
535
536#if defined(BOTAN_HAS_MCELIECE)
537 if(alg_name == "McEliece") {
538 const auto [n, t] = [&]() -> std::pair<size_t, size_t> {
539 if(params.empty()) {
540 return {2960, 57};
541 }
542
543 const auto mce_params = split_on(params, ',');
544
545 if(mce_params.size() != 2) {
546 throw Invalid_Argument(fmt("create_private_key: invalid McEliece parameters '{}'", params));
547 }
548
549 const size_t mce_n = to_u32bit(mce_params[0]);
550 const size_t mce_t = to_u32bit(mce_params[1]);
551 return {mce_n, mce_t};
552 }();
553
554 return std::make_unique<McEliece_PrivateKey>(rng, n, t);
555 }
556#endif
557#if defined(BOTAN_HAS_CLASSICMCELIECE)
558 if(alg_name == "ClassicMcEliece") {
559 const auto cmce_params_set = params.empty() ? Classic_McEliece_Parameter_Set::ClassicMcEliece_6960119f
561 return std::make_unique<Classic_McEliece_PrivateKey>(rng, cmce_params_set);
562 }
563#endif
564
565#if defined(BOTAN_HAS_FRODOKEM)
566 if(alg_name == "FrodoKEM") {
567 const auto mode = params.empty() ? FrodoKEMMode::FrodoKEM976_SHAKE : FrodoKEMMode(params);
568 return std::make_unique<FrodoKEM_PrivateKey>(rng, mode);
569 }
570#endif
571
572#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
573 if(alg_name == "Kyber") {
574 const auto mode = [&]() -> KyberMode {
575 if(params.empty()) {
577 }
578 return KyberMode(params);
579 }();
580
581 return std::make_unique<Kyber_PrivateKey>(rng, mode);
582 }
583#endif
584
585#if defined(BOTAN_HAS_ML_KEM)
586 if(alg_name == "ML-KEM") {
587 const auto mode = [&]() -> ML_KEM_Mode {
588 if(params.empty()) {
590 }
591 return ML_KEM_Mode(params);
592 }();
593
594 return std::make_unique<ML_KEM_PrivateKey>(rng, mode);
595 }
596#endif
597
598#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
599 if(alg_name == "Dilithium" || alg_name.starts_with("Dilithium-")) {
600 const auto mode = [&]() -> DilithiumMode {
601 if(params.empty()) {
603 }
604 return DilithiumMode(params);
605 }();
606
607 return std::make_unique<Dilithium_PrivateKey>(rng, mode);
608 }
609#endif
610
611#if defined(BOTAN_HAS_ML_DSA)
612 if(alg_name == "ML-DSA") {
613 const auto mode = [&]() -> ML_DSA_Mode {
614 if(params.empty()) {
616 }
617 return ML_DSA_Mode(params);
618 }();
619
620 return std::make_unique<ML_DSA_PrivateKey>(rng, mode);
621 }
622#endif
623
624#if defined(BOTAN_HAS_HSS_LMS)
625 if(alg_name == "HSS-LMS") {
626 const auto hss_params = [&]() -> std::string {
627 if(params.empty()) {
628 return "SHA-256,HW(10,1)";
629 } else {
630 return std::string(params);
631 }
632 }();
633 return std::make_unique<HSS_LMS_PrivateKey>(rng, hss_params);
634 }
635#endif
636
637#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
638 if(alg_name == "SPHINCS+" || alg_name == "SphincsPlus") {
639 const auto sphincs_params = Sphincs_Parameters::create(params);
640
641 return std::make_unique<SphincsPlus_PrivateKey>(rng, sphincs_params);
642 }
643#endif
644
645#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
646 if(alg_name == "SLH-DSA") {
647 const auto slh_dsa_params = SLH_DSA_Parameters::create(params);
648
649 return std::make_unique<SLH_DSA_PrivateKey>(rng, slh_dsa_params);
650 }
651#endif
652
653#if defined(BOTAN_HAS_XMSS_RFC8391)
654 if(alg_name == "XMSS") {
655 const auto xmss_oid = [&]() -> XMSS_Parameters::xmss_algorithm_t {
656 if(params.empty()) {
658 }
659 return XMSS_Parameters::from_name(params).oid();
660 }();
661
662 return std::make_unique<XMSS_PrivateKey>(xmss_oid, rng);
663 }
664#endif
665
666#if defined(BOTAN_HAS_ED25519)
667 if(alg_name == "Ed25519") {
668 return std::make_unique<Ed25519_PrivateKey>(rng);
669 }
670#endif
671
672#if defined(BOTAN_HAS_ED448)
673 if(alg_name == "Ed448") {
674 return std::make_unique<Ed448_PrivateKey>(rng);
675 }
676#endif
677
678 // ECC crypto
679#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
680
681 if(alg_name == "ECDSA" || alg_name == "ECDH" || alg_name == "ECKCDSA" || alg_name == "ECGDSA" || alg_name == "SM2" ||
682 alg_name == "SM2_Sig" || alg_name == "SM2_Enc" || alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" ||
683 alg_name == "GOST-34.10-2012-512") {
684 const std::string group_id = [&]() -> std::string {
685 if(!params.empty()) {
686 return std::string(params);
687 }
688 if(alg_name == "SM2" || alg_name == "SM2_Enc" || alg_name == "SM2_Sig") {
689 return "sm2p256v1";
690 }
691 if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256") {
692 return "gost_256A";
693 }
694 if(alg_name == "GOST-34.10-2012-512") {
695 return "gost_512A";
696 }
697 if(alg_name == "ECGDSA") {
698 return "brainpool256r1";
699 }
700 return "secp256r1";
701 }();
702
703 if(EC_Group::supports_named_group(group_id)) {
704 const auto ec_group = EC_Group::from_name(group_id);
705 return create_ec_private_key(alg_name, ec_group, rng);
706 } else {
707 return {};
708 }
709 }
710#endif
711
712 // DL crypto
713#if defined(BOTAN_HAS_DL_GROUP)
714 if(alg_name == "DH" || alg_name == "DSA" || alg_name == "ElGamal") {
715 const std::string group_id = [&]() -> std::string {
716 if(!params.empty()) {
717 return std::string(params);
718 }
719 if(alg_name == "DSA") {
720 return "dsa/botan/2048";
721 }
722 return "modp/ietf/2048";
723 }();
724
725 const auto modp_group = DL_Group::from_name(group_id);
726
727 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
728 if(alg_name == "DH") {
729 return std::make_unique<DH_PrivateKey>(rng, modp_group);
730 }
731 #endif
732
733 #if defined(BOTAN_HAS_DSA)
734 if(alg_name == "DSA") {
735 return std::make_unique<DSA_PrivateKey>(rng, modp_group);
736 }
737 #endif
738
739 #if defined(BOTAN_HAS_ELGAMAL)
740 if(alg_name == "ElGamal") {
741 return std::make_unique<ElGamal_PrivateKey>(rng, modp_group);
742 }
743 #endif
744 }
745#endif
746
747 BOTAN_UNUSED(alg_name, rng, params, provider);
748
749 return std::unique_ptr<Private_Key>();
750}
static Classic_McEliece_Parameter_Set from_string(std::string_view param_name)
Get the parameter set for a given parameter set name.
static DL_Group from_name(std::string_view name)
Definition dl_group.cpp:266
static EC_Group from_name(std::string_view name)
Definition ec_group.cpp:529
static bool supports_named_group(std::string_view name)
Definition ec_group.cpp:473
static Sphincs_Parameters create(Sphincs_Parameter_Set set, Sphincs_Hash_Type hash)
static XMSS_Parameters from_name(std::string_view algo_name)
xmss_algorithm_t oid() const
DilithiumMode ML_DSA_Mode
Definition ml_dsa.h:21
KyberMode ML_KEM_Mode
Definition ml_kem.h:21
std::unique_ptr< Private_Key > create_ec_private_key(std::string_view alg_name, const EC_Group &ec_group, RandomNumberGenerator &rng)
Definition pk_algs.cpp:464

References BOTAN_UNUSED, Botan::Classic_McEliece_Parameter_Set::ClassicMcEliece_6960119f, Botan::Sphincs_Parameters::create(), create_ec_private_key(), Botan::DilithiumMode::Dilithium6x5, fmt(), Botan::FrodoKEMMode::FrodoKEM976_SHAKE, Botan::DL_Group::from_name(), Botan::EC_Group::from_name(), Botan::XMSS_Parameters::from_name(), Botan::Classic_McEliece_Parameter_Set::from_string(), Botan::KyberMode::Kyber1024_R3, Botan::DilithiumMode::ML_DSA_6x5, Botan::KyberMode::ML_KEM_768, Botan::XMSS_Parameters::oid(), split_on(), Botan::EC_Group::supports_named_group(), to_u32bit(), and Botan::XMSS_Parameters::XMSS_SHA2_10_512.

Referenced by botan_privkey_create(), and Botan::TLS::Hybrid_KEM_PrivateKey::generate_from_group().

◆ create_sha2_32_mb_engine()

std::unique_ptr< Hash_Engine > Botan::create_sha2_32_mb_engine ( std::string_view hash_fn,
std::span< const uint8_t > common_prefix,
std::string_view provider )

Create a multi-buffer SHA-256 Hash_Engine

Returns nullptr if the hash is not SHA-256 (possibly truncated), if the requested provider does not match, or if no SIMD implementation is usable on this CPU.

Definition at line 21 of file hash_engine_sha2_32.cpp.

23 {
24#if defined(BOTAN_HASH_ENGINE_SHA2_32_HAS_IMPL)
25 size_t output_length = 0;
26
27 const AlgorithmSpec req(hash_fn);
28 if(req.matches("SHA-256")) {
29 output_length = 32;
30 } else if(auto m = req.match("Truncated(SHA-256,{bits:int})")) {
31 const size_t bits = m->integer("bits");
32 if(bits == 0 || bits % 8 != 0 || bits > 256) {
33 return nullptr;
34 }
35 output_length = bits / 8;
36 } else {
37 return nullptr;
38 }
39
40 SHA_256::digest_type midstate;
41 SHA_256::init(midstate);
42 const size_t full_bytes = common_prefix.size() - common_prefix.size() % SHA_256::block_bytes;
43 if(full_bytes > 0) {
44 SHA_256::compress_digest(midstate, common_prefix.first(full_bytes), full_bytes / SHA_256::block_bytes);
45 }
46
47 const auto make_engine = [&](std::string_view feat,
48 size_t lanes,
51 return std::make_unique<MDx_MB_Engine<uint32_t>>(hash_fn,
52 output_length,
53 common_prefix,
54 feat,
55 lanes,
58 midstate,
60 extract);
61 };
62
63 #if defined(BOTAN_HAS_HASH_ENGINE_SHA2_32_AVX512)
64 if(auto feat = CPUID::check(CPUID::Feature::AVX512)) {
65 if(provider.empty() || provider == *feat) {
66 return make_engine(*feat, 16, sha2_32_mb_compress_x16, sha2_32_mb_extract_x16);
67 }
68 }
69 #endif
70
71 #if defined(BOTAN_HAS_HASH_ENGINE_SHA2_32_AVX2)
72 if(auto feat = CPUID::check(CPUID::Feature::AVX2)) {
73 if(provider.empty() || provider == *feat) {
74 return make_engine(*feat, 8, sha2_32_mb_compress_x8, sha2_32_mb_extract_x8);
75 }
76 }
77 #endif
78
79 return nullptr;
80#else
81 BOTAN_UNUSED(hash_fn, common_prefix, provider);
82 return nullptr;
83#endif
84}
void(*)(const uint8_t *states, uint8_t *digests) extract_fn
void(*)(uint8_t *states, const uint8_t *const *blocks, size_t nblocks) compress_fn
secure_vector< uint32_t > digest_type
Definition sha2_32.h:61
static constexpr size_t ctr_bytes
Definition sha2_32.h:67
static void compress_digest(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_32.cpp:57
static void init(digest_type &digest)
Definition sha2_32.cpp:219
static constexpr size_t block_bytes
Definition sha2_32.h:65
constexpr std::make_unsigned_t< KyberConstants::T > compress(KyberConstants::T x)
BOTAN_FN_ISA_AVX512 void sha2_32_mb_extract_x16(const uint8_t *states, uint8_t *digests)
BOTAN_FN_ISA_AVX512 void sha2_32_mb_compress_x16(uint8_t *states, const uint8_t *const *blocks, size_t nblocks)
BOTAN_FN_ISA_AVX2 void sha2_32_mb_extract_x8(const uint8_t *states, uint8_t *digests)
BOTAN_FN_ISA_AVX2 void sha2_32_mb_compress_x8(uint8_t *states, const uint8_t *const *blocks, size_t nblocks)

References Botan::CPUFeature::AVX2, Botan::CPUFeature::AVX512, Botan::SHA_256::block_bytes, BOTAN_UNUSED, Botan::CPUID::check(), Botan::SHA_256::compress_digest(), Botan::SHA_256::ctr_bytes, Botan::SHA_256::init(), Botan::AlgorithmSpec::match(), Botan::AlgorithmSpec::matches(), sha2_32_mb_compress_x16(), sha2_32_mb_compress_x8(), sha2_32_mb_extract_x16(), and sha2_32_mb_extract_x8().

◆ create_sha2_64_mb_engine()

std::unique_ptr< Hash_Engine > Botan::create_sha2_64_mb_engine ( std::string_view hash_fn,
std::span< const uint8_t > common_prefix,
std::string_view provider )

Create a multi-buffer SHA-512 family Hash_Engine

Returns nullptr if the hash is not SHA-512/SHA-384/SHA-512-256 (possibly truncated), if the requested provider does not match, or if no SIMD implementation is usable on this CPU.

Definition at line 21 of file hash_engine_sha2_64.cpp.

23 {
24#if defined(BOTAN_HASH_ENGINE_SHA2_64_HAS_IMPL)
25 size_t output_length = 0;
26 SHA_512::digest_type midstate;
27
28 const AlgorithmSpec req(hash_fn);
29 if(req.matches("SHA-512")) {
30 output_length = SHA_512::output_bytes;
31 SHA_512::init(midstate);
32 } else if(req.matches("SHA-384")) {
33 output_length = SHA_384::output_bytes;
34 SHA_384::init(midstate);
35 } else if(req.matches("SHA-512-256")) {
36 output_length = SHA_512_256::output_bytes;
37 SHA_512_256::init(midstate);
38 } else if(auto m = req.match("Truncated(SHA-512,{bits:int})")) {
39 const size_t bits = m->integer("bits");
40 if(bits == 0 || bits % 8 != 0 || bits > 512) {
41 return nullptr;
42 }
43 output_length = bits / 8;
44 SHA_512::init(midstate);
45 } else {
46 return nullptr;
47 }
48
49 const size_t full_bytes = common_prefix.size() - common_prefix.size() % SHA_512::block_bytes;
50 if(full_bytes > 0) {
51 SHA_512::compress_digest(midstate, common_prefix.first(full_bytes), full_bytes / SHA_512::block_bytes);
52 }
53
54 const auto make_engine = [&](std::string_view feat,
55 size_t lanes,
58 return std::make_unique<MDx_MB_Engine<uint64_t>>(hash_fn,
59 output_length,
60 common_prefix,
61 feat,
62 lanes,
65 midstate,
67 extract);
68 };
69
70 #if defined(BOTAN_HAS_HASH_ENGINE_SHA2_64_AVX512)
71 if(auto feat = CPUID::check(CPUID::Feature::AVX512)) {
72 if(provider.empty() || provider == *feat) {
73 return make_engine(*feat, 8, sha2_64_mb_compress_x8, sha2_64_mb_extract_x8);
74 }
75 }
76 #endif
77
78 #if defined(BOTAN_HAS_HASH_ENGINE_SHA2_64_AVX2)
79 if(auto feat = CPUID::check(CPUID::Feature::AVX2)) {
80 if(provider.empty() || provider == *feat) {
81 return make_engine(*feat, 4, sha2_64_mb_compress_x4, sha2_64_mb_extract_x4);
82 }
83 }
84 #endif
85
86 return nullptr;
87#else
88 BOTAN_UNUSED(hash_fn, common_prefix, provider);
89 return nullptr;
90#endif
91}
static constexpr size_t output_bytes
Definition sha2_64.h:25
static void init(digest_type &digest)
Definition sha2_64.cpp:228
static constexpr size_t output_bytes
Definition sha2_64.h:124
static void init(digest_type &digest)
Definition sha2_64.cpp:217
static constexpr size_t block_bytes
Definition sha2_64.h:64
static constexpr size_t output_bytes
Definition sha2_64.h:65
static void init(digest_type &digest)
Definition sha2_64.cpp:239
static constexpr size_t ctr_bytes
Definition sha2_64.h:66
secure_vector< uint64_t > digest_type
Definition sha2_64.h:60
static void compress_digest(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_64.cpp:56
BOTAN_FN_ISA_SIMD_4X64 void sha2_64_mb_extract_x4(const uint8_t *states, uint8_t *digests)
BOTAN_FN_ISA_SIMD_8X64 void sha2_64_mb_compress_x8(uint8_t *states, const uint8_t *const *blocks, size_t nblocks)
BOTAN_FN_ISA_SIMD_4X64 void sha2_64_mb_compress_x4(uint8_t *states, const uint8_t *const *blocks, size_t nblocks)
BOTAN_FN_ISA_SIMD_8X64 void sha2_64_mb_extract_x8(const uint8_t *states, uint8_t *digests)

References Botan::CPUFeature::AVX2, Botan::CPUFeature::AVX512, Botan::SHA_512::block_bytes, BOTAN_UNUSED, Botan::CPUID::check(), Botan::SHA_512::compress_digest(), Botan::SHA_512::ctr_bytes, Botan::SHA_384::init(), Botan::SHA_512::init(), Botan::SHA_512_256::init(), Botan::AlgorithmSpec::match(), Botan::AlgorithmSpec::matches(), Botan::SHA_384::output_bytes, Botan::SHA_512::output_bytes, Botan::SHA_512_256::output_bytes, sha2_64_mb_compress_x4(), sha2_64_mb_compress_x8(), sha2_64_mb_extract_x4(), and sha2_64_mb_extract_x8().

◆ create_shake_row_generator()

auto Botan::create_shake_row_generator ( const FrodoKEMConstants & constants,
StrongSpan< const FrodoSeedA > seed_a )
inline

Definition at line 24 of file frodo_shake_generator.h.

24 {
25 BOTAN_ASSERT_NOMSG(constants.mode().is_shake());
26
27 // Each row i of A is SHAKE-128(le16(i) || seed_a), n 16-bit values
28 auto engine = std::shared_ptr<Hash_Engine>(Hash_Engine::create_or_throw(fmt("SHAKE-128({})", 16 * constants.n())));
29
30 return
31 [engine = std::move(engine), a = FrodoSeedA(seed_a)](std::span<uint8_t> out, uint16_t first_row, size_t nrows) {
32 const size_t row_bytes = engine->output_length();
33 BOTAN_ASSERT_NOMSG(out.size() == nrows * row_bytes);
34
35 std::vector<uint8_t> row_ids(sizeof(uint16_t) * nrows);
36 std::vector<std::span<uint8_t>> outputs(nrows);
37 std::vector<std::span<const uint8_t>> ids(nrows);
38 std::vector<std::span<const uint8_t>> seeds(nrows);
39
40 for(size_t r = 0; r != nrows; ++r) {
41 const auto id_span = std::span(row_ids).subspan(sizeof(uint16_t) * r).first<sizeof(uint16_t)>();
42 store_le(static_cast<uint16_t>(first_row + r), id_span);
43 ids[r] = id_span;
44 seeds[r] = a;
45 outputs[r] = out.subspan(r * row_bytes, row_bytes);
46 }
47
48 engine->batch_hash(outputs, ids, seeds);
49 };
50}
bool is_shake() const
Definition frodo_mode.h:56
static std::unique_ptr< Hash_Engine > create_or_throw(std::string_view hash_fn, std::span< const uint8_t > common_prefix={}, std::string_view provider="")
Strong< std::vector< uint8_t >, struct FrodoSeedA_ > FrodoSeedA
Definition frodo_types.h:23

References BOTAN_ASSERT_NOMSG, Botan::Hash_Engine::create_or_throw(), fmt(), Botan::FrodoKEMMode::is_shake(), Botan::FrodoKEMConstants::mode(), Botan::FrodoKEMConstants::n(), and store_le().

◆ cstr_as_span_of_bytes()

std::span< const uint8_t > Botan::cstr_as_span_of_bytes ( const char * s)
inline

Definition at line 72 of file mem_utils.h.

72 {
73 return as_span_of_bytes(s, std::strlen(s));
74}

References as_span_of_bytes().

◆ ct_compare_u8()

uint8_t Botan::ct_compare_u8 ( const uint8_t x[],
const uint8_t y[],
size_t len )

Memory comparison, input insensitive

Parameters
xa pointer to an array
ya pointer to another array
lenthe number of Ts in x and y
Returns
0xFF iff x[i] == y[i] forall i in [0...n) or 0x00 otherwise

Definition at line 13 of file mem_ops.cpp.

13 {
14 return CT::is_equal(x, y, len).value();
15}

References Botan::CT::is_equal().

◆ ct_divide() [1/2]

BigInt Botan::ct_divide ( const BigInt & x,
const BigInt & y )
inline

BigInt division

This runs with control flow independent of the values of x/y. Warning: the loop bounds still leak the sizes of x and y.

Parameters
xan integer
ya non-zero integer
Returns
x/y with remainder discarded

Definition at line 54 of file divide.h.

54 {
55 BigInt q;
56 BigInt r;
57 ct_divide(x, y, q, r);
58 return q;
59}
void ct_divide(const BigInt &x, const BigInt &y, BigInt &q_out, BigInt &r_out)
Definition divide.cpp:180

References ct_divide().

◆ ct_divide() [2/2]

BOTAN_TEST_API void Botan::ct_divide ( const BigInt & x,
const BigInt & y,
BigInt & q,
BigInt & r )

BigInt division

This runs with control flow independent of the values of x/y.

Warning: the sizes and signs of x and y still leak.

Parameters
xan integer
ya non-zero integer
qwill be set to x / y
rwill be set to x % y

Definition at line 180 of file divide.cpp.

180 {
181 if(y.is_zero()) {
182 throw Invalid_Argument("ct_divide: cannot divide by zero");
183 }
184
185 BigInt q;
186 BigInt r;
187 ct_divide_impl(q, r, x, y);
188
189 sign_fixup(x, y, q, r);
190 r_out = std::move(r);
191 q_out = std::move(q);
192}
bool is_zero() const
Definition bigint.h:510

References Botan::BigInt::is_zero().

Referenced by botan_mp_div(), ct_divide(), Botan::FPE_FE1::decrypt(), Botan::FPE_FE1::encrypt(), lcm(), operator%(), and operator/().

◆ ct_divide_pow2k()

BOTAN_TEST_API BigInt Botan::ct_divide_pow2k ( size_t k,
const BigInt & y )

BigInt division, 2^k variant

This runs with control flow independent of the value of y. This function leaks the value of k and the length of y. If k < bits(y) this returns zero

Parameters
kan integer
ya positive integer
Returns
q equal to 2**k / y

Definition at line 194 of file divide.cpp.

194 {
195 BOTAN_ARG_CHECK(y.signum() != 0, "Cannot divide by zero");
196 BOTAN_ARG_CHECK(y.signum() >= 0, "Negative divisor not supported");
197 BOTAN_ARG_CHECK(k > 1, "Invalid k");
198
199 BigInt q;
200 BigInt r;
201 ct_divide_impl(q, r, BigInt::power_of_2(k), y);
202 return q;
203}
int signum() const
Definition bigint.h:493
static BigInt power_of_2(size_t n)
Definition bigint.h:906

References BOTAN_ARG_CHECK, Botan::BigInt::power_of_2(), and Botan::BigInt::signum().

Referenced by Botan::Barrett_Reduction::for_secret_modulus().

◆ ct_divide_word() [1/2]

BigInt Botan::ct_divide_word ( const BigInt & x,
word y )

Constant time division

This runs with control flow independent of the value of x. The divisor y is treated as a public value. Warning: the loop bounds still leak the size of x.

Parameters
xan integer
ya non-zero word
Returns
quotient floor(x / y)

Definition at line 239 of file divide.cpp.

239 {
240 BigInt q;
241 word r = 0;
242 ct_divide_word(x, y, q, r);
243 BOTAN_UNUSED(r);
244 return q;
245}

References BOTAN_UNUSED, and ct_divide_word().

◆ ct_divide_word() [2/2]

BOTAN_TEST_API void Botan::ct_divide_word ( const BigInt & x,
word y,
BigInt & q,
word & r )

Constant time division

This runs with control flow independent of the value of x. The divisor y is treated as a public value. Warning: the loop bounds still leak the size of x.

Parameters
xan integer
ya non-zero integer
qwill be set to x / y
rwill be set to x % y

Definition at line 205 of file divide.cpp.

205 {
206 if(y == 0) {
207 throw Invalid_Argument("ct_divide_word: cannot divide by zero");
208 }
209
210 const size_t x_words = x.sig_words();
211
212 // The divisor is public here; setup is variable time in it
213 const auto div_y = divide_precomp<word>::setup_vartime(y);
214
215 secure_vector<word> qw(x_words);
216 word r = 0;
217
218 // Each step depends on r < y, which holds since r is a remainder mod y
219 for(size_t i = x_words; i > 0; --i) {
220 const auto [qi, ri] = div_y.divmod_2to1_vartime(r, x._data()[i - 1]);
221 qw[i - 1] = qi;
222 r = ri;
223 }
224
226
227 if(x.signum() < 0) {
228 q.flip_sign();
229 if(r != 0) {
230 --q;
231 r = y - r;
232 }
233 }
234
235 r_out = r;
236 q_out = std::move(q);
237}
size_t sig_words() const
Definition bigint.h:687
static BigInt _from_words(secure_vector< word > &words)
Definition bigint.h:1052
const word * _data() const
Definition bigint.h:1033
static constexpr divide_precomp setup_vartime(W divisor)
Definition mp_core.h:687

References Botan::BigInt::_data(), Botan::BigInt::_from_words(), Botan::BigInt::flip_sign(), Botan::divide_precomp< W >::setup_vartime(), Botan::BigInt::sig_words(), and Botan::BigInt::signum().

Referenced by compute_rsa_secret_exponent(), ct_divide_word(), operator/(), and Botan::BigInt::to_dec_string().

◆ ct_expand_top_bit()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::ct_expand_top_bit ( T a)
constexpr

If top bit of arg is set, return |1| (all bits set). Otherwise return |0| (all bits unset)

Definition at line 28 of file bit_ops.h.

28 {
29 const T top = CT::value_barrier<T>(a >> (sizeof(T) * 8 - 1));
30 return static_cast<T>(0) - top;
31}
constexpr T value_barrier(T x)

References BOTAN_FORCE_INLINE, and Botan::CT::value_barrier().

Referenced by ct_is_zero(), and Botan::CT::Mask< T >::expand_top_bit().

◆ ct_if_is_zero_ret()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr size_t Botan::ct_if_is_zero_ret ( T x,
size_t s )
constexpr

If arg is zero, return the size_t s. Otherwise return the size_t zero.

Definition at line 45 of file bit_ops.h.

45 {
46 /*
47 Similar to `return ct_is_zero(x) & s` but has to account for possibility that
48 sizeof(T) is smaller than sizeof(size_t) which would lead to incomplete masking
49 */
50 const T a = ~x & (x - 1);
51 const size_t a_top = static_cast<size_t>(CT::value_barrier<T>(a >> (sizeof(T) * 8 - 1)));
52 const size_t mask = static_cast<size_t>(0) - a_top;
53 return mask & s;
54}

References BOTAN_FORCE_INLINE, and Botan::CT::value_barrier().

Referenced by ctz(), high_bit(), and significant_bytes().

◆ ct_is_zero()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::ct_is_zero ( T x)
constexpr

If arg is zero, return |1|. Otherwise return |0|

Definition at line 37 of file bit_ops.h.

37 {
38 return ct_expand_top_bit<T>(~x & (x - 1));
39}
BOTAN_FORCE_INLINE constexpr T ct_expand_top_bit(T a)
Definition bit_ops.h:28

References BOTAN_FORCE_INLINE, and ct_expand_top_bit().

Referenced by Botan::CT::Choice::from_int(), Botan::CT::Choice::into_bitmask(), Botan::CT::Mask< T >::is_zero(), and prefetch_array_raw().

◆ ct_mod_word()

BOTAN_TEST_API word Botan::ct_mod_word ( const BigInt & x,
word y )

BigInt word modulo, const time variant

This runs with control flow independent of the value of x. The divisor y is treated as a public value. Warning: the loop bounds still leak the size of x.

Parameters
xa positive integer
ya non-zero word
Returns
r the remainder of x divided by y

Definition at line 247 of file divide.cpp.

247 {
248 BOTAN_ARG_CHECK(x.signum() >= 0, "The argument x must be non-negative");
249 BOTAN_ARG_CHECK(y != 0, "Cannot divide by zero");
250
251 // The divisor is public here; setup is variable time in it
252 const auto div_y = divide_precomp<word>::setup_vartime(y);
253
254 word r = 0;
255 for(size_t i = x.sig_words(); i > 0; --i) {
256 r = div_y.mod_2to1(r, x._data()[i - 1]);
257 }
258
259 return r;
260}

References Botan::BigInt::_data(), BOTAN_ARG_CHECK, Botan::divide_precomp< W >::setup_vartime(), Botan::BigInt::sig_words(), and Botan::BigInt::signum().

Referenced by compute_rsa_secret_exponent().

◆ ct_modulo()

BOTAN_TEST_API BigInt Botan::ct_modulo ( const BigInt & x,
const BigInt & modulo )

BigInt modulo, const time variant

Using this function is (slightly) cheaper than calling ct_divide and using only the remainder.

Parameters
xa non-negative integer
moduloa positive integer
Returns
result x % modulo

Definition at line 262 of file divide.cpp.

262 {
263 if(y.signum() <= 0) {
264 throw Invalid_Argument("ct_modulo requires y > 0");
265 }
266
267 BigInt q;
268 BigInt r;
269 ct_divide_impl(q, r, x, y);
270
271 if(x.signum() < 0) {
272 if(r.signum() != 0) {
273 r = y - r;
274 }
275 }
276
277 return r;
278}

References Botan::BigInt::signum().

Referenced by Botan::RSA_PrivateKey::check_key(), compute_rsa_secret_exponent(), Botan::FPE_FE1::decrypt(), Botan::FPE_FE1::encrypt(), inverse_mod(), inverse_mod_general(), power_mod(), Botan::Modular_Reducer::reduce(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and Botan::RSA_PrivateKey::RSA_PrivateKey().

◆ ct_popcount()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr uint8_t Botan::ct_popcount ( T x)
constexpr

Calculates the number of 1-bits in an unsigned integer in constant-time. This operation is also known as "population count" or hamming weight.

Modern compilers will recognize this pattern and replace it by a hardware instruction, if available. This is the SWAR (SIMD within a register) algorithm. See: https://nimrod.blog/posts/algorithms-behind-popcount/#swar-algorithm

Note: C++20 provides std::popcount(), but there's no guarantee that this is implemented in constant-time.

Parameters
xan unsigned integer
Returns
the number of 1-bits in the provided value

Definition at line 274 of file bit_ops.h.

274 {
275 constexpr size_t s = sizeof(T);
276 static_assert(s <= 8, "T is not a suitable unsigned integer value");
277 if constexpr(s == 8) {
278 x = x - ((x >> 1) & 0x5555555555555555);
279 x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
280 x = (x + (x >> 4)) & 0xF0F0F0F0F0F0F0F;
281 return (x * 0x101010101010101) >> 56;
282 } else if constexpr(s == 4) {
283 x = x - ((x >> 1) & 0x55555555);
284 x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
285 x = (x + (x >> 4)) & 0x0F0F0F0F;
286 return (x * 0x01010101) >> 24;
287 } else {
288 // s < 4
289 return ct_popcount(static_cast<uint32_t>(x));
290 }
291}
BOTAN_FORCE_INLINE constexpr uint8_t ct_popcount(T x)
Definition bit_ops.h:274

References BOTAN_FORCE_INLINE, and ct_popcount().

Referenced by ct_popcount(), and Botan::bitvector_base< secure_allocator >::hamming_weight().

◆ ct_reverse_bits()

template<std::unsigned_integral T>
T Botan::ct_reverse_bits ( T b)
inlineconstexpr
Returns
the reversed bits in b.

Definition at line 240 of file bit_ops.h.

240 {
241 const auto extend = [](uint8_t m) -> T {
242 T mask = 0;
243 for(size_t i = 0; i < sizeof(T); ++i) {
244 mask |= T(m) << i * 8;
245 }
246 return mask;
247 };
248
249 // First reverse bits in each byte...
250 // From: https://stackoverflow.com/a/2602885
251 b = (b & extend(0xF0)) >> 4 | (b & extend(0x0F)) << 4;
252 b = (b & extend(0xCC)) >> 2 | (b & extend(0x33)) << 2;
253 b = (b & extend(0xAA)) >> 1 | (b & extend(0x55)) << 1;
254
255 // ... then swap the bytes
256 return reverse_bytes(b);
257}
constexpr T reverse_bytes(T x)
Definition bswap.h:25

References reverse_bytes().

◆ ctz()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr size_t Botan::ctz ( T n)
constexpr

Count the trailing zero bits in n

Parameters
nan integer value
Returns
maximum x st 2^x divides n

Definition at line 115 of file bit_ops.h.

115 {
116 /*
117 * If n == 0 then this function will compute 8*sizeof(T)-1, so
118 * initialize lb to 1 if n == 0 to produce the expected result.
119 */
120 size_t lb = ct_if_is_zero_ret<T>(n, 1);
121
122 for(size_t s = 8 * sizeof(T) / 2; s > 0; s /= 2) {
123 const T range = (static_cast<T>(1) << s) - 1;
124 // Equivalent to: ((n & range) == 0) ? s : 0;
125 const size_t z = ct_if_is_zero_ret<T>(n & range, s);
126 lb += z;
127 n >>= z;
128 }
129
130 return lb;
131}
BOTAN_FORCE_INLINE constexpr size_t ct_if_is_zero_ret(T x, size_t s)
Definition bit_ops.h:45

References BOTAN_FORCE_INLINE, and ct_if_is_zero_ret().

Referenced by Botan::DER_Encoder::encode_named_bitstring(), low_zero_bits(), and var_ctz64().

◆ curve25519_basepoint()

void Botan::curve25519_basepoint ( uint8_t mypublic[32],
const uint8_t secret[32] )

Exponentiate by the x25519 base point

Parameters
mypublicoutput value
secretrandom scalar

Definition at line 230 of file x25519.cpp.

230 {
231 x25519_basepoint(std::span<uint8_t, 32>(mypublic, 32), std::span<const uint8_t, 32>(secret, 32));
232}
void x25519_basepoint(std::span< uint8_t, 32 > out, std::span< const uint8_t, 32 > scalar)

References x25519_basepoint().

◆ curve25519_donna()

void Botan::curve25519_donna ( uint8_t mypublic[32],
const uint8_t secret[32],
const uint8_t basepoint[32] )

Compute the X25519 scalar multiplication of secret and basepoint

Parameters
mypublicoutput value
secretrandom scalar
basepointthe u-coordinate of the point to multiply

Definition at line 224 of file x25519.cpp.

224 {
225 x25519_scalarmult(std::span<uint8_t, 32>(mypublic, 32),
226 std::span<const uint8_t, 32>(secret, 32),
227 std::span<const uint8_t, 32>(basepoint, 32));
228}
void x25519_scalarmult(std::span< uint8_t, 32 > out, std::span< const uint8_t, 32 > scalar, std::span< const uint8_t, 32 > u)

References x25519_scalarmult().

◆ dbl_a_minus_3()

template<typename ProjectivePoint>
ProjectivePoint Botan::dbl_a_minus_3 ( const ProjectivePoint & pt)
inlineconstexpr

Definition at line 384 of file pcurves_algos.h.

384 {
385 /*
386 if a == -3 then
387 3*x^2 + a*z^4 == 3*x^2 - 3*z^4 == 3*(x^2-z^4) == 3*(x-z^2)*(x+z^2)
388 */
389 const auto z2 = pt.z().square();
390 const auto m = (pt.x() - z2).mul3() * (pt.x() + z2);
391
392 // Remaining cost: 3M + 3S + 3A + 2*2 + 1*4 + 1*8
393 const auto y2 = pt.y().square();
394 const auto s = pt.x().mul4() * y2;
395 const auto nx = m.square() - s.mul2();
396 const auto ny = m * (s - nx) - y2.square().mul8();
397 const auto nz = pt.y().mul2() * pt.z();
398
399 return ProjectivePoint(nx, ny, nz);
400}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl().

◆ dbl_a_zero()

template<typename ProjectivePoint>
ProjectivePoint Botan::dbl_a_zero ( const ProjectivePoint & pt)
inlineconstexpr

Definition at line 403 of file pcurves_algos.h.

403 {
404 // If a == 0 then 3*x^2 + a*z^4 == 3*x^2
405 // Cost: 1S + 1*3
406 const auto m = pt.x().square().mul3();
407
408 // Remaining cost: 3M + 3S + 3A + 2*2 + 1*4 + 1*8
409 const auto y2 = pt.y().square();
410 const auto s = pt.x().mul4() * y2;
411 const auto nx = m.square() - s.mul2();
412 const auto ny = m * (s - nx) - y2.square().mul8();
413 const auto nz = pt.y().mul2() * pt.z();
414
415 return ProjectivePoint(nx, ny, nz);
416}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl(), and Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_iso().

◆ dbl_generic()

template<typename ProjectivePoint, typename FieldElement>
ProjectivePoint Botan::dbl_generic ( const ProjectivePoint & pt,
const FieldElement & A )
inlineconstexpr

Definition at line 419 of file pcurves_algos.h.

419 {
420 // Cost: 1M + 3S + 1A + 1*3
421 const auto z2 = pt.z().square();
422 const auto m = pt.x().square().mul3() + A * z2.square();
423
424 // Remaining cost: 3M + 3S + 3A + 2*2 + 1*4 + 1*8
425 const auto y2 = pt.y().square();
426 const auto s = pt.x().mul4() * y2;
427 const auto nx = m.square() - s.mul2();
428 const auto ny = m * (s - nx) - y2.square().mul8();
429 const auto nz = pt.y().mul2() * pt.z();
430
431 return ProjectivePoint(nx, ny, nz);
432}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl(), and Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_iso().

◆ dbl_n_a_minus_3()

template<typename ProjectivePoint>
ProjectivePoint Botan::dbl_n_a_minus_3 ( const ProjectivePoint & pt,
size_t n )
inlineconstexpr

Definition at line 454 of file pcurves_algos.h.

454 {
455 auto nx = pt.x();
456 auto ny = pt.y().mul2();
457 auto nz = pt.z();
458 auto w = nz.square().square();
459
460 // Conditional ok: loop iteration count is public
461 while(n > 0) {
462 const auto ny2 = ny.square();
463 const auto ny4 = ny2.square();
464 const auto t1 = (nx.square() - w).mul3();
465 const auto t2 = nx * ny2;
466 nx = t1.square() - t2.mul2();
467 nz *= ny;
468 ny = t1 * (t2 - nx).mul2() - ny4;
469 n--;
470 // Conditional ok: loop iteration count is public
471 if(n > 0) {
472 w *= ny4;
473 }
474 }
475 return ProjectivePoint(nx, ny.div2(), nz);
476}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_n().

◆ dbl_n_a_zero()

template<typename ProjectivePoint>
ProjectivePoint Botan::dbl_n_a_zero ( const ProjectivePoint & pt,
size_t n )
inlineconstexpr

Definition at line 479 of file pcurves_algos.h.

479 {
480 auto nx = pt.x();
481 auto ny = pt.y().mul2();
482 auto nz = pt.z();
483
484 // Conditional ok: loop iteration count is public
485 while(n > 0) {
486 const auto ny2 = ny.square();
487 const auto ny4 = ny2.square();
488 const auto t1 = nx.square().mul3();
489 const auto t2 = nx * ny2;
490 nx = t1.square() - t2.mul2();
491 nz *= ny;
492 ny = t1 * (t2 - nx).mul2() - ny4;
493 n--;
494 }
495 return ProjectivePoint(nx, ny.div2(), nz);
496}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_n(), and Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_n_iso().

◆ dbl_n_generic()

template<typename ProjectivePoint, typename FieldElement>
ProjectivePoint Botan::dbl_n_generic ( const ProjectivePoint & pt,
const FieldElement & A,
size_t n )
inlineconstexpr

Definition at line 499 of file pcurves_algos.h.

499 {
500 auto nx = pt.x();
501 auto ny = pt.y().mul2();
502 auto nz = pt.z();
503 auto w = nz.square().square() * A;
504
505 // Conditional ok: loop iteration count is public
506 while(n > 0) {
507 const auto ny2 = ny.square();
508 const auto ny4 = ny2.square();
509 const auto t1 = nx.square().mul3() + w;
510 const auto t2 = nx * ny2;
511 nx = t1.square() - t2.mul2();
512 nz *= ny;
513 ny = t1 * (t2 - nx).mul2() - ny4;
514 n--;
515 // Conditional ok: loop iteration count is public
516 if(n > 0) {
517 w *= ny4;
518 }
519 }
520 return ProjectivePoint(nx, ny.div2(), nz);
521}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_n(), and Botan::ProjectiveCurvePoint< FieldElement, Params >::dbl_n_iso().

◆ deallocate_memory()

void Botan::deallocate_memory ( void * p,
size_t elems,
size_t elem_size )

Free a pointer returned by allocate_memory

Parameters
pthe pointer returned by allocate_memory
elemsthe number of elements, as passed to allocate_memory
elem_sizethe size of each element, as passed to allocate_memory

Definition at line 50 of file allocator.cpp.

50 {
51 if(p == nullptr) {
52 [[unlikely]] return;
53 }
54
55 secure_scrub_memory(p, elems * elem_size);
56
57#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
58 if(mlock_allocator::instance().deallocate(p, elems, elem_size)) {
59 return;
60 }
61#endif
62
63 std::free(p); // NOLINT(*-no-malloc,*-owning-memory)
64}
void secure_scrub_memory(void *ptr, size_t n)
Definition mem_utils.cpp:24

References Botan::mlock_allocator::instance(), and secure_scrub_memory().

Referenced by Botan::secure_allocator< T >::deallocate().

◆ decode_gf2m()

gf2m Botan::decode_gf2m ( const uint8_t * mem)

Definition at line 113 of file gf2m_small_m.cpp.

113 {
114 gf2m result = mem[0] << 8;
115 result |= mem[1];
116 return result;
117}
uint16_t gf2m

Referenced by Botan::polyn_gf2m::polyn_gf2m().

◆ decode_ml_kem_private_key()

KyberDecodedKeypair Botan::decode_ml_kem_private_key ( std::span< const uint8_t > private_key,
KyberConstants mode )

Decodes an ML-KEM private key from any of the three CHOICE alternatives of the ML-KEM-PrivateKey structure specified in RFC 9935, Section 6. For backwards compatibility, also the raw 64-byte seed and the raw expanded key of FIPS 203 (without any ASN.1 wrapping) are accepted.

Definition at line 154 of file kyber_keys.cpp.

154 {
155 BOTAN_ARG_CHECK(mode.mode().is_ml_kem(), "RFC 9935 private key encodings are only defined for ML-KEM");
156
157 if(private_key.size() == mode.seed_private_key_bytes()) {
158 // backwards compatibility (not RFC 9935 conforming) to the raw seed d || z
159 return {
160 .keypair = decode_ml_kem_seed(private_key, std::move(mode)),
161 .format = MlPrivateKeyFormat::Seed,
162 };
163 }
164 if(private_key.size() == mode.expanded_private_key_bytes()) {
165 // raw expanded key in the FIPS 203 dk encoding without ASN.1 wrapping (not RFC 9935
166 // conforming), as used e.g. by the NIST ACVP and Wycheproof test vectors. The length
167 // cannot collide with any of the RFC 9935 encodings.
168 return {
169 .keypair = decode_ml_kem_expanded(private_key, std::move(mode)),
171 };
172 }
173
174 auto dec = BER_Decoder(private_key, BER_Decoder::Limits::DER());
175
176 // RFC 9935, Section 6: the ASN.1 tag identifies the CHOICE alternative
177 const auto obj = [&]() {
178 try {
179 return dec.peek_next_object();
180 } catch(const Decoding_Error&) {
181 throw Decoding_Error("Invalid ML-KEM private key encoding");
182 }
183 }();
184
185 if(obj.type() == ASN1_Type(0) && obj.class_tag() == ASN1_Class::ContextSpecific) {
186 // "seed" alternative: [0] IMPLICIT OCTET STRING
188 dec.decode(seed, ASN1_Type::OctetString, ASN1_Type(0), ASN1_Class::ContextSpecific).verify_end();
189
190 return {
191 .keypair = decode_ml_kem_seed(seed, std::move(mode)),
192 .format = MlPrivateKeyFormat::Seed,
193 };
194 }
195
196 if(obj.type() == ASN1_Type::OctetString && obj.class_tag() == ASN1_Class::Universal) {
197 // "expandedKey" alternative: OCTET STRING
198 secure_vector<uint8_t> expanded;
199 dec.decode(expanded, ASN1_Type::OctetString).verify_end();
200
201 return {
202 .keypair = decode_ml_kem_expanded(expanded, std::move(mode)),
204 };
205 }
206
207 if(obj.type() == ASN1_Type::Sequence && obj.class_tag() == ASN1_Class::Constructed) {
208 // "both" alternative: SEQUENCE { seed OCTET STRING, expandedKey OCTET STRING }
210 secure_vector<uint8_t> expanded;
211 dec.start_sequence()
212 .decode(seed, ASN1_Type::OctetString)
213 .decode(expanded, ASN1_Type::OctetString)
214 .end_cons()
215 .verify_end();
216
217 if(expanded.size() != mode.expanded_private_key_bytes()) {
218 throw Decoding_Error("invalid length of ML-KEM expanded private key");
219 }
220
221 // RFC 9935, Section 8: the expanded key must be the expansion of the seed
222 auto keypair = decode_ml_kem_seed(seed, std::move(mode));
223 const auto expanded_from_seed = Expanded_Keypair_Codec().encode_keypair(keypair);
224 if(expanded_from_seed.size() != expanded.size() || !constant_time_compare(expanded_from_seed, expanded)) {
225 throw Decoding_Error("seed and expanded key in ML-KEM private key do not match");
226 }
227
228 return {
229 .keypair = std::move(keypair),
230 .format = MlPrivateKeyFormat::Both,
231 };
232 }
233
234 throw Decoding_Error("Invalid ML-KEM private key encoding");
235}
static Limits DER()
Definition ber_dec.h:44
Codec for expanded private keys (as specified in FIPS 203).
Definition kyber_keys.h:31
secure_vector< uint8_t > encode_keypair(KyberInternalKeypair private_key) const override
size_t seed_private_key_bytes() const
byte length of an private key encoded as the seed: d || z
size_t expanded_private_key_bytes() const
byte length of a private key with expanded encoding as defined
KyberMode mode() const
bool is_ml_kem() const
Definition kyber.cpp:128
ASN1_Type
Definition asn1_obj.h:47

References BOTAN_ARG_CHECK, Both, constant_time_compare(), Constructed, ContextSpecific, Botan::BER_Decoder::Limits::DER(), Botan::Expanded_Keypair_Codec::encode_keypair(), Expanded, Botan::KyberConstants::expanded_private_key_bytes(), Botan::KyberMode::is_ml_kem(), Botan::KyberConstants::mode(), OctetString, Seed, Botan::KyberConstants::seed_private_key_bytes(), Sequence, and Universal.

Referenced by Botan::Kyber_PrivateKey::Kyber_PrivateKey().

◆ decode_point()

Point448 Botan::decode_point ( std::span< const uint8_t > p_bytes)

Decode a point from a byte array. RFC 7748 Section 5 (decodeUCoordinate).

Definition at line 25 of file x448_internal.cpp.

25 {
26 BOTAN_ARG_CHECK(p_bytes.size() == X448_LEN, "Invalid size for X448 point");
27 return typecast_copy<Point448>(p_bytes);
28}
constexpr void typecast_copy(ToR &&out, const FromR &in)
Definition mem_ops.h:176
constexpr size_t X448_LEN

References BOTAN_ARG_CHECK, typecast_copy(), and X448_LEN.

Referenced by Botan::X448_PublicKey::check_key().

◆ decode_scalar()

ScalarX448 Botan::decode_scalar ( std::span< const uint8_t > scalar_bytes)

Decode a scalar from a byte array. RFC 7748 Section 5 (decodeScalar448).

Definition at line 30 of file x448_internal.cpp.

30 {
31 BOTAN_ARG_CHECK(scalar_bytes.size() == X448_LEN, "Invalid size for X448 scalar");
32 auto buf = typecast_copy<ScalarX448>(scalar_bytes);
33
34 buf[0] &= 0xfc;
35 buf[55] |= 0x80;
36
37 return buf;
38}

References BOTAN_ARG_CHECK, typecast_copy(), and X448_LEN.

Referenced by Botan::X448_PublicKey::check_key().

◆ distribution_point_match()

DistributionPointMatch Botan::distribution_point_match ( const X509_CRL & crl,
const X509_Certificate & cert )

Definition at line 458 of file x509_crl.cpp.

458 {
459 const auto* idp_ext = crl.extensions().get_extension_object_as<Cert_Extension::CRL_Issuing_Distribution_Point>();
461
462 /*
463 * RFC 5280 6.3.3 trailing paragraph: "If the revocation status has not
464 * been determined, repeat the process above with any available CRLs not
465 * specified in a distribution point but issued by the certificate issuer.
466 * For the processing of such a CRL, assume a DP with both the reasons and
467 * the cRLIssuer fields omitted and a distribution point name of the
468 * certificate issuer."
469 *
470 * When the cert has no CDP this implicit DP is the only DP; with no reasons
471 * field it covers all reasons by construction.
472 */
473 if(cdp_ext == nullptr || cdp_ext->distribution_points().empty()) {
474 const bool match = implicit_dp_matches(crl, cert, idp_ext);
475 return {match, match};
476 }
477
478 /*
479 * Walk the cert's CDP once, recording both the bare name-match and whether
480 * any matching DP omits the reasons field. (b)(1) cRLIssuer + indirectCRL
481 * and (b)(2)(i) IDP-vs-DP name overlap live in the helpers; reason coverage
482 * is decided per (d)(3): a matching DP whose reasons field is set narrows
483 * the CRL's coverage to that subset, so full coverage requires a
484 * matching DP with no reasons field.
485 */
486 const auto name_matches = [&](const auto& dp) {
487 return dp_issuer_and_scope_ok(dp, crl.issuer_dn(), idp_ext, cert) && dp_idp_name_matches(dp, idp_ext);
488 };
489
490 bool any = false;
491 bool any_with_absent_reasons = false;
492 for(const auto& dp : cdp_ext->distribution_points()) {
493 if(name_matches(dp)) {
494 any = true;
495 if(!dp.reasons().has_value()) {
496 any_with_absent_reasons = true;
497 }
498 }
499 }
500 if(any) {
501 return {true, any_with_absent_reasons};
502 }
503
504 /*
505 * Implicit-DP fallback: a same-issuer complete CRL that matches no explicit
506 * DP is still usable, unless its own IDP scopes it to a distribution point
507 * (see crl_eligible_for_implicit_dp_fallback). The implicit DP omits
508 * reasons, so a name match here also gives full reason coverage.
509 */
510 const bool implicit_dp_fallback = (idp_ext == nullptr || !idp_ext->distribution_point_name().has_value());
511 const bool implicit = implicit_dp_fallback && implicit_dp_matches(crl, cert, idp_ext);
512 return {implicit, implicit};
513}
const T * get_extension_object_as(const OID &oid=T::static_oid()) const
Definition pkix_types.h:882
const Extensions & v3_extensions() const
Definition x509cert.cpp:517
botan_x509_crl_t crl
Definition ffi_tls.h:127

References crl, Botan::Extensions::get_extension_object_as(), and Botan::X509_Certificate::v3_extensions().

Referenced by Botan::X509_CRL::has_matching_distribution_point().

◆ dl_exponent_size()

size_t BOTAN_TEST_API Botan::dl_exponent_size ( size_t prime_group_size)

Return the appropriate exponent size to use for a particular prime group. This is twice the size of the estimated cost of breaking the key using an index calculus attack; the assumption is that if an arbitrary discrete log on a group of size bits would take about 2^n effort, and thus using an exponent of size 2^(2*n) implies that all available attacks are about as easy (as e.g Pollard's kangaroo algorithm can compute the DL in sqrt(x) operations) while minimizing the exponent size for performance reasons.

Definition at line 53 of file workfactor.cpp.

53 {
54 BOTAN_ARG_CHECK(p_bits > 1, "Invalid prime length");
55
56 /*
57 For relevant sizes we follow the suggestions in
58 NIST SP 800-56B Rev 2 Appendix D
59 "Maximum Security Strength Estimates for IFC Modulus Lengths"
60
61 For sizes outside the range considered in the SP we use some sensible values
62
63 Note that we return twice the value given in Table 4 since we are choosing
64 the exponent size as twice the estimated security strength.
65
66 See also NIST SP 800-56A Rev 3 Appendix D, Tables 25 and 26
67 */
68
69 if(p_bits <= 256) {
70 /*
71 * For stupidly small groups we might return a value larger than the group
72 * size if we fell into the conditionals below. Just use the maximum
73 * possible exponent size - for all the good it will do you with a group
74 * this weak.
75 */
76 return p_bits - 1;
77 } else if(p_bits <= 1024) {
78 /*
79 Not in the SP, but general estimates are that a 1024 bit group provides at
80 most 80 bits security, so using an exponent appropriate for 96 bit security
81 is more than sufficient.
82 */
83 return 192;
84 } else if(p_bits <= 2048) {
85 return 224; // SP 800-56B
86 } else if(p_bits <= 3072) {
87 return 256; // SP 800-56B
88 } else if(p_bits <= 4096) {
89 return 304; // SP 800-56B
90 } else if(p_bits <= 6144) {
91 return 352; // SP 800-56B
92 } else if(p_bits <= 8192) {
93 return 400; // SP 800-56B
94 } else {
95 // For values larger than we know about, just saturate to 256 bit security
96 // which is Good Enough for FFDH
97 //
98 // NIST puts 15360 bit groups at exactly 256 bits security
99 return 512;
100 }
101}

References BOTAN_ARG_CHECK.

Referenced by Botan::DL_Group::DL_Group().

◆ dl_work_factor()

size_t BOTAN_TEST_API Botan::dl_work_factor ( size_t prime_group_size)

Estimate work factor for discrete logarithm

Parameters
prime_group_sizesize of the group in bits
Returns
estimated security level for this group

Definition at line 48 of file workfactor.cpp.

48 {
49 // Lacking better estimates...
50 return if_work_factor(bits);
51}
size_t if_work_factor(size_t bits)

References if_work_factor().

◆ do_throw_error()

template<typename E, typename... Args>
void Botan::do_throw_error ( const char * file,
int line,
const char * func,
Args... args )
inline

Throw an exception of type E, prefixing the message with the source location

Parameters
filethe source file name
linethe source line number
functhe enclosing function name
argsthe remaining arguments forwarded to E's constructor

Definition at line 514 of file exceptn.h.

514 {
515 throw E(file, line, func, args...);
516}

◆ ecp_work_factor()

size_t Botan::ecp_work_factor ( size_t prime_group_size)

Estimate work factor for EC discrete logarithm

Parameters
prime_group_sizesize of the group in bits
Returns
estimated security level for this group

Definition at line 16 of file workfactor.cpp.

16 {
17 return bits / 2;
18}

Referenced by Botan::EC_PublicKey::estimated_strength().

◆ ed25519_basepoint_mul()

void Botan::ed25519_basepoint_mul ( std::span< uint8_t, 32 > out,
const Ed25519_Scalar & scalar )

Compute the Ed25519 point [scalar]B and write its encoding to out

Definition at line 624 of file ed25519_ge.cpp.

624 {
625 const auto h = basepoint_mul(scalar);
626 h.serialize_to(out);
627}

◆ ed25519_basepoint_mul_to_x25519()

void Botan::ed25519_basepoint_mul_to_x25519 ( std::span< uint8_t, 32 > out,
const Ed25519_Scalar & scalar )

Compute the Ed25519 point [scalar]B and write the Montgomery u-coordinate of its image on Curve25519 to out, in the X25519 encoding.

Since the Ed25519 base point maps to the X25519 base point u = 9, this is the X25519 public key for scalar (which must already be reduced mod l; reducing does not change the result since B has order l). This uses the fixed-base tables and is several times faster than the Montgomery ladder.

Definition at line 629 of file ed25519_ge.cpp.

629 {
630 const auto h = basepoint_mul(scalar);
631
632 /*
633 * The birational map from the twisted Edwards curve to Curve25519 sends
634 * (x, y) to u = (1 + y) / (1 - y) (RFC 7748 Section 4.1), which for a
635 * projective point (X : Y : Z) is (Z + Y) / (Z - Y). The map sends the
636 * Ed25519 base point to u = 9, so this is the X25519 public key for the
637 * scalar.
638 *
639 * The only point with Z == Y is the identity, where the inversion of zero
640 * returns zero and so u == 0, matching what the Montgomery ladder produces
641 * for the identity. A clamped X25519 scalar is never zero mod l so this
642 * cannot happen for X25519 anyway.
643 */
644 const auto u = (h.Z + h.Y) * (h.Z - h.Y).invert();
645 u.serialize_to(out);
646}

Referenced by x25519_basepoint().

◆ ed25519_check_signature()

bool Botan::ed25519_check_signature ( std::span< const uint8_t, 32 > pk,
const Ed25519_Scalar & h,
const uint8_t r[32],
const Ed25519_Scalar & s )

Definition at line 648 of file ed25519_ge.cpp.

651 {
652 if(auto A = frombytes_negate_vartime(pk)) {
653 std::array<uint8_t, 32> rcheck{};
654 ge_double_scalarmult_vartime(rcheck, h, *A, s);
655 return CT::is_equal(rcheck.data(), r, 32).as_bool();
656 }
657 return false;
658}

References Botan::CT::is_equal().

◆ ed25519_fp_words()

std::array< word, 256/WordInfo< word >::bits > Botan::ed25519_fp_words ( )
consteval

Definition at line 22 of file ed25519_fe.h.

22 {
23 // 2^255 - 19
24 std::array<word, 256 / WordInfo<word>::bits> p{};
25 for(auto& w : p) {
26 w = WordInfo<word>::max;
27 }
28 p[0] -= 18;
29 p[p.size() - 1] >>= 1;
30 return p;
31}

◆ ed25519_gen_keypair()

void Botan::ed25519_gen_keypair ( uint8_t pk[32],
uint8_t sk[64],
const uint8_t seed[32] )

Definition at line 522 of file ed25519_key.cpp.

522 {
523 const auto key = Ed25519_PrivateKey::from_seed(std::span<const uint8_t>{seed, 32});
524 const auto pub_bytes = key.raw_public_key_bits();
525 const auto priv_bytes = key.raw_private_key_bits();
526 copy_mem(pk, pub_bytes.data(), 32);
527 copy_mem(sk, priv_bytes.data(), 64);
528}
static Ed25519_PrivateKey from_seed(std::span< const uint8_t > seed)
std::vector< uint8_t > raw_public_key_bits() const override

References copy_mem(), Botan::Ed25519_PrivateKey::from_seed(), and Botan::Ed25519_PublicKey::raw_public_key_bits().

Referenced by Botan::Sodium::crypto_sign_ed25519_seed_keypair().

◆ ed25519_sign()

void Botan::ed25519_sign ( uint8_t sig[64],
const uint8_t msg[],
size_t msg_len,
const uint8_t sk[64],
const uint8_t domain_sep[],
size_t domain_sep_len )

Definition at line 530 of file ed25519_key.cpp.

535 {
536 const auto key = Ed25519_PrivateKey::from_bytes(std::span<const uint8_t>{sk, 64});
537
538 Null_RNG null_rng;
539
540 std::vector<uint8_t> sig_vec;
541 if(domain_sep_len == 0) {
542 PK_Signer signer(key, null_rng, PK_Signature_Options());
543 signer.update(std::span<const uint8_t>{msg, msg_len});
544 sig_vec = signer.signature(null_rng);
545 } else {
546 Ed25519_Pure_Sign_Operation op(std::make_shared<Ed25519_PrivateKey_Data>(key.raw_private_key_bits()),
547 std::vector<uint8_t>(domain_sep, domain_sep + domain_sep_len));
548 op.update(std::span<const uint8_t>{msg, msg_len});
549 sig_vec = op.sign(null_rng);
550 }
551
552 copy_mem(sig, sig_vec.data(), 64);
553}
static Ed25519_PrivateKey from_bytes(std::span< const uint8_t > bytes)

References copy_mem(), Botan::Ed25519_PrivateKey::from_bytes(), Botan::PK_Signer::signature(), and Botan::PK_Signer::update().

Referenced by Botan::Sodium::crypto_sign_ed25519_detached().

◆ ed25519_valid_public_key_point()

bool Botan::ed25519_valid_public_key_point ( std::span< const uint8_t, 32 > pk)

Check that this is a valid public key point encoding: it must decode, must not be the identity or the point of order 2, and must lie within the prime order subgroup

Definition at line 660 of file ed25519_ge.cpp.

660 {
661 if(auto A = frombytes_negate_vartime(pk)) {
662 // Points with x == 0 are the identity and the point of order 2;
663 // neither is a valid public key
664 if(A->X.is_zero()) {
665 return false;
666 }
667
668 /*
669 * Check that the point is in the prime order subgroup, ie that
670 * [l]A == O, by checking that [l-1]A + A == O, or equivalently that
671 * [l-1]A == -A. Since l-1 == -1 (mod l) the scalar is just -1, and
672 * since frombytes_negate_vartime returned -A the final comparison is
673 * against the encoding of A, ie of the negation of what it returned.
674 */
675 auto neg_A = *A;
676 neg_A.X = -A->X;
677 neg_A.T = -A->T;
678
679 std::array<uint8_t, 32> acheck{};
680 neg_A.serialize_to(acheck);
681
682 std::array<uint8_t, 32> rcheck{};
683 ge_double_scalarmult_vartime(rcheck, -Ed25519_Scalar::one(), *A, Ed25519_Scalar::zero());
684
685 return CT::is_equal(rcheck.data(), acheck.data(), 32).as_bool();
686 }
687 return false;
688}
static Ed25519_Scalar zero()
static Ed25519_Scalar one()

References Botan::CT::is_equal(), Botan::Ed25519_Scalar::one(), and Botan::Ed25519_Scalar::zero().

◆ ed25519_verify()

bool Botan::ed25519_verify ( const uint8_t msg[],
size_t msg_len,
const uint8_t sig[64],
const uint8_t pk[32],
const uint8_t domain_sep[],
size_t domain_sep_len )

Definition at line 555 of file ed25519_key.cpp.

560 {
561 try {
562 const Ed25519_PublicKey key(std::span<const uint8_t>{pk, 32});
563
564 if(domain_sep_len == 0) {
565 PK_Verifier verifier(key, PK_Signature_Options());
566 verifier.update(std::span<const uint8_t>{msg, msg_len});
567 return verifier.check_signature(std::span<const uint8_t>{sig, 64});
568 } else {
569 Ed25519_Pure_Verify_Operation op(std::make_shared<Ed25519_PublicKey_Data>(key.raw_public_key_bits()),
570 std::vector<uint8_t>(domain_sep, domain_sep + domain_sep_len));
571 op.update(std::span<const uint8_t>{msg, msg_len});
572 return op.is_valid_signature(std::span<const uint8_t>{sig, 64});
573 }
574 } catch(Decoding_Error&) {
575 // An invalid public key cannot have signed anything
576 return false;
577 }
578}

References Botan::PK_Verifier::check_signature(), and Botan::PK_Verifier::update().

Referenced by Botan::Sodium::crypto_sign_ed25519_verify_detached().

◆ ed448_validate_public_key_point()

void Botan::ed448_validate_public_key_point ( std::span< const uint8_t, ED448_LEN > pk)

Check that this is a valid public key point encoding: it must decode, must not be the identity or another point of small order, and must lie within the prime order subgroup

Exceptions
Decoding_Errorif any of these checks fail

Definition at line 468 of file ed448_internal.cpp.

468 {
469 const auto A = Ed448Point::decode(pk);
470
471 if(A.is_identity()) {
472 throw Decoding_Error("Ed448 public key is the identity element");
473 }
474
475 /*
476 * Check that the point is in the prime order subgroup, ie that
477 * [L]A == O, by checking that [L-1]A == -A. Since L is odd this also
478 * rejects the points of order 2 and 4.
479 */
480 constexpr std::array<uint8_t, 56> L_minus_1 = {
481 0xf2, 0x44, 0x58, 0xab, 0x92, 0xc2, 0x78, 0x23, 0x55, 0x8f, 0xc5, 0x8d, 0x72, 0xc2, 0x6c, 0x21, 0x90, 0x36, 0xd6,
482 0xae, 0x49, 0xdb, 0x4e, 0xc4, 0xe9, 0x23, 0xca, 0x7c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
483 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f};
484
485 if((Scalar448(L_minus_1) * A) != A.negate()) {
486 throw Decoding_Error("Ed448 public key is not in the prime order subgroup");
487 }
488}
static Ed448Point decode(std::span< const uint8_t, ED448_LEN > enc)
Decode a point from its 57-byte encoding (RFC 8032 5.2.3).

References Botan::Ed448Point::decode().

Referenced by Botan::Ed448_PublicKey::Ed448_PublicKey().

◆ encode_gf2m()

uint32_t Botan::encode_gf2m ( gf2m to_enc,
uint8_t * mem )

Definition at line 107 of file gf2m_small_m.cpp.

107 {
108 mem[0] = to_enc >> 8;
109 mem[1] = to_enc & 0xFF;
110 return sizeof(to_enc);
111}

◆ encode_ml_kem_private_key()

secure_vector< uint8_t > Botan::encode_ml_kem_private_key ( const KyberInternalKeypair & keypair,
MlPrivateKeyFormat format )

Encodes an ML-KEM private key as the CHOICE alternative of the ML-KEM-PrivateKey structure of RFC 9935 selected by format.

Exceptions
Encoding_Errorif format requires the seed but the key pair does not contain it

Definition at line 237 of file kyber_keys.cpp.

237 {
238 BOTAN_ASSERT_NONNULL(keypair.second);
239 BOTAN_ARG_CHECK(keypair.second->mode().mode().is_ml_kem(),
240 "RFC 9935 private key encodings are only defined for ML-KEM");
241 if(format != MlPrivateKeyFormat::Expanded && !keypair.second->seed().d.has_value()) {
242 throw Encoding_Error("ML-KEM private key does not contain the seed, cannot encode it in the requested format");
243 }
244
245 DER_Encoder der_enc;
246 switch(format) {
248 // RFC 9935 "seed" CHOICE alternative: [0] IMPLICIT OCTET STRING
249 der_enc.encode(Seed_Expanding_Keypair_Codec().encode_keypair(keypair),
251 ASN1_Type(0),
253 break;
255 // RFC 9935 "expandedKey" CHOICE alternative: OCTET STRING
256 der_enc.encode(Expanded_Keypair_Codec().encode_keypair(keypair), ASN1_Type::OctetString);
257 break;
259 // RFC 9935 "both" CHOICE alternative:
260 // SEQUENCE { seed OCTET STRING, expandedKey OCTET STRING }
261 der_enc.start_sequence()
262 .encode(Seed_Expanding_Keypair_Codec().encode_keypair(keypair), ASN1_Type::OctetString)
263 .encode(Expanded_Keypair_Codec().encode_keypair(keypair), ASN1_Type::OctetString)
264 .end_cons();
265 break;
266 }
267
268 return der_enc.get_contents();
269}
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:121

References BOTAN_ARG_CHECK, BOTAN_ASSERT_NONNULL, Both, ContextSpecific, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Expanded, Botan::DER_Encoder::get_contents(), OctetString, Seed, and Botan::DER_Encoder::start_sequence().

Referenced by Botan::Kyber_PrivateKey::formatted_private_key_bits().

◆ encode_point()

secure_vector< uint8_t > Botan::encode_point ( const Point448 & p)

Encode a point to a 56 byte vector. RFC 7748 Section 5 (encodeUCoordinate).

Definition at line 21 of file x448_internal.cpp.

21 {
22 return {p.begin(), p.end()};
23}
decltype(auto) begin() noexcept(noexcept(this->get().begin()))
decltype(auto) end() noexcept(noexcept(this->get().end()))

References Botan::detail::Container_Strong_Adapter_Base< T >::begin(), and Botan::detail::Container_Strong_Adapter_Base< T >::end().

Referenced by Botan::X448_PublicKey::check_key().

◆ escape_control_chars()

BOTAN_TEST_API std::string Botan::escape_control_chars ( std::string_view utf8)

Return a copy of utf8 with control characters escaped for safe display

C0 controls (0x00..0x1F), DEL (0x7F), and C1 controls (U+0080..U+009F) are each replaced by a "\xHH" escape per byte; all other code points, including printable non-ASCII, are passed through unchanged. Any byte that is not part of a valid UTF-8 sequence is escaped individually.

Definition at line 207 of file charset.cpp.

207 {
208 std::string out;
209 out.reserve(utf8.size());
210
211 const auto append_hex_escape = [&](uint8_t b) {
212 out += "\\x";
213 out += nibble_to_hex(b >> 4);
214 out += nibble_to_hex(b);
215 };
216
217 size_t pos = 0;
218 while(pos < utf8.size()) {
219 const size_t start = pos;
220
221 uint32_t cp = 0;
222 try {
223 cp = next_utf8_codepoint(utf8, pos);
224 } catch(const Decoding_Error&) {
225 // Not valid UTF-8: escape the offending byte and resume
226 append_hex_escape(static_cast<uint8_t>(utf8[start]));
227 pos = start + 1;
228 continue;
229 }
230
232 for(size_t i = start; i < pos; ++i) {
233 append_hex_escape(static_cast<uint8_t>(utf8[i]));
234 }
235 } else {
236 out.append(utf8.substr(start, pos - start));
237 }
238 }
239
240 return out;
241}
constexpr char nibble_to_hex(uint8_t b)
Definition charset.h:76
bool is_unicode_control_char(uint32_t cp)
Definition charset.cpp:203
uint32_t next_utf8_codepoint(std::string_view utf8, size_t &pos)
Definition charset.cpp:53

References is_unicode_control_char(), next_utf8_codepoint(), and nibble_to_hex().

Referenced by Botan::X509_Certificate::to_string().

◆ esdm_rng()

RandomNumberGenerator & Botan::esdm_rng ( )

Return a shared reference to a global PRNG instance provided by ESDM

Definition at line 101 of file esdm_rng.cpp.

101 {
102 static ESDM_RNG g_esdm_rng;
103 return g_esdm_rng;
104}

◆ expand_mask_16bit()

template<typename T>
uint16_t Botan::expand_mask_16bit ( T tst)

Expand an input to a bit mask depending on it being being zero or non-zero

Parameters
tstthe input
Returns
the mask 0xFFFF if tst is non-zero and 0 otherwise

Definition at line 25 of file code_based_util.h.

25 {
26 const uint16_t result = (tst != 0);
27 return ~(result - 1);
28}

Referenced by Botan::polyn_gf2m::calc_degree_secure(), Botan::polyn_gf2m::eea_with_coefficients(), and Botan::polyn_gf2m::patchup_deg_secure().

◆ expand_message_xmd()

void BOTAN_TEST_API Botan::expand_message_xmd ( HashFunction & hash,
std::span< uint8_t > output,
std::span< const uint8_t > input,
std::span< const uint8_t > domain_sep )

XMD hash function from RFC 9380

This is only used internally to implement hash2curve so is not exposed to end users.

The hash must be in its initial state. The caller is responsible for checking that the hash is strong enough for the target security level, as required by RFC 9380.

Definition at line 17 of file xmd.cpp.

20 {
21 const size_t block_size = hash.hash_block_size();
22 if(block_size == 0) {
23 throw Invalid_Argument(fmt("expand_message_xmd cannot be used with {}", hash.name()));
24 }
25
26 const size_t hash_output_size = hash.output_length();
27
28 // RFC 9380 Section 5.3.1: "For correctness, H requires b <= s."
29 if(hash_output_size > block_size || hash_output_size == 0 || hash_output_size >= 256) {
30 throw Invalid_Argument(fmt("expand_message_xmd cannot be used with {}", hash.name()));
31 }
32
33 if(output.size() > 255 * hash_output_size || output.size() > 0xFFFF) {
34 throw Invalid_Argument("expand_message_xmd requested output length too long");
35 }
36
37 std::vector<uint8_t> hashed_domain_sep;
38 if(domain_sep.size() > 0xFF) {
39 /* RFC 9380 section 5.3.3: "If applications require a domain
40 * separation tag longer than 255 bytes, e.g., because of
41 * requirements imposed by an invoking protocol, implementors MUST
42 * compute a short domain separation tag by hashing, as follows:
43 *
44 * For expand_message_xmd using hash function H, DST is computed as
45 *
46 * DST = H("H2C-OVERSIZE-DST-" || a_very_long_DST)"
47 */
48 hash.update("H2C-OVERSIZE-DST-");
49 hash.update(domain_sep);
50 hashed_domain_sep = hash.final_stdvec();
51 domain_sep = hashed_domain_sep;
52 }
53
54 if(domain_sep.empty()) {
55 // RFC 9380 Section 3.1: "Tags MUST have nonzero length."
56 throw Invalid_Argument("expand_message_xmd requires a non-empty domain separation tag");
57 }
58
59 const uint8_t domain_sep_len = static_cast<uint8_t>(domain_sep.size());
60
61 // Compute b_0 = H(msg_prime) = H(Z_pad || msg || l_i_b_str || 0x00 || DST_prime)
62
63 hash.update(std::vector<uint8_t>(block_size));
64 hash.update(input);
65 hash.update_be(static_cast<uint16_t>(output.size()));
66 hash.update(0x00);
67 hash.update(domain_sep);
68 hash.update(domain_sep_len);
69
70 const secure_vector<uint8_t> b_0 = hash.final();
71
72 // Compute b_1 = H(b_0 || 0x01 || DST_prime)
73
74 hash.update(b_0);
75 hash.update(0x01);
76 hash.update(domain_sep);
77 hash.update(domain_sep_len);
78
79 secure_vector<uint8_t> b_i = hash.final();
80
81 uint8_t cnt = 2;
82 for(;;) {
83 const size_t produced = std::min(output.size(), hash_output_size);
84
85 copy_mem(output.data(), b_i.data(), produced);
86 output = output.subspan(produced);
87
88 if(output.empty()) {
89 break;
90 }
91
92 // Now compute the next b_i if needed
93
94 b_i ^= b_0;
95 hash.update(b_i);
96 hash.update(cnt);
97 hash.update(domain_sep);
98 hash.update(domain_sep_len);
99 hash.final(b_i);
100 cnt += 1;
101 }
102}
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:35
virtual size_t output_length() const =0
std::vector< uint8_t > final_stdvec()
Definition buf_comp.h:114
void update_be(uint16_t val)
Definition buf_comp.cpp:18
void final(uint8_t out[])
Definition buf_comp.h:97
virtual size_t hash_block_size() const
Definition hash.h:68
virtual std::string name() const =0

References copy_mem(), Botan::Buffered_Computation::final(), Botan::Buffered_Computation::final_stdvec(), fmt(), Botan::HashFunction::hash_block_size(), Botan::HashFunction::name(), Botan::Buffered_Computation::output_length(), Botan::Buffered_Computation::update(), and Botan::Buffered_Computation::update_be().

Referenced by h2c_expand_message().

◆ extended_euclidean_algorithm()

template<std::integral T>
eea_result< T > Botan::extended_euclidean_algorithm ( T a,
T b )
consteval

Run the extended Euclidean algorithm to find the greatest common divisor of a and b and the Bézout coefficients, u and v.

Definition at line 69 of file pqcrystals_helpers.h.

69 {
70 if(a > b) {
71 std::swap(a, b);
72 }
73
74 T u1 = 0;
75 T v1 = 1;
76 T u2 = 1;
77 T v2 = 0;
78
79 if(a != b) {
80 while(a != 0) {
81 const T q = b / a;
82 std::tie(a, b) = std::make_tuple(static_cast<T>(b - q * a), a);
83 std::tie(u1, v1, u2, v2) = std::make_tuple(u2, v2, static_cast<T>(u1 - q * u2), static_cast<T>(v1 - q * v2));
84 }
85 }
86
87 return {.gcd = b, .u = u1, .v = v1};
88}

Referenced by modular_inverse().

◆ externally_computed_prehash_name()

std::optional< std::string > Botan::externally_computed_prehash_name ( const PK_Signature_Options_Reader & options)

For schemes which can sign an externally computed prehash

Returns the name of the hash function the caller used, if it was named (either in the prehash option or via with_hash; if both were given they must agree), or nullopt if the input is an unidentified digest.

Must only be called if using_externally_computed_prehash() is true.

Definition at line 333 of file pk_options_impl.cpp.

333 {
335
336 const auto& prehash = options.externally_computed_prehash_function();
337 const auto& hash = options.hash_function();
338
339 if(prehash.has_value() && hash.has_value() && *prehash != *hash) {
340 throw Invalid_Argument(
341 fmt("Externally computed prehash was named as {} but the hash option specified {}", *prehash, *hash));
342 }
343
344 return prehash.has_value() ? prehash : hash;
345}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
const std::optional< std::string > & hash_function() const
const std::optional< std::string > & externally_computed_prehash_function() const

References BOTAN_STATE_CHECK, Botan::PK_Signature_Options_Reader::externally_computed_prehash_function(), fmt(), Botan::PK_Signature_Options_Reader::hash_function(), and Botan::PK_Signature_Options_Reader::using_externally_computed_prehash().

Referenced by Botan::PKCS11::MechanismWrapper::create_rsa_sign_mechanism(), and Botan::PKCS1v15_Raw_SignaturePaddingScheme::PKCS1v15_Raw_SignaturePaddingScheme().

◆ find_roots_gf2m_decomp()

secure_vector< gf2m > Botan::find_roots_gf2m_decomp ( const polyn_gf2m & polyn,
size_t code_length )

Find the roots of a polynomial over GF(2^m) using the method by Federenko et al.

Definition at line 241 of file gf2m_rootfind_dcmp.cpp.

241 {
242 gf2m_decomp_rootfind_state state(polyn, code_length);
243 return state.find_roots(polyn);
244}

References find_roots_gf2m_decomp().

Referenced by find_roots_gf2m_decomp().

◆ floor_log2()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::floor_log2 ( T n)
constexpr

Definition at line 134 of file bit_ops.h.

134 {
135 BOTAN_ARG_CHECK(n != 0, "log2(0) is not defined");
136 return static_cast<T>(high_bit(n) - 1);
137}
BOTAN_FORCE_INLINE constexpr size_t high_bit(T n)
Definition bit_ops.h:73

References BOTAN_ARG_CHECK, BOTAN_FORCE_INLINE, and high_bit().

Referenced by Botan::Classic_McEliece_GF::log_q_from_mod(), and Botan::Classic_McEliece_Parameters::tau().

◆ fmt()

template<typename... T>
std::string Botan::fmt ( std::string_view format,
const T &... args )

Simple formatter utility.

Should be replaced with std::format once that's available on all our supported compilers.

'{}' markers in the format string are replaced by the arguments. Unlike std::format, there is no support for escaping or for any kind of conversion flags.

Definition at line 53 of file fmt.h.

53 {
54 std::ostringstream oss;
55 oss.imbue(std::locale::classic());
56 fmt_detail::do_fmt(oss, format, args...);
57 return oss.str();
58}
void do_fmt(std::ostringstream &oss, std::string_view format)
Definition fmt.h:20

References Botan::fmt_detail::do_fmt().

Referenced by Botan::Private_Key::_create_decryption_op(), Botan::Public_Key::_create_encryption_op(), Botan::Private_Key::_create_kem_decryption_op(), Botan::Public_Key::_create_kem_encryption_op(), Botan::Private_Key::_create_key_agreement_op(), Botan::Private_Key::_create_signature_op(), Botan::Public_Key::_create_verification_op(), Botan::GeneralName::_dns_san_value(), Botan::GeneralName::_uri_san_value(), Botan::AlternativeName::add_attribute(), Botan::Certificate_Store_In_SQL::affirm_cert(), Botan::GOST_3410_PublicKey::algo_name(), Botan::KEX_to_KEM_Adapter_PublicKey::algo_name(), Botan::Algorithm_Not_Found::Algorithm_Not_Found(), Botan::AlternativeName::AlternativeName(), Botan::AlgorithmSpec::arg(), argon2_generate_pwhash(), Botan::ASN1_String::ASN1_String(), Botan::EC_PublicKey::assert_algorithm_identifier(), assert_unreachable(), Botan::HPKE::KEM_Ops::auth_decap(), Botan::HPKE::KEM_Ops::auth_encap(), Botan::HPKE::KEM_Ops::auth_encap_with_ephemeral(), Botan::TLS::auth_method_from_string(), Botan::BER_Bad_Tag::BER_Bad_Tag(), Botan::BER_Decoding_Error::BER_Decoding_Error(), Botan::Certificate_Store_In_SQL::Certificate_Store_In_SQL(), Botan::CFB_Mode::CFB_Mode(), Botan::TPM2::cipher_tss2_to_botan(), Botan::CMAC::CMAC(), Botan::CommonCrypto_Error::CommonCrypto_Error(), Botan::Compression_Error::Compression_Error(), Botan::TLS::Connection_Cipher_State::Connection_Cipher_State(), Botan::AES_256_CTR_XOF::copy_state(), Botan::HPKE::KEM_Ops::create(), Botan::KDF::create(), Botan::PasswordHashFamily::create(), Botan::PBKDF::create(), Botan::Sphincs_Parameters::create(), Botan::TPM2::PrivateKey::create(), Botan::TPM2::PublicKey::create(), Botan::PKCS11::MechanismWrapper::create_ecdh_mechanism(), Botan::PKCS11::MechanismWrapper::create_ecdsa_mechanism(), create_keccak_mb_engine(), Botan::SignaturePaddingScheme::create_or_throw(), create_private_key(), Botan::PKCS11::MechanismWrapper::create_rsa_crypt_mechanism(), Botan::PKCS11::MechanismWrapper::create_rsa_sign_mechanism(), create_shake_row_generator(), Botan::Public_Key::create_x509_verification_op(), Botan::PEM_Code::decode(), Botan::PEM_Code::decode_check_label(), Botan::AlternativeName::decode_from(), Botan::ASN1_String::decode_from(), Botan::ASN1_Time::decode_from(), Botan::Cert_Extension::ASBlocks::ASIdentifierChoice::decode_from(), Botan::Cert_Extension::ASBlocks::ASIdentifiers::decode_from(), Botan::Cert_Extension::ASBlocks::ASIdOrRange::decode_from(), Botan::Cert_Extension::IPAddressBlocks::IPAddressChoice< V >::decode_from(), Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::decode_from(), Botan::Cert_Extension::IPAddressBlocks::IPAddressOrRange< V >::decode_from(), Botan::Cert_Extension::TNAuthList::Entry::decode_from(), Botan::OCSP::SingleResponse::decode_from(), Botan::Decoding_Error::Decoding_Error(), Botan::DL_Group::DL_Group(), Botan::DL_Group::DL_Group(), Botan::GeneralName::dns(), Botan::EC_Group::EC_Group(), Botan::EC_Group_Data::EC_Group_Data(), Botan::GeneralName::email(), Botan::HPKE::KEM_Ops::encap_with_ephemeral(), Botan::PEM_Code::encode(), Botan::TPM2::Error::Error(), Botan::Exception::Exception(), Botan::Exception::Exception(), expand_message_xmd(), Botan::PKCS12::export_to(), externally_computed_prehash_name(), Botan::Certificate_Store_In_SQL::find_key(), Botan::Stream_Decompression::finish(), Botan::DL_Group::from_name(), Botan::EC_Group::from_name(), Botan::EC_Group::from_OID(), Botan::Classic_McEliece_Parameter_Set::from_oid(), Botan::PSS_Params::from_padding_name(), Botan::Classic_McEliece_Parameter_Set::from_string(), Botan::OID::from_string(), Botan::TLS::Signature_Scheme::from_string(), Botan::Certificate_Store_In_SQL::generate_crls(), generate_dsa_primes(), Botan::EC_PublicKey::get_int_field(), Botan::TLS::Stream_Handshake_IO::get_next_record(), Botan::TPM2::get_raw_rc(), Botan::GOST_28147_89::GOST_28147_89(), Botan::GOST_28147_89_Params::GOST_28147_89_Params(), h2c_expand_message(), Botan::AlgorithmMatch::has(), Botan::Sphincs_Parameters::hash_name(), hex_decode(), hkdf_expand_label(), Botan::HMAC_DRBG::HMAC_DRBG(), Botan::HSS_LMS_Params::HSS_LMS_Params(), Botan::Hybrid_PublicKey::Hybrid_PublicKey(), Botan::Certificate_Store_In_SQL::insert_key(), Botan::AlgorithmMatch::integer(), Botan::Invalid_Algorithm_Name::Invalid_Algorithm_Name(), Botan::Invalid_Argument::Invalid_Argument(), Botan::Invalid_IV_Length::Invalid_IV_Length(), Botan::Invalid_Key_Length::Invalid_Key_Length(), Botan::Pipe::Invalid_Message_Number::Invalid_Message_Number(), Botan::HPKE::KDF_Id::is_available(), Botan::TLS::kex_method_from_string(), Botan::HPKE::AEAD_Id::key_length(), Botan::Key_Not_Set::Key_Not_Set(), Botan::HPKE::labeled_expand(), Botan::HPKE::labeled_extract(), Botan::Lion::Lion(), load_private_key(), load_public_key(), Botan::PEM_Code::matches(), Botan::AlgorithmMatch::name(), Botan::BLAKE2b::name(), Botan::BLAKE2s::name(), Botan::Cascade_Cipher::name(), Botan::CBC_Mode::name(), Botan::CCM_Mode::name(), Botan::CFB_Mode::name(), Botan::ChaCha::name(), Botan::CMAC::name(), Botan::Comb4P::name(), Botan::CTR_BE::name(), Botan::DilithiumMessageHash::name(), Botan::FPE_FE1::name(), Botan::GCM_Mode::name(), Botan::GCM_SIV_Mode::name(), Botan::GMAC::name(), Botan::HKDF::name(), Botan::HKDF_Expand::name(), Botan::HKDF_Extract::name(), Botan::HMAC::name(), Botan::HMAC_DRBG::name(), Botan::ISO_9796_DS2::name(), Botan::ISO_9796_DS3::name(), Botan::KDF1::name(), Botan::KDF1_18033::name(), Botan::KDF2::name(), Botan::Keccak_1600::name(), Botan::KMAC128::name(), Botan::KMAC256::name(), Botan::Lion::name(), Botan::OFB::name(), Botan::PBKDF2_Family::name(), Botan::PKCS12_KDF_Family::name(), Botan::PKCS1v15_Raw_SignaturePaddingScheme::name(), Botan::PKCS1v15_SignaturePaddingScheme::name(), Botan::PKCS5_PBKDF2::name(), Botan::PSS_Raw::name(), Botan::PSSR::name(), Botan::RFC4880_S2K_Family::name(), Botan::SHA_3::name(), Botan::SHAKE_128::name(), Botan::SHAKE_256::name(), Botan::SignRawBytes::name(), Botan::SipHash::name(), Botan::Skein_512::name(), Botan::SP800_108_Counter::name(), Botan::SP800_108_Feedback::name(), Botan::SP800_108_Pipeline::name(), Botan::SP800_56C_One_Step_Hash::name(), Botan::SP800_56C_One_Step_HMAC::name(), Botan::SP800_56C_Two_Step::name(), Botan::Streebog::name(), Botan::TLS::TLS_NULL_HMAC_AEAD_Mode::name(), Botan::TLS_12_PRF::name(), Botan::Truncated_Hash::name(), Botan::X931_SignaturePadding::name(), Botan::HPKE::AEAD_Id::nonce_length(), Botan::Asymmetric_Key::object_identifier(), Botan::OID::OID(), Botan::HPKE::KDF_Id::output_length(), parse_legacy_sig_options(), pbes2_decrypt(), Botan::PK_Decryptor_EME::PK_Decryptor_EME(), Botan::PK_Encryptor_EME::PK_Encryptor_EME(), Botan::PK_KEM_Decryptor::PK_KEM_Decryptor(), Botan::PK_KEM_Encryptor::PK_KEM_Encryptor(), Botan::PK_Key_Agreement::PK_Key_Agreement(), Botan::PK_Signer::PK_Signer(), Botan::PK_Verifier::PK_Verifier(), Botan::PK_Verifier::PK_Verifier(), Botan::PKCS11::PKCS11_ReturnError::PKCS11_ReturnError(), Botan::PKCS12::PKCS12(), pkcs12_pbe_decrypt(), pkcs12_pbe_encrypt(), Botan::Entropy_Source::poll(), Botan::PRNG_Unseeded::PRNG_Unseeded(), Botan::Provider_Not_Found::Provider_Not_Found(), Botan::Credentials_Manager::psk(), Botan::HTTP::read_response_from_socket(), Botan::Certificate_Store_In_SQL::remove_cert(), Botan::Certificate_Store_In_SQL::remove_key(), Botan::Dynamically_Loaded_Library::resolve_symbol(), Botan::AlgorithmMatch::rest(), Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator(), Botan::Sqlite3_Database::row_count(), Botan::RSA_PrivateKey::RSA_PrivateKey(), runtime_version_check(), Botan::CTR_BE::seek(), Botan::Kyber_Symmetric_Primitives::shake_XOF_batch(), Botan::Sphincs_Hash_Functions_Sha2::Sphincs_Hash_Functions_Sha2(), Botan::Sphincs_Hash_Functions_Shake::Sphincs_Hash_Functions_Shake(), split_on(), srp6_client_agree(), srp6_generate_verifier(), Botan::TLS::Text_Policy::srtp_profiles(), Botan::XOF::start(), Botan::SRP6_Server_Session::step1(), Botan::SRP6_Server_Session::step2(), Botan::AlgorithmMatch::str(), Botan::Streebog::Streebog(), Botan::System_Error::System_Error(), Botan::HPKE::AEAD_Id::tag_length(), throw_invalid_argument(), throw_invalid_state(), Botan::TLS::Callbacks::tls12_protocol_specific_kdf(), Botan::Argon2::to_string(), Botan::ASN1_Time::to_string(), Botan::Bcrypt_PBKDF::to_string(), Botan::EmailAddress::to_string(), Botan::HPKE::Suite::to_string(), Botan::IPv4Subnet::to_string(), Botan::IPv6Subnet::to_string(), Botan::PBKDF2::to_string(), Botan::PKCS12_KDF::to_string(), Botan::RFC4880_S2K::to_string(), Botan::Scrypt::to_string(), Botan::SmtpUtf8Mailbox::to_string(), to_u32bit(), Botan::Unknown_PK_Field_Name::Unknown_PK_Field_Name(), Botan::TLS::Cipher_State::update_read_keys(), Botan::TLS::Cipher_State::update_write_keys(), Botan::Sqlite3_Database::upsert(), Botan::GeneralName::uri(), Botan::UUID::UUID(), validate_for_hash_based_signature(), Botan::TLS::Certificate_Type_Base::validate_selection(), Botan::PK_Ops::Verification_with_Hash::Verification_with_Hash(), Botan::XMSS_Hash::XMSS_Hash(), Botan::XMSS_Parameters::xmss_id_from_string(), and Botan::XTS_Mode::XTS_Mode().

◆ format_char_for_display()

std::string Botan::format_char_for_display ( char c)

Return a string containing 'c', quoted and possibly escaped

This is used when creating an error message noting an invalid character in some codec (for example during hex decoding)

Tab, newline, and carriage return are escaped as "\t", "\n", and "\r". Any other control character (or DEL), and any byte above 0x7F, is escaped as "\xHH" where HH is the hex code.

Definition at line 243 of file charset.cpp.

243 {
244 std::string out;
245 out += '\'';
246
247 if(c == '\t') {
248 out += "\\t";
249 } else if(c == '\n') {
250 out += "\\n";
251 } else if(c == '\r') {
252 out += "\\r";
253 } else if(is_ascii_control_char(c) || static_cast<uint8_t>(c) >= 0x80) {
254 const auto b = static_cast<uint8_t>(c);
255 out += "\\x";
256 out += nibble_to_hex(b >> 4);
257 out += nibble_to_hex(b);
258 } else {
259 out += c;
260 }
261
262 out += '\'';
263
264 return out;
265}
bool is_ascii_control_char(char c)
Definition charset.cpp:198

References is_ascii_control_char(), and nibble_to_hex().

Referenced by hex_decode().

◆ format_hex_fingerprint()

std::string Botan::format_hex_fingerprint ( std::span< const uint8_t > bits)

Hex encode the data and separate them in blocks with : characters

Definition at line 47 of file pk_keys.cpp.

47 {
48 const std::string hex = hex_encode(bits);
49
50 std::string fprint;
51 fprint.reserve(3 * bits.size());
52
53 for(size_t i = 0; i != hex.size(); i += 2) {
54 if(i != 0) {
55 fprint.push_back(':');
56 }
57
58 fprint.push_back(hex[i]);
59 fprint.push_back(hex[i + 1]);
60 }
61
62 return fprint;
63}
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition hex.cpp:34

References hex_encode().

Referenced by create_hex_fingerprint().

◆ fors_public_key_from_signature()

BOTAN_TEST_API SphincsTreeNode Botan::fors_public_key_from_signature ( const SphincsHashedMessage & hashed_message,
StrongSpan< const ForsSignature > signature,
const Sphincs_Address & address,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hash )

FIPS 205, Algorithm 17: fors_pkFromSig.

Reconstructs the FORS public key from a given FORS signature and message. This is tailored for the use case in the SLH-DSA implementation and is not meant for general usability.

Definition at line 150 of file sp_fors.cpp.

154 {
155 const auto indices = fors_message_to_indices(hashed_message, params);
156
157 auto fors_tree_addr = Sphincs_Address::as_keypair_from(address).set_type(Sphincs_Address::ForsTree);
158
159 const auto fors_pk_addr =
160 Sphincs_Address::as_keypair_from(address).set_type(Sphincs_Address::ForsTreeRootsCompression);
161
162 BufferSlicer s(signature);
163 std::vector<uint8_t> roots_buffer(params.k() * params.n());
164 BufferStuffer roots(roots_buffer);
165
166 // For each of the k FORS subtrees: Reconstruct the subtree's root node by using the
167 // leaf and the authentication path offered in the FORS signature.
168 BOTAN_ASSERT_NOMSG(indices.size() == params.k());
169 for(uint32_t i = 0; i < params.k(); ++i) {
170 const uint32_t idx_offset = i * (1 << params.a());
171
172 // Compute the FORS leaf by using the secret leaf contained in the signature
173 fors_tree_addr.set_tree_height(TreeLayerIndex(0)).set_tree_index(indices[i] + idx_offset);
174 const auto fors_leaf_secret = s.take<ForsLeafSecret>(params.n());
175 const auto auth_path = s.take<SphincsAuthenticationPath>(params.n() * params.a());
176 const auto leaf = hashes.T<SphincsTreeNode>(fors_tree_addr, fors_leaf_secret);
177
178 // Reconstruct the subtree's root using the authentication path
179 compute_root(roots.next<SphincsTreeNode>(params.n()),
180 params,
181 hashes,
182 leaf,
183 indices[i],
184 idx_offset,
185 auth_path,
186 params.a(),
187 fors_tree_addr);
188 }
189
190 BOTAN_ASSERT_NOMSG(roots.full());
191
192 // Reconstruct the public key the signature creates with the hash of the concatenation of all roots
193 // Only if the signature is valid, the pk is the correct FORS pk.
194 return hashes.T<SphincsTreeNode>(fors_pk_addr, roots_buffer);
195}
Helper class to ease in-place marshalling of concatenated fixed-length values.
Sphincs_Address & set_type(Sphincs_Address_Type type)
Definition sp_address.h:71
static Sphincs_Address as_keypair_from(const Sphincs_Address &other)
Definition sp_address.h:128
Strong< secure_vector< uint8_t >, struct ForsLeafSecret_ > ForsLeafSecret
Definition sp_types.h:71
Strong< std::vector< uint8_t >, struct SphincsAuthenticationPath_ > SphincsAuthenticationPath
Definition sp_types.h:67
void compute_root(StrongSpan< SphincsTreeNode > out, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes, const SphincsTreeNode &leaf, TreeNodeIndex leaf_idx, uint32_t idx_offset, StrongSpan< const SphincsAuthenticationPath > authentication_path, uint32_t total_tree_height, Sphincs_Address &tree_address)

References Botan::Sphincs_Parameters::a(), Botan::Sphincs_Address::as_keypair_from(), BOTAN_ASSERT_NOMSG, compute_root(), Botan::BufferStuffer::full(), Botan::Sphincs_Parameters::k(), Botan::Sphincs_Parameters::n(), Botan::BufferStuffer::next(), Botan::Sphincs_Address::set_type(), Botan::Sphincs_Hash_Functions::T(), and Botan::BufferSlicer::take().

◆ fors_sign_and_pkgen()

BOTAN_TEST_API SphincsTreeNode Botan::fors_sign_and_pkgen ( StrongSpan< ForsSignature > sig_out,
const SphincsHashedMessage & hashed_message,
const SphincsSecretSeed & secret_seed,
const Sphincs_Address & address,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hashes )

FIPS 205, Algorithm 16: fors_sign (with simultaneous FORS pk generation).

Implements a domain specific wrapper for the few-times signature scheme FORS (Forest of Random Subsets). It is meant to be used inside SLH-DSA and does not aim to be applicable for other use cases.

Definition at line 63 of file sp_fors.cpp.

68 {
69 BOTAN_ASSERT_NOMSG(sig_out.size() == params.fors_signature_bytes());
70
71 const auto indices = fors_message_to_indices(hashed_message, params);
72
73 auto fors_tree_addr = Sphincs_Address::as_keypair_from(address);
74
75 const auto fors_pk_addr =
76 Sphincs_Address::as_keypair_from(address).set_type(Sphincs_Address::ForsTreeRootsCompression);
77
78 std::vector<uint8_t> roots_buffer(params.k() * params.n());
79 BufferStuffer roots(roots_buffer);
80 BufferStuffer sig(sig_out);
81
82 // Scratch space for batched leaf generation, reused across subtrees
83 std::vector<Sphincs_Address> leaf_addrs;
84 secure_vector<uint8_t> leaf_secrets;
85 std::vector<std::span<uint8_t>> secret_spans;
86 std::vector<std::span<const uint8_t>> csecret_spans;
87 std::vector<std::span<uint8_t>> leaf_spans;
88
89 // Each leaf is the hash of a secret derived from the leaf's address
90 const GenerateLeavesFunction fors_gen_leaves = [&](std::span<uint8_t> out, TreeNodeIndex first_idx, uint32_t count) {
91 leaf_addrs.assign(count, fors_tree_addr);
92 leaf_secrets.resize(count * params.n());
93 secret_spans.resize(count);
94 csecret_spans.resize(count);
95 leaf_spans.resize(count);
96
97 for(uint32_t j = 0; j != count; ++j) {
98 leaf_addrs[j]
100 .set_tree_height(TreeLayerIndex(0))
101 .set_tree_index(first_idx + j);
102 secret_spans[j] = std::span(leaf_secrets).subspan(j * params.n(), params.n());
103 csecret_spans[j] = secret_spans[j];
104 leaf_spans[j] = out.subspan(j * params.n(), params.n());
105 }
106
107 hashes.PRF_batch(secret_spans, secret_seed, leaf_addrs);
108
109 for(uint32_t j = 0; j != count; ++j) {
110 leaf_addrs[j].set_type(Sphincs_Address_Type::ForsTree);
111 }
112
113 hashes.T_batch(leaf_spans, leaf_addrs, csecret_spans);
114 };
115
116 // For each of the k FORS subtrees: Compute the secret leaf, the authentication path
117 // and the trees' root and append the signature respectively
118 BOTAN_ASSERT_NOMSG(indices.size() == params.k());
119 for(uint32_t i = 0; i < params.k(); ++i) {
120 const uint32_t idx_offset = i * (1 << params.a());
121
122 // Compute the secret leaf given by the chunk of the message and append it to the signature
123 fors_tree_addr.set_type(Sphincs_Address_Type::ForsKeyGeneration)
124 .set_tree_height(TreeLayerIndex(0))
125 .set_tree_index(indices[i] + idx_offset);
126
127 hashes.PRF(sig.next<ForsLeafSecret>(params.n()), secret_seed, fors_tree_addr);
128
129 // Compute the authentication path and root for this leaf node
130 fors_tree_addr.set_type(Sphincs_Address_Type::ForsTree);
131
132 treehash(roots.next<SphincsTreeNode>(params.n()),
133 sig.next<SphincsAuthenticationPath>(params.a() * params.n()),
134 params,
135 hashes,
136 indices[i],
137 idx_offset,
138 params.a(),
139 fors_gen_leaves,
140 fors_tree_addr);
141 }
142
143 BOTAN_ASSERT_NOMSG(sig.full());
144 BOTAN_ASSERT_NOMSG(roots.full());
145
146 // Compute the public key by the hash of the concatenation of all roots
147 return hashes.T<SphincsTreeNode>(fors_pk_addr, roots_buffer);
148}
void T_batch(std::span< std::span< uint8_t > > outputs, std::span< const Sphincs_Address > addresses, std::span< std::span< const uint8_t > > inputs)
Definition sp_hash.cpp:32
void PRF_batch(std::span< std::span< uint8_t > > outputs, const SphincsSecretSeed &sk_seed, std::span< const Sphincs_Address > addresses)
Definition sp_hash.cpp:56
void PRF(StrongSpan< ForsLeafSecret > out, const SphincsSecretSeed &sk_seed, const Sphincs_Address &address)
Definition sp_hash.h:72
uint32_t fors_signature_bytes() const
std::function< void(std::span< uint8_t >, TreeNodeIndex, uint32_t)> GenerateLeavesFunction
Definition sp_treehash.h:30
void treehash(StrongSpan< SphincsTreeNode > out_root, StrongSpan< SphincsAuthenticationPath > out_auth_path, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes, std::optional< TreeNodeIndex > leaf_idx, uint32_t idx_offset, uint32_t total_tree_height, const GenerateLeavesFunction &gen_leaves, Sphincs_Address &tree_address)

References Botan::Sphincs_Parameters::a(), Botan::Sphincs_Address::as_keypair_from(), BOTAN_ASSERT_NOMSG, Botan::Sphincs_Parameters::fors_signature_bytes(), ForsKeyGeneration, ForsTree, Botan::BufferStuffer::full(), Botan::Sphincs_Parameters::k(), Botan::Sphincs_Parameters::n(), Botan::BufferStuffer::next(), Botan::Sphincs_Hash_Functions::PRF(), Botan::Sphincs_Hash_Functions::PRF_batch(), Botan::Sphincs_Address::set_type(), Botan::StrongSpan< T >::size(), Botan::Sphincs_Hash_Functions::T(), Botan::Sphincs_Hash_Functions::T_batch(), and treehash().

◆ gcd()

BigInt Botan::gcd ( const BigInt & x,
const BigInt & y )

Compute the greatest common divisor

Parameters
xa positive integer
ya positive integer
Returns
gcd(x,y)

Definition at line 220 of file numthry.cpp.

220 {
221 if(a.is_zero()) {
222 return abs(b);
223 }
224 if(b.is_zero()) {
225 return abs(a);
226 }
227
228 const size_t sz = std::max(a.sig_words(), b.sig_words());
229 auto u = BigInt::with_capacity(sz);
230 auto v = BigInt::with_capacity(sz);
231 u += a;
232 v += b;
233
234 CT::poison_all(u, v);
235
236 u.set_sign(BigInt::Positive);
237 v.set_sign(BigInt::Positive);
238
239 // In the worst case we have two fully populated big ints. After right
240 // shifting so many times, we'll have reached the result for sure.
241 const size_t loop_cnt = u.bits() + v.bits();
242
243 // This temporary is big enough to hold all intermediate results of the
244 // algorithm. No reallocation will happen during the loop.
245 // Note however, that `ct_cond_assign()` will invalidate the 'sig_words'
246 // cache, which _does not_ shrink the capacity of the underlying buffer.
247 auto tmp = BigInt::with_capacity(sz);
248 secure_vector<word> ws(sz * 2);
249 size_t factors_of_two = 0;
250 for(size_t i = 0; i != loop_cnt; ++i) {
251 const auto both_odd = CT::Mask<word>::expand_bool(u.is_odd()) & CT::Mask<word>::expand_bool(v.is_odd());
252
253 // Subtract the smaller from the larger if both are odd
254 const auto u_gt_v = CT::Mask<word>::expand_bool(bigint_cmp(u._data(), u.size(), v._data(), v.size()) > 0);
255 bigint_sub_abs(tmp.mutable_data(), u._data(), v._data(), sz, ws.data());
256 u.ct_cond_assign((u_gt_v & both_odd).as_bool(), tmp);
257 v.ct_cond_assign((~u_gt_v & both_odd).as_bool(), tmp);
258
259 const auto u_is_even = CT::Mask<word>::expand_bool(u.is_even());
260 const auto v_is_even = CT::Mask<word>::expand_bool(v.is_even());
261 BOTAN_DEBUG_ASSERT((u_is_even | v_is_even).as_bool());
262
263 // When both are even, we're going to eliminate a factor of 2.
264 // We have to reapply this factor to the final result.
265 factors_of_two += (u_is_even & v_is_even).if_set_return(1);
266
267 // remove one factor of 2, if u is even
268 bigint_shr2(tmp.mutable_data(), sz, u._data(), sz, 1);
269 u.ct_cond_assign(u_is_even.as_bool(), tmp);
270
271 // remove one factor of 2, if v is even
272 bigint_shr2(tmp.mutable_data(), sz, v._data(), sz, 1);
273 v.ct_cond_assign(v_is_even.as_bool(), tmp);
274 }
275
276 // The GCD (without factors of two) is either in u or v, the other one is
277 // zero. The non-zero variable _must_ be odd, because all factors of two were
278 // removed in the loop iterations above.
279 BOTAN_DEBUG_ASSERT(u.is_zero() || v.is_zero());
280 BOTAN_DEBUG_ASSERT(u.is_odd() || v.is_odd());
281
282 // make sure that the GCD (without factors of two) is in u
283 u.ct_cond_assign(u.is_even() /* .is_zero() would not be constant time */, v);
284
285 // re-apply the factors of two
286 u.ct_shift_left(factors_of_two);
287
288 CT::unpoison_all(u, v);
289
290 return u;
291}
static BigInt with_capacity(size_t n)
Definition bigint.cpp:52
static constexpr Mask< T > expand_bool(bool v)
Definition ct_utils.h:402
constexpr void poison_all(const Ts &... ts)
Definition ct_utils.h:201
BigInt abs(const BigInt &n)
Definition numthry.h:22
constexpr int32_t bigint_cmp(const W x[], size_t x_size, const W y[], size_t y_size)
Definition mp_core.h:463
constexpr void bigint_shr2(W y[], size_t y_size, const W x[], size_t x_size, size_t shift)
Definition mp_core.h:382
constexpr auto bigint_sub_abs(W z[], const W x[], const W y[], size_t N, W ws[]) -> CT::Mask< W >
Definition mp_core.h:283

References abs(), bigint_cmp(), bigint_shr2(), bigint_sub_abs(), BOTAN_DEBUG_ASSERT, Botan::CT::Mask< T >::expand_bool(), Botan::BigInt::is_zero(), Botan::CT::poison_all(), Botan::BigInt::Positive, Botan::BigInt::sig_words(), Botan::CT::unpoison_all(), and Botan::BigInt::with_capacity().

Referenced by botan_mp_gcd(), generate_rsa_prime(), and lcm().

◆ generalize_to() [1/2]

template<typename GeneralVariantT, typename SpecialT>
requires (std::is_constructible_v<GeneralVariantT, std::decay_t<SpecialT>>)
GeneralVariantT Botan::generalize_to ( SpecialT && specific)
constexpr

Converts a given variant into another variant-ish whose type states are a super set of the given variant.

This is useful to convert restricted variant types into more general variants types.

Definition at line 88 of file stl_util.h.

90{
91 return std::forward<SpecialT>(specific);
92}

Referenced by Botan::TLS::TLS_Record_Layer::next_record(), and Botan::TLS::Handshake_Layer::parse_handshake_message().

◆ generalize_to() [2/2]

template<typename GeneralVariantT, typename... SpecialTs>
GeneralVariantT Botan::generalize_to ( std::variant< SpecialTs... > specific)
constexpr

Converts a given variant into another variant-ish whose type states are a super set of the given variant.

This is useful to convert restricted variant types into more general variants types.

Definition at line 102 of file stl_util.h.

102 {
103 static_assert(
105 "Desired general type must be implicitly constructible by all types of the specialized std::variant<>");
106 return std::visit([](auto s) -> GeneralVariantT { return s; }, std::move(specific));
107}
constexpr bool is_generalizable_to(const SpecialT &) noexcept
Definition stl_util.h:71

References is_generalizable_to().

◆ generate_bcrypt()

std::string Botan::generate_bcrypt ( std::string_view password,
RandomNumberGenerator & rng,
uint16_t work_factor = 12,
char version = 'a' )

Create a password hash using Bcrypt

Takes the password to hash, a rng, and a work_factor. The resulting password hash is returned as a string.

Higher work factors increase the amount of time the algorithm runs, increasing the cost of cracking attempts. The increase is exponential, so a work factor of 12 takes roughly twice as long as work factor 11. The default work factor was set to 10 up until the 2.8.0 release.

It is recommended to set the work factor as high as your system can tolerate (from a performance and latency perspective) since higher work factors greatly improve the security against GPU-based attacks. For example, for protecting high value administrator passwords, consider using work factor 15 or 16; at these work factors each bcrypt computation takes several seconds. Since admin logins will be relatively uncommon, it might be acceptable for each login attempt to take some time. As of 2018, a good password cracking rig (with 8 NVIDIA 1080 cards) can attempt about 1 billion bcrypt computations per month for work factor 13. For work factor 12, it can do twice as many. For work factor 15, it can do only one quarter as many attempts.

Due to bugs affecting various implementations of bcrypt, several different variants of the algorithm are defined. As of 2.7.0 Botan supports generating (or checking) the 2a, 2b, and 2y variants. Since Botan has never been affected by any of the bugs which necessitated these version upgrades, all three versions are identical beyond the version identifier. Which variant to use is controlled by the version argument.

The bcrypt work_factor must be at least 4 (though at this work factor bcrypt is not very secure). The bcrypt format allows up to 31, but Botan currently rejects all work factors greater than 18 since even that work factor requires roughly 15 seconds of computation on a fast machine.

Warning
The password is truncated at at most 72 characters; characters after that do not have any effect on the resulting hash. To support longer passwords, consider pre-hashing the password, for example by using the hex encoding of SHA-256 of the password as the input to bcrypt.
Parameters
passwordthe password.
Random Number Generatorsa random number generator
work_factorhow much work to do to slow down guessing attacks
versionwhich version to emit (may be 'a', 'b', or 'y' all of which have identical behavior in this implementation).
See also
https://www.usenix.org/events/usenix99/provos/provos_html/

TODO(Botan4) Convert work_factor to a size_t

Definition at line 148 of file bcrypt.cpp.

148 {
149 /*
150 2a, 2b and 2y are identical for our purposes because our implementation of 2a
151 never had the truncation or signed char bugs in the first place.
152 */
153
154 if(version != 'a' && version != 'b' && version != 'y') {
155 throw Invalid_Argument("Unknown bcrypt version '" + std::string(1, version) + "'");
156 }
157
158 std::vector<uint8_t> salt;
159 rng.random_vec(salt, 16);
160 return make_bcrypt(pass, salt, work_factor, version);
161}
void random_vec(std::span< uint8_t > v)
Definition rng.h:254

References Botan::RandomNumberGenerator::random_vec().

Referenced by botan_bcrypt_generate().

◆ generate_dsa_primes() [1/2]

std::vector< uint8_t > Botan::generate_dsa_primes ( RandomNumberGenerator & rng,
BigInt & p_out,
BigInt & q_out,
size_t pbits,
size_t qbits )

Generate DSA parameters using the FIPS 186 kosherizer

Parameters
Random Number Generatorsa random number generator
p_outwhere the prime p will be stored
q_outwhere the prime q will be stored
pbitshow long p will be in bits
qbitshow long q will be in bits
Returns
random seed used to generate this parameter set

Definition at line 138 of file dsa_gen.cpp.

138 {
139 while(true) {
140 std::vector<uint8_t> seed(qbits / 8);
141 rng.randomize(seed.data(), seed.size());
142
143 if(generate_dsa_primes(rng, p, q, pbits, qbits, seed)) {
144 return seed;
145 }
146 }
147}
bool generate_dsa_primes(RandomNumberGenerator &rng, BigInt &p, BigInt &q, size_t pbits, size_t qbits, const std::vector< uint8_t > &seed_c, size_t offset)
Definition dsa_gen.cpp:54

References generate_dsa_primes(), and Botan::RandomNumberGenerator::randomize().

◆ generate_dsa_primes() [2/2]

bool BOTAN_TEST_API Botan::generate_dsa_primes ( RandomNumberGenerator & rng,
BigInt & p_out,
BigInt & q_out,
size_t pbits,
size_t qbits,
const std::vector< uint8_t > & seed,
size_t offset = 0 )

Generate DSA parameters using the FIPS 186 kosherizer

Parameters
Random Number Generatorsa random number generator
p_outwhere the prime p will be stored
q_outwhere the prime q will be stored
pbitshow long p will be in bits
qbitshow long q will be in bits
SEEDthe seed used to generate the parameters
offsetoptional offset from seed to start searching at
Returns
true if seed generated a valid DSA parameter set, otherwise false. p_out and q_out are only valid if true was returned.

Definition at line 54 of file dsa_gen.cpp.

60 {
61 if(!fips186_3_valid_size(pbits, qbits)) {
62 throw Invalid_Argument(fmt("FIPS 186-3 does not allow DSA domain parameters of {}/{} bits long", pbits, qbits));
63 }
64
65 if(seed_c.size() * 8 < qbits) {
66 throw Invalid_Argument(
67 fmt("Generating a DSA parameter set with a {} bit long q requires a seed at least as many bits long", qbits));
68 }
69
70 const std::string hash_name = hash_function_for(qbits);
71 auto hash = HashFunction::create_or_throw(hash_name);
72
73 const size_t HASH_SIZE = hash->output_length();
74
75 class Seed final {
76 public:
77 explicit Seed(const std::vector<uint8_t>& s) : m_seed(s) {}
78
79 const std::vector<uint8_t>& value() const { return m_seed; }
80
81 Seed& operator++() {
82 for(size_t j = m_seed.size(); j > 0; --j) {
83 m_seed[j - 1] += 1;
84 if(m_seed[j - 1] != 0) {
85 break;
86 }
87 }
88 return (*this);
89 }
90
91 private:
92 std::vector<uint8_t> m_seed;
93 };
94
95 Seed seed(seed_c);
96
97 q._assign_from_bytes(hash->process(seed.value()));
98 q.set_bit(qbits - 1);
99 q.set_bit(0);
100
101 if(!is_prime_vartime(q, rng, 128, true)) {
102 return false;
103 }
104
105 const size_t n = (pbits - 1) / (HASH_SIZE * 8);
106 const size_t b = (pbits - 1) % (HASH_SIZE * 8);
107
108 BigInt X;
109 std::vector<uint8_t> V(HASH_SIZE * (n + 1));
110
111 const BigInt q2 = 2 * q;
112
113 for(size_t j = 0; j != 4 * pbits; ++j) {
114 for(size_t k = 0; k <= n; ++k) {
115 ++seed;
116 hash->update(seed.value());
117 hash->final(&V[HASH_SIZE * (n - k)]);
118 }
119
120 if(j >= offset) {
121 X._assign_from_bytes(std::span{V}.subspan(HASH_SIZE - 1 - b / 8));
122 X.set_bit(pbits - 1);
123
124 // Variable time division is OK here since DSA primes are public anyway
125 p = X - ((X % q2) - 1);
126
127 if(p.bits() == pbits && is_prime_vartime(p, rng, 128, true)) {
128 return true;
129 }
130 }
131 }
132 return false;
133}
bool is_prime_vartime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition numthry.cpp:453
constexpr auto operator++(Strong< T, Tags... > &a, int)

References Botan::BigInt::_assign_from_bytes(), Botan::BigInt::bits(), Botan::HashFunction::create_or_throw(), fmt(), is_prime_vartime(), operator++(), Seed, and Botan::BigInt::set_bit().

Referenced by Botan::DL_Group::DL_Group(), Botan::DL_Group::DL_Group(), and generate_dsa_primes().

◆ generate_mceliece_key()

McEliece_PrivateKey Botan::generate_mceliece_key ( RandomNumberGenerator & rng,
size_t ext_deg,
size_t code_length,
size_t t )

Definition at line 186 of file code_based_key_gen.cpp.

186 {
187 const McEliece_Params params = mceliece_validate_keygen_params(code_length, t);
188
189 if(ext_deg != params.ext_deg) {
190 throw Invalid_Argument("inconsistent McEliece extension degree");
191 }
192
193 const size_t codimension = params.codimension;
194 const auto sp_field = std::make_shared<GF2m_Field>(params.ext_deg);
195
196 //pick the support.........
197 std::vector<gf2m> L(code_length);
198
199 for(size_t i = 0; i != L.size(); i++) {
200 L[i] = static_cast<gf2m>(i);
201 }
202 randomize_support(L, rng);
203 polyn_gf2m g(sp_field); // create as zero
204
205 bool success = false;
206 std::unique_ptr<binary_matrix> R;
207
208 // NOLINTNEXTLINE(*-avoid-do-while)
209 do {
210 // create a random irreducible polynomial
211 g = polyn_gf2m(t, rng, sp_field);
212
213 try {
214 R = generate_R(L, &g, *sp_field, code_length, t);
215 success = true;
216 } catch(const Invalid_State&) {}
217 } while(!success);
218
219 const std::vector<polyn_gf2m> sqrtmod = polyn_gf2m::sqrt_mod_init(g);
220 std::vector<polyn_gf2m> F = syndrome_init(g, L, static_cast<int>(code_length));
221
222 // Each F[i] is the (precomputed) syndrome of the error vector with
223 // a single '1' in i-th position.
224 // We do not store the F[i] as polynomials of degree t , but
225 // as binary vectors of length ext_deg * t (this will
226 // speed up the syndrome computation)
227 //
228 const size_t co32 = bit_size_to_32bit_size(codimension);
229 std::vector<uint32_t> H(co32 * code_length);
230 uint32_t* sk = H.data();
231 for(size_t i = 0; i < code_length; ++i) {
232 for(size_t l = 0; l < t; ++l) {
233 const size_t k = (l * ext_deg) / 32;
234 const size_t j = (l * ext_deg) % 32;
235 sk[k] ^= static_cast<uint32_t>(F[i].get_coef(l)) << j;
236 if(j + ext_deg > 32) {
237 if(j > 0) {
238 sk[k + 1] ^= F[i].get_coef(l) >> (32 - j);
239 }
240 }
241 }
242 sk += co32;
243 }
244
245 // We need the support L for decoding (decryption). In fact the
246 // inverse is needed
247
248 std::vector<gf2m> Linv(code_length);
249 for(size_t i = 0; i != Linv.size(); ++i) {
250 Linv[L[i]] = static_cast<gf2m>(i);
251 }
252 std::vector<uint8_t> pubmat(R->elem().size() * 4);
253 for(size_t i = 0; i < R->elem().size(); i++) {
254 store_le(R->elem()[i], &pubmat[i * 4]);
255 }
256
257 return McEliece_PrivateKey(g, H, sqrtmod, Linv, pubmat);
258}
static std::vector< polyn_gf2m > sqrt_mod_init(const polyn_gf2m &g)
std::vector< polyn_gf2m > syndrome_init(const polyn_gf2m &generator, const std::vector< gf2m > &support, int n)
size_t bit_size_to_32bit_size(size_t bit_size)
McEliece_Params mceliece_validate_keygen_params(size_t code_length, size_t t)

References bit_size_to_32bit_size(), Botan::McEliece_Params::codimension, Botan::McEliece_Params::ext_deg, generate_mceliece_key(), mceliece_validate_keygen_params(), Botan::polyn_gf2m::sqrt_mod_init(), store_le(), and syndrome_init().

Referenced by generate_mceliece_key(), and Botan::McEliece_PrivateKey::McEliece_PrivateKey().

◆ generate_passhash9()

std::string Botan::generate_passhash9 ( std::string_view password,
RandomNumberGenerator & rng,
uint16_t work_factor = 15,
uint8_t alg_id = 4 )

Create a password hash using PBKDF2

Functions much like generate_bcrypt(). The last parameter, alg_id, specifies which PRF to use. Currently defined values are:

  • 0: HMAC(SHA-1)
  • 1: HMAC(SHA-256)
  • 2: CMAC(Blowfish)
  • 3: HMAC(SHA-384)
  • 4: HMAC(SHA-512)

The work_factor must be greater than zero and less than 512. This performs 10000 * work_factor PBKDF2 iterations, using 96 bits of salt taken from rng. Using work factor of 10 or more is recommended.

Parameters
passwordthe password
Random Number Generatorsa random number generator
work_factorhow much work to do to slow down guessing attacks
alg_idspecifies which PRF to use with PBKDF2 0 is HMAC(SHA-1) 1 is HMAC(SHA-256) 2 is CMAC(Blowfish) 3 is HMAC(SHA-384) 4 is HMAC(SHA-512) all other values are currently undefined

Definition at line 47 of file passhash9.cpp.

50 {
51 BOTAN_ARG_CHECK(work_factor > 0 && work_factor < 512, "Invalid Passhash9 work factor");
52
53 auto prf = get_pbkdf_prf(alg_id);
54
55 if(!prf) {
56 throw Invalid_Argument("Passhash9: Algorithm id " + std::to_string(alg_id) + " is not defined");
57 }
58
59 const PKCS5_PBKDF2 kdf(std::move(prf));
60
61 secure_vector<uint8_t> salt(SALT_BYTES);
62 rng.randomize(salt.data(), salt.size());
63
64 const size_t kdf_iterations = WORK_FACTOR_SCALE * work_factor;
65
67 blob.push_back(alg_id);
68 blob.push_back(get_byte<0>(work_factor));
69 blob.push_back(get_byte<1>(work_factor));
70 blob += salt;
71 blob += kdf.derive_key(PASSHASH9_PBKDF_OUTPUT_LEN, pass, salt.data(), salt.size(), kdf_iterations).bits_of();
72
73 return std::string(MAGIC_PREFIX) + base64_encode(blob);
74}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References base64_encode(), Botan::OctetString::bits_of(), BOTAN_ARG_CHECK, Botan::PBKDF::derive_key(), get_byte(), and Botan::RandomNumberGenerator::randomize().

◆ generate_rfc6979_nonce()

BigInt Botan::generate_rfc6979_nonce ( const BigInt & x,
const BigInt & q,
const BigInt & h,
std::string_view hash )
inline
Parameters
xthe secret (EC)DSA key
qthe group order
hthe message hash already reduced mod q
Hashesthe hash function used to generate h

Definition at line 56 of file rfc6979.h.

56 {
57 RFC6979_Nonce_Generator gen(hash, q.bits(), x);
58 return gen.nonce_for(q, h);
59}
size_t bits() const
Definition bigint.cpp:308

References Botan::BigInt::bits(), and Botan::RFC6979_Nonce_Generator::nonce_for().

◆ generate_rsa_prime()

BigInt Botan::generate_rsa_prime ( RandomNumberGenerator & keygen_rng,
RandomNumberGenerator & prime_test_rng,
size_t bits,
const BigInt & coprime,
size_t prob = 128 )

Generate a prime suitable for RSA p/q

Parameters
keygen_rnga random number generator
prime_test_rnga random number generator
bitshow large the resulting prime should be in bits (must be >= 512)
coprimea positive integer that (prime - 1) should be coprime to
probuse test so false positive is bounded by 1/2**prob
Returns
random prime with the specified criteria

Definition at line 252 of file make_prm.cpp.

256 {
257 if(bits < 512) {
258 throw Invalid_Argument("generate_rsa_prime bits too small");
259 }
260
261 /*
262 * The restriction on coprime <= 64 bits is arbitrary but generally speaking
263 * very large RSA public exponents are a bad idea both for performance and due
264 * to attacks on small d.
265 */
266 if(coprime <= 1 || coprime.is_even() || coprime.bits() > 64) {
267 throw Invalid_Argument("generate_rsa_prime coprime must be small odd positive integer");
268 }
269
270 const size_t MAX_ATTEMPTS = 32 * 1024;
271
272 const size_t mr_trials = miller_rabin_test_iterations(bits, prob, true);
273
274 while(true) {
275 BigInt p(keygen_rng, bits);
276
277 const auto scope = CT::scoped_poison(p);
278
279 /*
280 Force high two bits so multiplication always results in expected n bit integer
281
282 Force the two low bits, and step by 4, so the generated prime is always == 3 (mod 4).
283 This way when we perform the inversion modulo phi(n) it is always of the form 2*o
284 with o odd, which allows a fastpath and avoids leaking any information about the
285 structure of the prime.
286 */
287 p.set_bit(bits - 1);
288 p.set_bit(bits - 2);
289 p.set_bit(1);
290 p.set_bit(0);
291
292 const word step = 4;
293
294 Prime_Sieve sieve(p, bits, step, false);
295
296 /*
297 * Which candidates pass the sieve and are then rejected is visible to a side
298 * channel, and their offsets from the final prime would reveal its residues
299 * modulo the sieve primes. After each rejection, skip ahead by a secret random
300 * multiple of the step so that these offsets are unknown.
301 */
302 const auto skip_ahead = [&]() {
303 // Always 64 bits so that the output does not depend on the word size
304 uint64_t r = load_le<uint64_t>(keygen_rng.random_array<8>());
305 CT::poison(r);
306 r *= step;
307 p += BigInt::from_u64(r);
308 sieve.add(r);
309 };
310
311 for(size_t attempt = 0; attempt <= MAX_ATTEMPTS; ++attempt) {
312 p += step;
313
314 if(!sieve.next()) {
315 continue;
316 }
317
318 BOTAN_DEBUG_ASSERT(no_small_multiples(p, sieve));
319
320 const Montgomery_Params monty_p(p);
321
322 /*
323 * Do a single primality test first before checking coprimality, since
324 * currently a single Miller-Rabin test is faster than computing gcd,
325 * and this eliminates almost all wasted gcd computations.
326 */
327 if(!is_miller_rabin_probable_prime(p, monty_p, prime_test_rng, 1)) {
328 skip_ahead();
329 continue;
330 }
331
332 /*
333 * Check if p - 1 and coprime are relatively prime.
334 */
335 if(gcd(p - 1, coprime) > 1) {
336 skip_ahead();
337 continue;
338 }
339
340 if(p.bits() > bits) {
341 break;
342 }
343
344 if(is_miller_rabin_probable_prime(p, monty_p, prime_test_rng, mr_trials)) {
345 return p;
346 }
347
348 skip_ahead();
349 }
350 }
351}
bool is_even() const
Definition bigint.h:481
static BigInt from_u64(uint64_t n)
Definition bigint.cpp:31
std::array< uint8_t, bytes > random_array()
Definition rng.h:290
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:56
BigInt gcd(const BigInt &a, const BigInt &b)
Definition numthry.cpp:220
size_t miller_rabin_test_iterations(size_t n_bits, size_t prob, bool random)
bool is_miller_rabin_probable_prime(const BigInt &n, const Montgomery_Params &monty_n, RandomNumberGenerator &rng, size_t test_iterations)

References Botan::BigInt::bits(), BOTAN_DEBUG_ASSERT, Botan::BigInt::from_u64(), gcd(), Botan::BigInt::is_even(), is_miller_rabin_probable_prime(), load_le(), miller_rabin_test_iterations(), Botan::CT::poison(), Botan::RandomNumberGenerator::random_array(), Botan::CT::scoped_poison(), and Botan::BigInt::set_bit().

Referenced by Botan::RSA_PrivateKey::RSA_PrivateKey().

◆ get_aead()

AEAD_Mode * Botan::get_aead ( std::string_view name,
Cipher_Dir direction )
inline

Get an AEAD mode by name (eg "AES-128/GCM" or "Serpent/EAX")

Parameters
nameAEAD name
directionCipher_Dir::Encryption or Cipher_Dir::Decryption

Definition at line 147 of file aead.h.

147 {
148 return AEAD_Mode::create(name, direction, "").release();
149}
static std::unique_ptr< AEAD_Mode > create(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
Definition aead.cpp:61

References Botan::AEAD_Mode::create(), get_aead(), and name.

Referenced by get_aead().

◆ get_byte()

◆ get_byte_var()

template<typename T>
uint8_t Botan::get_byte_var ( size_t byte_num,
T input )
inlineconstexpr

Byte extraction

Parameters
byte_numwhich byte to extract, 0 == highest byte
inputthe value to extract from
Returns
byte byte_num of input

Definition at line 69 of file loadstor.h.

69 {
70 return static_cast<uint8_t>(input >> (((~byte_num) & (sizeof(T) - 1)) << 3));
71}

Referenced by Botan::TLS::append_tls_length_value(), Botan::BigInt::binary_encode(), Botan::BigInt::byte_at(), copy_out_be(), copy_out_le(), Botan::CCM_Mode::encode_length(), and Botan::TLS::Certificate_Status::serialize().

◆ get_cipher() [1/3]

Keyed_Filter * Botan::get_cipher ( std::string_view algo_spec,
Cipher_Dir direction )
inline

Factory method for general symmetric cipher filters. No key will be set in the filter.

Parameters
algo_specthe name of the desired cipher
directiondetermines whether the filter will be an encrypting or decrypting filter
Returns
pointer to the encryption or decryption filter

Definition at line 238 of file filters.h.

238 {
239 auto c = Cipher_Mode::create_or_throw(algo_spec, direction);
240 // NOLINTNEXTLINE(*-owning-memory)
241 return new Cipher_Mode_Filter(c.release());
242}
static std::unique_ptr< Cipher_Mode > create_or_throw(std::string_view algo, Cipher_Dir direction, std::string_view provider="")

References Botan::Cipher_Mode::create_or_throw().

Referenced by get_cipher(), and get_cipher().

◆ get_cipher() [2/3]

Keyed_Filter * Botan::get_cipher ( std::string_view algo_spec,
const SymmetricKey & key,
Cipher_Dir direction )
inline

Factory method for general symmetric cipher filters.

Parameters
algo_specthe name of the desired cipher
keythe key to be used for encryption/decryption performed by the filter
directiondetermines whether the filter will be an encrypting or decrypting filter
Returns
pointer to the encryption or decryption filter

Definition at line 253 of file filters.h.

253 {
254 Keyed_Filter* cipher = get_cipher(algo_spec, direction);
255 cipher->set_key(key);
256 return cipher;
257}
virtual void set_key(const SymmetricKey &key)=0
Keyed_Filter * get_cipher(std::string_view algo_spec, Cipher_Dir direction)
Definition filters.h:238

References get_cipher(), and Botan::Keyed_Filter::set_key().

◆ get_cipher() [3/3]

Keyed_Filter * Botan::get_cipher ( std::string_view algo_spec,
const SymmetricKey & key,
const InitializationVector & iv,
Cipher_Dir direction )
inline

Factory method for general symmetric cipher filters.

Parameters
algo_specthe name of the desired cipher
keythe key to be used for encryption/decryption performed by the filter
ivthe initialization vector to be used
directiondetermines whether the filter will be an encrypting or decrypting filter
Returns
pointer to newly allocated encryption or decryption filter

Definition at line 269 of file filters.h.

272 {
273 Keyed_Filter* cipher = get_cipher(algo_spec, key, direction);
274 if(!iv.empty()) {
275 cipher->set_iv(iv);
276 }
277 return cipher;
278}
virtual void set_iv(const InitializationVector &iv)
Definition filters.h:137
bool empty() const
Definition symkey.h:40

References Botan::OctetString::empty(), get_cipher(), and Botan::Keyed_Filter::set_iv().

◆ get_cipher_mode()

Cipher_Mode * Botan::get_cipher_mode ( std::string_view algo_spec,
Cipher_Dir direction,
std::string_view provider = "" )
inline

Get a cipher mode by name (eg "AES-128/CBC" or "Serpent/XTS")

Parameters
algo_speccipher name
directionCipher_Dir::Encryption or Cipher_Dir::Decryption
providerprovider implementation to choose

Definition at line 295 of file cipher_mode.h.

295 {
296 return Cipher_Mode::create(algo_spec, direction, provider).release();
297}
static std::unique_ptr< Cipher_Mode > create(std::string_view algo, Cipher_Dir direction, std::string_view provider="")

References Botan::Cipher_Mode::create(), and get_cipher_mode().

Referenced by get_cipher_mode().

◆ get_files_recursive()

BOTAN_TEST_API std::vector< std::string > Botan::get_files_recursive ( std::string_view dir)

Definition at line 122 of file filesystem.cpp.

122 {
123 std::vector<std::string> files;
124
125#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
126 files = impl_readdir(dir);
127#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
128 files = impl_win32(dir);
129#else
130 BOTAN_UNUSED(dir);
131 throw No_Filesystem_Access();
132#endif
133
134 std::sort(files.begin(), files.end());
135
136 return files;
137}

References BOTAN_UNUSED.

◆ get_kdf()

KDF * Botan::get_kdf ( std::string_view algo_spec)
inline

Factory method for KDF (key derivation function)

Parameters
algo_specthe name of the KDF to create
Returns
pointer to newly allocated object of that type

Prefer KDF::create

Definition at line 278 of file kdf.h.

278 {
279 if(algo_spec == "Raw") {
280 return nullptr;
281 }
282
283 return KDF::create_or_throw(algo_spec).release();
284}
static std::unique_ptr< KDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition kdf.cpp:208

References Botan::KDF::create_or_throw(), and get_kdf().

Referenced by get_kdf().

◆ get_pbkdf()

PBKDF * Botan::get_pbkdf ( std::string_view algo_spec,
std::string_view provider = "" )
inline

Password based key derivation function factory method

Parameters
algo_specthe name of the desired PBKDF algorithm
providerthe provider to use
Returns
pointer to newly allocated object of that type

Definition at line 249 of file pbkdf.h.

249 {
250 return PBKDF::create_or_throw(algo_spec, provider).release();
251}
static std::unique_ptr< PBKDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition pbkdf.cpp:60

References Botan::PBKDF::create_or_throw(), and get_pbkdf().

Referenced by get_pbkdf().

◆ get_s2k()

PBKDF * Botan::get_s2k ( std::string_view algo_spec)
inline

Password based key derivation function factory method

Parameters
algo_specthe name of the desired PBKDF algorithm
Returns
pointer to newly allocated object of that type

Definition at line 258 of file pbkdf.h.

258 {
259 return PBKDF::create_or_throw(algo_spec).release();
260}

References Botan::PBKDF::create_or_throw(), and get_s2k().

Referenced by get_s2k().

◆ get_uint32()

template<WordType W>
uint32_t Botan::get_uint32 ( const W xw[],
size_t i )
constexpr

Definition at line 33 of file pcurves_solinas.h.

33 {
34 static_assert(WordInfo<W>::bits == 32 || WordInfo<W>::bits == 64);
35
36 if constexpr(WordInfo<W>::bits == 32) {
37 return xw[i];
38 } else {
39 return static_cast<uint32_t>(xw[i / 2] >> ((i % 2) * 32));
40 }
41}

◆ gf2p8affine() [1/2]

template<uint64_t A, uint8_t B>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX512_GFNI SIMD_16x32 Botan::gf2p8affine ( const SIMD_16x32 & x)

Definition at line 18 of file simd_avx512_gfni.h.

18 {
19 return SIMD_16x32(_mm512_gf2p8affine_epi64_epi8(x.raw(), _mm512_set1_epi64(A), B));
20}
__m512i BOTAN_FN_ISA_AVX512 raw() const

References BOTAN_FORCE_INLINE, and Botan::SIMD_16x32::raw().

◆ gf2p8affine() [2/2]

template<uint64_t A, uint8_t B>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX2_GFNI SIMD_8x32 Botan::gf2p8affine ( const SIMD_8x32 & x)

Definition at line 18 of file simd_avx2_gfni.h.

18 {
19 return SIMD_8x32(_mm256_gf2p8affine_epi64_epi8(x.raw(), _mm256_set1_epi64x(A), B));
20}
__m256i BOTAN_FN_ISA_SIMD_8X32 raw() const noexcept
Definition simd_8x32.h:390

References BOTAN_FORCE_INLINE, and Botan::SIMD_8x32::raw().

◆ gf2p8affineinv() [1/2]

template<uint64_t A, uint8_t B>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX512_GFNI SIMD_16x32 Botan::gf2p8affineinv ( const SIMD_16x32 & x)

Definition at line 23 of file simd_avx512_gfni.h.

23 {
24 return SIMD_16x32(_mm512_gf2p8affineinv_epi64_epi8(x.raw(), _mm512_set1_epi64(A), B));
25}

References BOTAN_FORCE_INLINE, and Botan::SIMD_16x32::raw().

◆ gf2p8affineinv() [2/2]

template<uint64_t A, uint8_t B>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX2_GFNI SIMD_8x32 Botan::gf2p8affineinv ( const SIMD_8x32 & x)

Definition at line 23 of file simd_avx2_gfni.h.

23 {
24 return SIMD_8x32(_mm256_gf2p8affineinv_epi64_epi8(x.raw(), _mm256_set1_epi64x(A), B));
25}

References BOTAN_FORCE_INLINE, and Botan::SIMD_8x32::raw().

◆ gf2p8mul()

BOTAN_FORCE_INLINE BOTAN_FN_ISA_AVX2_GFNI SIMD_8x32 Botan::gf2p8mul ( const SIMD_8x32 & a,
const SIMD_8x32 & b )

Definition at line 27 of file simd_avx2_gfni.h.

27 {
28 return SIMD_8x32(_mm256_gf2p8mul_epi8(a.raw(), b.raw()));
29}

References BOTAN_FORCE_INLINE, and Botan::SIMD_8x32::raw().

◆ gfni_matrix()

uint64_t Botan::gfni_matrix ( std::string_view s)
consteval

Definition at line 17 of file gfni_utils.h.

17 {
18 uint64_t matrix = 0;
19 size_t bit_cnt = 0;
20 uint8_t row = 0;
21
22 for(const char c : s) {
23 if(c == ' ' || c == '\n') {
24 continue;
25 }
26 if(c != '0' && c != '1') {
27 throw std::runtime_error("gfni_matrix: invalid bit value");
28 }
29
30 if(c == '1') {
31 row |= 0x80 >> (7 - bit_cnt % 8);
32 }
33 bit_cnt++;
34
35 if(bit_cnt % 8 == 0) {
36 matrix <<= 8;
37 matrix |= row;
38 row = 0;
39 }
40 }
41
42 if(bit_cnt != 64) {
43 throw std::runtime_error("gfni_matrix: invalid bit count");
44 }
45
46 return matrix;
47}

◆ gray_to_lex()

gf2m Botan::gray_to_lex ( gf2m gray)
inline

Definition at line 30 of file code_based_util.h.

30 {
31 gf2m result = gray ^ (gray >> 8);
32 result ^= (result >> 4);
33 result ^= (result >> 2);
34 result ^= (result >> 1);
35 return result;
36}

◆ h2c_expand_message()

std::function< void(std::span< uint8_t >)> Botan::h2c_expand_message ( std::string_view hash_fn,
size_t order_bits,
std::span< const uint8_t > input,
std::span< const uint8_t > domain_sep )

Instantiate the named hash and return a closure implementing the expand_message function of RFC 9380

Throws if the hash is unknown, or too weak for use with a group of order_bits, per the RFC 9380 requirements

Definition at line 464 of file ec_inner_data.cpp.

467 {
468 /*
469 * This could be extended to support expand_message_xof or a MHF like Argon2
470 */
471
472 if(hash_fn.starts_with("SHAKE")) {
473 throw Not_Implemented("Hash to curve currently does not support expand_message_xof");
474 }
475
476#if defined(BOTAN_HAS_XMD)
477 // Here we capture the HashFunction by shared_ptr because it will be owned by
478 // the returned std::function
479 const std::shared_ptr<HashFunction> hash = HashFunction::create_or_throw(hash_fn);
480
481 /*
482 * RFC 9380 Section 5.3.1: "The number of bits output by H MUST be b >= 2 * k,
483 * where k is the target security level in bits", as this "ensures k-bit
484 * collision resistance". Checking the hash's collision resistance estimate
485 * covers this, and also rejects hashes with known collision attacks. The
486 * target level is capped at 256 since the RFC 9380 suites for P-521 use k = 256.
487 */
488 const size_t k = std::min<size_t>((order_bits + 1) / 2, 256);
489
490 if(hash->security_level() < k) {
491 throw Invalid_Argument(fmt("Hash {} is too weak for use with a {} bit group", hash->name(), order_bits));
492 }
493
494 return [hash, input, domain_sep](std::span<uint8_t> uniform_bytes) {
495 expand_message_xmd(*hash, uniform_bytes, input, domain_sep);
496 };
497#else
498 BOTAN_UNUSED(order_bits, input, domain_sep);
499 throw Not_Implemented("Hash to curve is not implemented due to XMD being disabled");
500#endif
501}
void expand_message_xmd(HashFunction &hash, std::span< uint8_t > output, std::span< const uint8_t > input, std::span< const uint8_t > domain_sep)
Definition xmd.cpp:17

References BOTAN_UNUSED, Botan::HashFunction::create_or_throw(), expand_message_xmd(), and fmt().

Referenced by Botan::EC_Scalar::hash(), Botan::EC_Group_Data::point_hash_to_curve_nu(), and Botan::EC_Group_Data::point_hash_to_curve_ro().

◆ has_filesystem_impl()

BOTAN_TEST_API bool Botan::has_filesystem_impl ( )

Definition at line 112 of file filesystem.cpp.

112 {
113#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
114 return true;
115#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
116 return true;
117#else
118 return false;
119#endif
120}

◆ hash_to_curve_sswu()

template<typename C, bool RO, std::invocable< std::span< uint8_t > > ExpandMsg>
auto Botan::hash_to_curve_sswu ( const ExpandMsg & expand_message) -> std::conditional_t< RO, typename C::ProjectivePoint, typename C::AffinePoint >
inline

Hash to curve (SSWU); RFC 9380

This is the Simplified Shallue-van de Woestijne-Ulas (SSWU) map.

The parameter expand_message models the function of RFC 9380 and is provided by higher levels. For the curves implemented here it will typically be XMD, but could also be an XOF (expand_message_xof) or a MHF like Argon2.

For details see RFC 9380 sections 3, 5.2 and 6.6.2.

Definition at line 1912 of file pcurves_impl.h.

1913 {
1914 constexpr size_t SecurityLevel = (C::OrderBits + 1) / 2;
1915 constexpr size_t L = (C::PrimeFieldBits + SecurityLevel + 7) / 8;
1916 constexpr size_t Cnt = RO ? 2 : 1;
1917
1918 std::array<uint8_t, L * Cnt> uniform_bytes = {};
1919 expand_message(uniform_bytes);
1920
1921 if constexpr(RO) {
1922 const auto u0 = C::FieldElement::from_wide_bytes(std::span<const uint8_t, L>(uniform_bytes.data(), L));
1923 const auto u1 = C::FieldElement::from_wide_bytes(std::span<const uint8_t, L>(uniform_bytes.data() + L, L));
1924
1925 auto accum = C::ProjectivePoint::from_affine(map_to_curve_sswu<C>(u0));
1926 accum += map_to_curve_sswu<C>(u1);
1927 return accum;
1928 } else {
1929 const auto u = C::FieldElement::from_wide_bytes(std::span<const uint8_t, L>(uniform_bytes.data(), L));
1930 return map_to_curve_sswu<C>(u);
1931 }
1932}
auto map_to_curve_sswu(const typename C::FieldElement &u) -> typename C::AffinePoint

References map_to_curve_sswu().

Referenced by Botan::PCurve::PrimeOrderCurveImpl< C >::hash_to_curve_nu(), and Botan::PCurve::PrimeOrderCurveImpl< C >::hash_to_curve_ro().

◆ hex_decode() [1/6]

std::vector< uint8_t > Botan::hex_decode ( const char input[],
size_t input_length,
bool ignore_ws = true )

Perform hex decoding

Parameters
inputsome hex input
input_lengththe length of input in bytes
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
decoded hex output

Definition at line 155 of file hex.cpp.

155 {
156 std::vector<uint8_t> bin(1 + input_length / 2);
157
158 const size_t written = hex_decode(bin.data(), input, input_length, ignore_ws);
159
160 bin.resize(written);
161 return bin;
162}
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition hex.cpp:75

References hex_decode().

◆ hex_decode() [2/6]

size_t Botan::hex_decode ( std::span< uint8_t > output,
std::string_view input,
bool ignore_ws = true )

Perform hex decoding

Parameters
outputa contiguous byte buffer of at least input_length/2 bytes
inputsome hex input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 135 of file hex.cpp.

135 {
136 if(output.size() < input.length() / 2) {
137 throw Invalid_Argument("hex_decode: output buffer too small");
138 }
139 return hex_decode(output.data(), input.data(), input.length(), ignore_ws);
140}

References hex_decode().

◆ hex_decode() [3/6]

std::vector< uint8_t > Botan::hex_decode ( std::string_view input,
bool ignore_ws = true )

Perform hex decoding

Parameters
inputsome hex input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
decoded hex output

Definition at line 164 of file hex.cpp.

164 {
165 return hex_decode(input.data(), input.size(), ignore_ws);
166}

References hex_decode().

◆ hex_decode() [4/6]

size_t Botan::hex_decode ( uint8_t output[],
const char input[],
size_t input_length,
bool ignore_ws = true )

Perform hex decoding

Parameters
outputan array of at least input_length/2 bytes
inputsome hex input
input_lengthlength of input in bytes
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 120 of file hex.cpp.

120 {
121 size_t consumed = 0;
122 const size_t written = hex_decode(output, input, input_length, consumed, ignore_ws);
123
124 if(consumed != input_length) {
125 throw Invalid_Argument("hex_decode: input did not have full bytes");
126 }
127
128 return written;
129}

References hex_decode().

◆ hex_decode() [5/6]

size_t Botan::hex_decode ( uint8_t output[],
const char input[],
size_t input_length,
size_t & input_consumed,
bool ignore_ws = true )

Perform hex decoding

Parameters
outputan array of at least input_length/2 bytes
inputsome hex input
input_lengthlength of input in bytes
input_consumedis an output parameter which says how many bytes of input were actually consumed. If less than input_length, then the range input[consumed:length] should be passed in later along with more input.
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 75 of file hex.cpp.

75 {
76 uint8_t* out_ptr = output;
77 bool top_nibble = true;
78 uint8_t next = 0;
79
80 input_consumed = 0;
81
82 clear_mem(output, input_length / 2);
83
84 for(size_t i = 0; i != input_length; ++i) {
85 const uint8_t bin = hex_char_to_bin(input[i]);
86
87 if(bin >= 0x10) {
88 if(bin == 0x80 && ignore_ws) {
89 continue;
90 }
91
92 throw Invalid_Argument(fmt("hex_decode: invalid character '{}'", format_char_for_display(input[i])));
93 }
94
95 if(top_nibble) {
96 next = bin << 4;
97 } else {
98 next |= bin;
99 *out_ptr = next;
100 }
101
102 top_nibble = !top_nibble;
103 if(top_nibble) {
104 ++out_ptr;
105 input_consumed = i + 1;
106 }
107 }
108
109 /*
110 * Consume trailing whitespace following the last full byte; a leftover
111 * unpaired nibble (if any) stops the scan and is left unconsumed.
112 */
113 while(input_consumed < input_length && hex_char_to_bin(input[input_consumed]) == 0x80) {
114 ++input_consumed;
115 }
116
117 return (out_ptr - output);
118}
std::string format_char_for_display(char c)
Definition charset.cpp:243

References clear_mem(), fmt(), format_char_for_display(), and out_ptr().

Referenced by botan_hex_decode(), Botan::Hex_Decoder::end_msg(), Botan::TLS::Session_Manager_SQL::find_some(), Botan::TLS::Signature_Scheme::from_string(), hex_decode(), hex_decode(), hex_decode(), hex_decode(), hex_decode(), hex_decode_locked(), Botan::OctetString::OctetString(), Botan::UUID::UUID(), and Botan::Hex_Decoder::write().

◆ hex_decode() [6/6]

size_t Botan::hex_decode ( uint8_t output[],
std::string_view input,
bool ignore_ws = true )

Perform hex decoding

Parameters
outputan array of at least input_length/2 bytes
inputsome hex input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
number of bytes written to output

Definition at line 131 of file hex.cpp.

131 {
132 return hex_decode(output, input.data(), input.length(), ignore_ws);
133}

References hex_decode().

◆ hex_decode_locked() [1/2]

secure_vector< uint8_t > Botan::hex_decode_locked ( const char input[],
size_t input_length,
bool ignore_ws = true )

Perform hex decoding

Parameters
inputsome hex input
input_lengththe length of input in bytes
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
decoded hex output

Definition at line 142 of file hex.cpp.

142 {
143 secure_vector<uint8_t> bin(1 + input_length / 2);
144
145 const size_t written = hex_decode(bin.data(), input, input_length, ignore_ws);
146
147 bin.resize(written);
148 return bin;
149}

References hex_decode().

Referenced by Botan::BigInt::from_radix_digits(), hex_decode_locked(), and Botan::RTSS_Share::RTSS_Share().

◆ hex_decode_locked() [2/2]

secure_vector< uint8_t > Botan::hex_decode_locked ( std::string_view input,
bool ignore_ws = true )

Perform hex decoding

Parameters
inputsome hex input
ignore_wsignore whitespace on input; if false, throw an exception if whitespace is encountered
Returns
decoded hex output

Definition at line 151 of file hex.cpp.

151 {
152 return hex_decode_locked(input.data(), input.size(), ignore_ws);
153}
secure_vector< uint8_t > hex_decode_locked(const char input[], size_t input_length, bool ignore_ws)
Definition hex.cpp:142

References hex_decode_locked().

◆ hex_encode() [1/3]

void Botan::hex_encode ( char output[],
const uint8_t input[],
size_t input_length,
bool uppercase = true )

Perform hex encoding

Parameters
outputan array of at least input_length*2 bytes
inputis some binary data
input_lengthlength of input in bytes
uppercaseshould output be upper or lower case?

Definition at line 34 of file hex.cpp.

34 {
35 for(size_t i = 0; i != input_length; ++i) {
36 const uint16_t h = hex_encode_2nibble(input[i], uppercase);
37 output[2 * i] = get_byte<0>(h);
38 output[2 * i + 1] = get_byte<1>(h);
39 }
40}

References get_byte().

Referenced by botan_hex_encode(), format_hex_fingerprint(), hex_encode(), hex_encode(), Botan::TLS::Session_Manager_SQL::remove(), Botan::TLS::Session_Manager_SQL::retrieve_one(), Botan::TLS::Session_Manager_SQL::store(), Botan::BigInt::to_hex_string(), Botan::OctetString::to_string(), Botan::PK_Encryption_Options::to_string(), Botan::PK_Signature_Options::to_string(), Botan::RTSS_Share::to_string(), Botan::UUID::to_string(), Botan::X509_Certificate::to_string(), Botan::X509_Serial_Number::to_string(), and Botan::UUID::UUID().

◆ hex_encode() [2/3]

std::string Botan::hex_encode ( const uint8_t input[],
size_t input_length,
bool uppercase = true )

Perform hex encoding

Parameters
inputsome input
input_lengthlength of input in bytes
uppercaseshould output be upper or lower case?
Returns
hexadecimal representation of input

Definition at line 42 of file hex.cpp.

42 {
43 const size_t output_length = mul_or_throw<size_t>(2, input_length, "Input too large to hex encode");
44 std::string output(output_length, 0);
45
46 if(input_length > 0) {
47 hex_encode(&output.front(), input, input_length, uppercase);
48 }
49
50 return output;
51}
constexpr T mul_or_throw(T a, T b, std::string_view msg)
Definition int_utils.h:81

References hex_encode(), and mul_or_throw().

◆ hex_encode() [3/3]

std::string Botan::hex_encode ( std::span< const uint8_t > input,
bool uppercase = true )
inline

Perform hex encoding

Parameters
inputsome input
uppercaseshould output be upper or lower case?
Returns
hexadecimal representation of input

Definition at line 43 of file hex.h.

43 {
44 return hex_encode(input.data(), input.size(), uppercase);
45}

References hex_encode().

◆ hex_to_words()

template<WordType W, size_t N>
auto Botan::hex_to_words ( const char(&) s[N])
constexpr

Definition at line 921 of file mp_core.h.

921 {
922 // Char count includes null terminator which we ignore
923 const constexpr size_t C = N - 1;
924
925 // Number of nibbles that a word can hold
926 const constexpr size_t NPW = (WordInfo<W>::bits / 4);
927
928 // Round up to the next number of words that will fit the input
929 const constexpr size_t S = (C + NPW - 1) / NPW;
930
931 static_assert(S > 0, "Input too small");
932
933 const auto hex2int = [](char c) -> int8_t {
934 if(c >= '0' && c <= '9') {
935 return static_cast<int8_t>(c - '0');
936 } else if(c >= 'a' && c <= 'f') {
937 return static_cast<int8_t>(c - 'a' + 10);
938 } else if(c >= 'A' && c <= 'F') {
939 return static_cast<int8_t>(c - 'A' + 10);
940 } else {
941 return -1;
942 }
943 };
944
945 std::array<W, S> r = {0};
946
947 for(size_t i = 0; i != C; ++i) {
948 const int8_t c = hex2int(s[i]);
949 if(c >= 0) {
950 shift_left<4>(r);
951 r[0] += c;
952 }
953 }
954
955 return r;
956}

References shift_left().

Referenced by Botan::BLS12_381::Fp12::frobenius_map(), Botan::BLS12_381::Fp6::frobenius_map(), and Botan::BLS12_381::FieldElement2::sqrt().

◆ high_bit()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr size_t Botan::high_bit ( T n)
constexpr

Return the index of the highest set bit T is an unsigned integer type

Parameters
nan integer value
Returns
index of the highest set bit in n

Definition at line 73 of file bit_ops.h.

73 {
74 size_t hb = 0;
75
76 for(size_t s = 8 * sizeof(T) / 2; s > 0; s /= 2) {
77 // Equivalent to: ((n >> s) == 0) ? 0 : s;
78 const size_t z = s - ct_if_is_zero_ret<T>(n >> s, s);
79 hb += z;
80 n >>= z;
81 }
82
83 hb += static_cast<size_t>(n);
84
85 return hb;
86}

References BOTAN_FORCE_INLINE, and ct_if_is_zero_ret().

Referenced by Botan::OID::encode_into(), floor_log2(), random_prime(), Botan::divide_precomp< W >::setup(), Botan::divide_precomp< W >::setup_vartime(), and Botan::BigInt::top_bits_free().

◆ hkdf_expand_label()

secure_vector< uint8_t > BOTAN_TEST_API Botan::hkdf_expand_label ( std::string_view hash_fn,
std::span< const uint8_t > secret,
std::string_view label,
std::span< const uint8_t > hash_val,
size_t length )

HKDF-Expand-Label from TLS 1.3/QUIC

Parameters
hash_fnthe hash to use
secretthe secret bits
labelthe full label (no "TLS 1.3, " or "tls13 " prefix is applied)
hash_valthe previous hash value (used for chaining, may be empty)
lengththe desired output length

Definition at line 119 of file hkdf.cpp.

123 {
124 BOTAN_ARG_CHECK(length <= 0xFFFF, "HKDF-Expand-Label requested output too large");
125 BOTAN_ARG_CHECK(label.size() <= 0xFF, "HKDF-Expand-Label label too long");
126 BOTAN_ARG_CHECK(hash_val.size() <= 0xFF, "HKDF-Expand-Label hash too long");
127
128 const HKDF_Expand hkdf(MessageAuthenticationCode::create_or_throw(fmt("HMAC({})", hash_fn)));
129
130 const auto prefix = concat<std::vector<uint8_t>>(store_be(static_cast<uint16_t>(length)),
131 store_be(static_cast<uint8_t>(label.size())),
132 as_span_of_bytes(label),
133 store_be(static_cast<uint8_t>(hash_val.size())));
134
135 /*
136 * We do something a little dirty here to avoid copying the hash_val,
137 * making use of the fact that Botan's KDF interface supports label+salt,
138 * and knowing that our HKDF hashes first param label then param salt.
139 */
140 return hkdf.derive_key(length, secret, hash_val, prefix);
141}
static std::unique_ptr< MessageAuthenticationCode > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition mac.cpp:142
constexpr auto concat(Rs &&... ranges)
Definition concat_util.h:95

References as_span_of_bytes(), BOTAN_ARG_CHECK, concat(), Botan::MessageAuthenticationCode::create_or_throw(), Botan::KDF::derive_key(), fmt(), and store_be().

◆ holds_any_of()

template<typename... Alts, typename... Ts>
bool Botan::holds_any_of ( const std::variant< Ts... > & v)
constexprnoexcept

Definition at line 66 of file stl_util.h.

66 {
67 return (std::holds_alternative<Alts>(v) || ...);
68}

Referenced by Botan::TLS::Channel_IO::next_pending_handshake_message().

◆ ht_sign()

void Botan::ht_sign ( StrongSpan< SphincsHypertreeSignature > out_sig,
const SphincsTreeNode & message_to_sign,
const SphincsSecretSeed & secret_seed,
XmssTreeIndexInLayer tree_index_in_layer,
TreeNodeIndex idx_leaf,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hashes )

FIPS 205, Algorithm 12: ht_sign.

Creates a SLH-DSA XMSS hypertree signature of message_to_sign. The signature is written into the buffer defined by out_sig. tree_index_in_layer and idx_leaf define which XMSS tree of the hypertree and which leaf of this XMSS tree is used for signing.

Definition at line 22 of file sp_hypertree.cpp.

28 {
29 BOTAN_ASSERT_NOMSG(out_sig.size() == params.ht_signature_bytes());
30 BufferStuffer ht_signature(out_sig);
31
33 wots_addr.set_tree_address(tree_index_in_layer).set_keypair_address(idx_leaf);
34
36
37 SphincsTreeNode xmss_root;
38 for(HypertreeLayerIndex layer_idx(0); layer_idx < params.d(); layer_idx++) {
39 // The first XMSS tree signs the message, the others their underlying XMSS tree root
40 const SphincsTreeNode& node_to_xmss_sign = (layer_idx == 0U) ? message_to_sign : xmss_root;
41
42 tree_addr.set_layer_address(layer_idx).set_tree_address(tree_index_in_layer);
43 wots_addr.copy_subtree_from(tree_addr).set_keypair_address(idx_leaf);
44
45 xmss_root = xmss_sign_and_pkgen(ht_signature.next<SphincsXmssSignature>(params.xmss_signature_bytes()),
46 node_to_xmss_sign,
47 secret_seed,
48 wots_addr,
49 tree_addr,
50 idx_leaf,
51 params,
52 hashes);
53
54 // Update the indices for the next layer.
55 idx_leaf = TreeNodeIndex(tree_index_in_layer.get() & ((1 << params.xmss_tree_height()) - 1));
56 tree_index_in_layer = tree_index_in_layer >> params.xmss_tree_height();
57 }
58
59 BOTAN_ASSERT_NOMSG(ht_signature.full());
60}
uint32_t xmss_tree_height() const
uint32_t ht_signature_bytes() const
uint32_t xmss_signature_bytes() const
Strong< std::vector< uint8_t >, struct SphincsXmssSignature_ > SphincsXmssSignature
Definition sp_types.h:65
SphincsTreeNode xmss_sign_and_pkgen(StrongSpan< SphincsXmssSignature > out_sig, const SphincsTreeNode &message, const SphincsSecretSeed &secret_seed, const Sphincs_Address &wots_addr, Sphincs_Address &tree_addr, std::optional< TreeNodeIndex > idx_leaf, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
FIPS 205, Algorithm 10: xmss_sign.
Definition sp_xmss.cpp:19
Strong< uint32_t, struct HypertreeLayerIndex_ > HypertreeLayerIndex
Index of a layer in the XMSS hyper-tree.
Definition sp_types.h:86

References BOTAN_ASSERT_NOMSG, Botan::Sphincs_Address::copy_subtree_from(), Botan::Sphincs_Parameters::d(), Botan::BufferStuffer::full(), Botan::detail::Strong_Base< T >::get(), HashTree, Botan::Sphincs_Parameters::ht_signature_bytes(), Botan::BufferStuffer::next(), Botan::Sphincs_Address::set_keypair_address(), Botan::Sphincs_Address::set_layer_address(), Botan::Sphincs_Address::set_tree_address(), Botan::StrongSpan< T >::size(), WotsHash, xmss_sign_and_pkgen(), Botan::Sphincs_Parameters::xmss_signature_bytes(), and Botan::Sphincs_Parameters::xmss_tree_height().

◆ ht_verify()

bool Botan::ht_verify ( const SphincsTreeNode & signed_msg,
StrongSpan< const SphincsHypertreeSignature > ht_sig,
const SphincsTreeNode & pk_root,
XmssTreeIndexInLayer tree_index_in_layer,
TreeNodeIndex idx_leaf,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hashes )

FIPS 205, Algorithm 13: ht_verify.

Given a message signed_msg the SLH-DSA XMSS hypertree is reconstructed using a hypertree signature ht_sig. tree_index_in_layer and idx_leaf define which XMSS tree of the hypertree and which leaf of this XMSS tree was used for signing.

Returns
true iff the top-most reconstructed root equals pk_root

Definition at line 62 of file sp_hypertree.cpp.

68 {
69 BOTAN_ASSERT_NOMSG(ht_sig.size() == params.ht_signature_bytes());
70 BufferSlicer sig_s(ht_sig);
71
75
76 SphincsTreeNode reconstructed_root(params.n());
77
78 // Each iteration reconstructs the root of one XMSS tree of the hypertree
79 for(HypertreeLayerIndex layer_idx(0); layer_idx < params.d(); layer_idx++) {
80 // The first XMSS tree signs the message, the others their underlying XMSS tree root
81 const SphincsTreeNode& current_root = (layer_idx == 0U) ? signed_msg : reconstructed_root;
82
83 tree_addr.set_layer_address(layer_idx);
84 tree_addr.set_tree_address(tree_index_in_layer);
85
86 wots_addr.copy_subtree_from(tree_addr);
87 wots_addr.set_keypair_address(idx_leaf);
88
89 wots_pk_addr.copy_keypair_from(wots_addr);
90
91 const auto wots_pk = wots_public_key_from_signature(
92 current_root, sig_s.take<WotsSignature>(params.wots_bytes()), wots_addr, params, hashes);
93
94 // Compute the leaf node using the WOTS public key.
95 const auto leaf = hashes.T<SphincsTreeNode>(wots_pk_addr, wots_pk);
96
97 // Compute the root node of this subtree.
98 compute_root(StrongSpan<SphincsTreeNode>(reconstructed_root),
99 params,
100 hashes,
101 leaf,
102 idx_leaf,
103 0,
104 sig_s.take<SphincsAuthenticationPath>(params.xmss_tree_height() * params.n()),
105 params.xmss_tree_height(),
106 tree_addr);
107
108 // Update the indices for the next layer.
109 idx_leaf = TreeNodeIndex(tree_index_in_layer.get() & ((1 << params.xmss_tree_height()) - 1));
110 tree_index_in_layer = tree_index_in_layer >> params.xmss_tree_height();
111 }
112
113 BOTAN_ASSERT_NOMSG(sig_s.empty());
114
115 // Check if the root node equals the root node in the public key.
116 return reconstructed_root == pk_root;
117}
uint32_t wots_bytes() const
Strong< secure_vector< uint8_t >, struct WotsSignature_ > WotsSignature
Definition sp_types.h:80
WotsPublicKey wots_public_key_from_signature(const SphincsTreeNode &hashed_message, StrongSpan< const WotsSignature > signature, const Sphincs_Address &address, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
FIPS 205, Algorithm 8: wots_pkFromSig.
Definition sp_wots.cpp:81

References BOTAN_ASSERT_NOMSG, compute_root(), Botan::Sphincs_Address::copy_keypair_from(), Botan::Sphincs_Address::copy_subtree_from(), Botan::Sphincs_Parameters::d(), Botan::BufferSlicer::empty(), Botan::detail::Strong_Base< T >::get(), HashTree, Botan::Sphincs_Parameters::ht_signature_bytes(), Botan::Sphincs_Parameters::n(), Botan::Sphincs_Address::set_keypair_address(), Botan::Sphincs_Address::set_layer_address(), Botan::Sphincs_Address::set_tree_address(), Botan::StrongSpan< T >::size(), Botan::Sphincs_Hash_Functions::T(), Botan::BufferSlicer::take(), Botan::Sphincs_Parameters::wots_bytes(), wots_public_key_from_signature(), WotsHash, WotsPublicKeyCompression, and Botan::Sphincs_Parameters::xmss_tree_height().

◆ hw_aes_dec_last_round()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_dec_last_round ( SIMD_4x32 B,
SIMD_4x32 K )
inline

The final decryption round, which omits InvMixColumns

Definition at line 214 of file simd_hwaes.h.

214 {
215#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
216 return SIMD_4x32(_mm_aesdeclast_si128(B.raw(), K.raw()));
217#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
218 return SIMD_4x32(vreinterpretq_u32_u8(vaesdq_u8(vreinterpretq_u8_u32(B.raw()), vreinterpretq_u8_u32(K.raw()))));
219#elif defined(BOTAN_TARGET_ARCH_IS_PPC64)
220 return detail::hw_aes_simd(__builtin_crypto_vncipherlast(detail::hw_aes_vec(B), detail::hw_aes_vec(K)));
221#else
222 #error "hw_aes_dec_last_round not implemented for this architecture"
223#endif
224}

References Botan::SIMD_4x32::raw().

◆ hw_aes_dec_round()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_dec_round ( SIMD_4x32 B,
SIMD_4x32 K )
inline

One decryption round, taking a round key prepared by hw_aes_dec_round_key

Definition at line 198 of file simd_hwaes.h.

198 {
199#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
200 return SIMD_4x32(_mm_aesdec_si128(B.raw(), K.raw()));
201#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
202 return SIMD_4x32(
203 vreinterpretq_u32_u8(vaesimcq_u8(vaesdq_u8(vreinterpretq_u8_u32(B.raw()), vreinterpretq_u8_u32(K.raw())))));
204#elif defined(BOTAN_TARGET_ARCH_IS_PPC64)
205 return detail::hw_aes_simd(__builtin_crypto_vncipher(detail::hw_aes_vec(B), detail::hw_aes_vec(K)));
206#else
207 #error "hw_aes_dec_round not implemented for this architecture"
208#endif
209}

References Botan::SIMD_4x32::raw().

◆ hw_aes_dec_round_key()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_dec_round_key ( SIMD_4x32 K)
inline

Convert an inner encryption round key to the form hw_aes_dec_round takes

x86 and ARMv8 implement the equivalent inverse cipher, which needs InvMixColumns applied to the inner round keys. POWER's vncipher implements the standard inverse cipher and takes the encryption round keys unchanged.

Definition at line 233 of file simd_hwaes.h.

233 {
234#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
235 return SIMD_4x32(_mm_aesimc_si128(K.raw()));
236#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
237 return SIMD_4x32(vreinterpretq_u32_u8(vaesimcq_u8(vreinterpretq_u8_u32(K.raw()))));
238#elif defined(BOTAN_TARGET_ARCH_IS_PPC64)
239 return K;
240#else
241 #error "hw_aes_dec_round_key not implemented for this architecture"
242#endif
243}

References Botan::SIMD_4x32::raw().

◆ hw_aes_enc_last_round()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_enc_last_round ( SIMD_4x32 B,
SIMD_4x32 K )
inline

The final encryption round, which omits MixColumns

Definition at line 183 of file simd_hwaes.h.

183 {
184#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
185 return SIMD_4x32(_mm_aesenclast_si128(B.raw(), K.raw()));
186#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
187 return SIMD_4x32(vreinterpretq_u32_u8(vaeseq_u8(vreinterpretq_u8_u32(B.raw()), vreinterpretq_u8_u32(K.raw()))));
188#elif defined(BOTAN_TARGET_ARCH_IS_PPC64)
189 return detail::hw_aes_simd(__builtin_crypto_vcipherlast(detail::hw_aes_vec(B), detail::hw_aes_vec(K)));
190#else
191 #error "hw_aes_enc_last_round not implemented for this architecture"
192#endif
193}

References Botan::SIMD_4x32::raw().

◆ hw_aes_enc_round()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_enc_round ( SIMD_4x32 B,
SIMD_4x32 K )
inline

One encryption round, adding the round key where HwAesKeyFirst says

Definition at line 167 of file simd_hwaes.h.

167 {
168#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
169 return SIMD_4x32(_mm_aesenc_si128(B.raw(), K.raw()));
170#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
171 return SIMD_4x32(
172 vreinterpretq_u32_u8(vaesmcq_u8(vaeseq_u8(vreinterpretq_u8_u32(B.raw()), vreinterpretq_u8_u32(K.raw())))));
173#elif defined(BOTAN_TARGET_ARCH_IS_PPC64)
174 return detail::hw_aes_simd(__builtin_crypto_vcipher(detail::hw_aes_vec(B), detail::hw_aes_vec(K)));
175#else
176 #error "hw_aes_enc_round not implemented for this architecture"
177#endif
178}

References Botan::SIMD_4x32::raw().

◆ hw_aes_inv_sbox()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_inv_sbox ( SIMD_4x32 x)
inline

Apply the AES inverse S-box to each byte of the input vector.

Definition at line 83 of file simd_hwaes.h.

83 {
84#if defined(BOTAN_TARGET_ARCH_IS_PPC64)
85 /*
86 * Undo the InvShiftRows with a byte shuffle implementing ShiftRows. POWER
87 * numbers the AES state bytes starting from the most significant byte of the
88 * register, so the indices differ from x86/ARM and depend on endianness.
89 */
90 const auto sr = (std::endian::native == std::endian::little)
91 ? SIMD_4x32(0x030E0904, 0x07020D08, 0x0B06010C, 0x0F0A0500)
92 : SIMD_4x32(0x0306090C, 0x070A0D00, 0x0B0E0104, 0x0F020508);
93#else
94 // Undo the InvShiftRows with a byte shuffle implementing ShiftRows
95 const auto sr = SIMD_4x32(0x0F0A0500, 0x030E0904, 0x07020D08, 0x0B06010C);
96#endif
97
98#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
99 const auto dec = SIMD_4x32(_mm_aesdeclast_si128(x.raw(), _mm_setzero_si128()));
100#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
101 const auto dec = SIMD_4x32(vreinterpretq_u32_u8(vaesdq_u8(vreinterpretq_u8_u32(x.raw()), vdupq_n_u8(0))));
102#elif defined(BOTAN_TARGET_ARCH_IS_PPC64)
103 const auto dec =
104 detail::hw_aes_simd(__builtin_crypto_vncipherlast(detail::hw_aes_vec(x), detail::hw_aes_vec(SIMD_4x32())));
105#else
106 #error "hw_aes_inv_sbox not implemented for this architecture"
107#endif
108
109 return SIMD_4x32::byte_shuffle(dec, sr);
110}
static SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 byte_shuffle(const SIMD_4x32 &tbl, const SIMD_4x32 &idx)
Definition simd_4x32.h:796

References Botan::SIMD_4x32::byte_shuffle(), and Botan::SIMD_4x32::raw().

◆ hw_aes_load_block()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_load_block ( const uint8_t in[16])
inline

Load a block in the byte order the AES round instructions operate on

Definition at line 145 of file simd_hwaes.h.

145 {
146#if defined(BOTAN_TARGET_ARCH_IS_PPC64)
147 return SIMD_4x32(reinterpret_cast<__vector unsigned int>(detail::hw_aes_state_order(vec_xl(0, in))));
148#else
149 return SIMD_4x32::load_le(in);
150#endif
151}
static SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 load_le(const void *in) noexcept
Definition simd_4x32.h:183

References Botan::SIMD_4x32::load_le().

◆ hw_aes_sbox()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_sbox ( SIMD_4x32 x)
inline

Apply the AES S-box to each byte of the input vector.

Definition at line 60 of file simd_hwaes.h.

60 {
61#if defined(BOTAN_TARGET_ARCH_IS_PPC64)
62 // vsbox is SubBytes alone so no shuffle is required
63 return detail::hw_aes_simd(__builtin_crypto_vsbox(detail::hw_aes_vec(x)));
64#else
65 // Undo the ShiftRows with a byte shuffle implementing InvShiftRows
66 const auto inv_sr = SIMD_4x32(0x070A0D00, 0x0B0E0104, 0x0F020508, 0x0306090C);
67
68 #if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
69 const auto enc = SIMD_4x32(_mm_aesenclast_si128(x.raw(), _mm_setzero_si128()));
70 #elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
71 const auto enc = SIMD_4x32(vreinterpretq_u32_u8(vaeseq_u8(vreinterpretq_u8_u32(x.raw()), vdupq_n_u8(0))));
72 #else
73 #error "hw_aes_sbox not implemented for this architecture"
74 #endif
75
76 return SIMD_4x32::byte_shuffle(enc, inv_sr);
77#endif
78}

References Botan::SIMD_4x32::byte_shuffle(), and Botan::SIMD_4x32::raw().

◆ hw_aes_sbox_splat()

SIMD_4x32 BOTAN_FN_ISA_HWAES Botan::hw_aes_sbox_splat ( SIMD_4x32 x,
SIMD_4x32 k )
inline

Compute SubBytes(x) ^ k for a vector x whose four 32-bit words are all equal

ShiftRows is the identity on such a vector, so this is exactly what the final round instruction computes. The AES key schedule uses it to apply SubWord to a broadcast word, with k carrying the round constant.

Definition at line 119 of file simd_hwaes.h.

119 {
120#if defined(BOTAN_TARGET_ARCH_IS_X86_FAMILY)
121 return SIMD_4x32(_mm_aesenclast_si128(x.raw(), k.raw()));
122#elif defined(BOTAN_TARGET_ARCH_IS_ARM64)
123 // AESE adds its key before SubBytes so k is added afterwards instead
124 return SIMD_4x32(vreinterpretq_u32_u8(vaeseq_u8(vreinterpretq_u8_u32(x.raw()), vdupq_n_u8(0)))) ^ k;
125#elif defined(BOTAN_TARGET_ARCH_IS_PPC64)
126 return detail::hw_aes_simd(__builtin_crypto_vcipherlast(detail::hw_aes_vec(x), detail::hw_aes_vec(k)));
127#else
128 #error "hw_aes_sbox_splat not implemented for this architecture"
129#endif
130}

References Botan::SIMD_4x32::raw().

◆ hw_aes_store_block()

void BOTAN_FN_ISA_HWAES Botan::hw_aes_store_block ( SIMD_4x32 B,
uint8_t out[16] )
inline

Store a block produced by the AES round instructions

Definition at line 156 of file simd_hwaes.h.

156 {
157#if defined(BOTAN_TARGET_ARCH_IS_PPC64)
158 vec_xst(detail::hw_aes_state_order(reinterpret_cast<__vector unsigned char>(B.raw())), 0, out);
159#else
160 B.store_le(out);
161#endif
162}
void BOTAN_FN_ISA_SIMD_4X32 store_le(uint32_t out[4]) const noexcept
Definition simd_4x32.h:210

References Botan::SIMD_4x32::raw(), and Botan::SIMD_4x32::store_le().

◆ ieee1363_hash_id()

uint8_t Botan::ieee1363_hash_id ( std::string_view hash_name)

Return the IEEE 1363 hash identifier

Parameters
hash_namethe name of the hash function
Returns
uint8_t code identifying the hash, or 0 if not known

Definition at line 144 of file hash_id.cpp.

144 {
145 if(name == "SHA-1") {
146 return 0x33;
147 }
148
149 if(name == "SHA-224") {
150 return 0x38;
151 }
152 if(name == "SHA-256") {
153 return 0x34;
154 }
155 if(name == "SHA-384") {
156 return 0x36;
157 }
158 if(name == "SHA-512") {
159 return 0x35;
160 }
161
162 if(name == "RIPEMD-160") {
163 return 0x31;
164 }
165
166 if(name == "Whirlpool") {
167 return 0x37;
168 }
169
170 return 0;
171}

References name.

Referenced by Botan::X931_SignaturePadding::X931_SignaturePadding().

◆ if_work_factor()

size_t BOTAN_TEST_API Botan::if_work_factor ( size_t n_bits)

Estimate work factor for integer factorization

Parameters
n_bitssize of modulus in bits
Returns
estimated security level for this modulus

Definition at line 37 of file workfactor.cpp.

37 {
38 if(bits < 512) {
39 return 0;
40 }
41
42 // RFC 3766 estimates k at .02 and o(1) to be effectively zero for sizes of interest
43
44 const double log2_k = -5.6438; // log2(.02)
45 return nfs_workfactor(bits, log2_k);
46}

Referenced by dl_work_factor(), Botan::RSA_PublicKey::estimated_strength(), and Botan::TPM_PrivateKey::estimated_strength().

◆ ignore_params()

template<typename... T>
void Botan::ignore_params ( const T &... args)
constexpr

Mark variable as unused.

Takes any number of arguments and marks all as unused, for instance BOTAN_UNUSED(a); or BOTAN_UNUSED(x, y, z);

Definition at line 149 of file assert.h.

149{}

References ignore_params().

Referenced by ignore_params().

◆ index_of_first_set_byte()

template<std::unsigned_integral T>
size_t Botan::index_of_first_set_byte ( T v)
constexpr

Return the index of the first byte with the high bit set

Definition at line 160 of file int_utils.h.

160 {
161 // The constant 0x010101... as a T
162 constexpr T lo1 = (static_cast<T>(-1) / 255);
163 // The constant 0x808080... as a T
164 constexpr T hi1 = lo1 << 7;
165 // How many bits to shift in order to get the top byte
166 constexpr size_t bits = (sizeof(T) * 8) - 8;
167
168 return static_cast<size_t>((((((v & hi1) - 1) & lo1) * lo1) >> bits) - 1);
169}

◆ initialize_allocator()

void BOTAN_UNSTABLE_API Botan::initialize_allocator ( )

Ensure the allocator is initialized

Definition at line 66 of file allocator.cpp.

66 {
67#if defined(BOTAN_HAS_LOCKING_ALLOCATOR)
69#endif
70}

References Botan::mlock_allocator::instance().

Referenced by Botan::Allocator_Initializer::Allocator_Initializer().

◆ intersects()

bool Botan::intersects ( ASN1_Class x,
ASN1_Class y )
inline

Return true if the two class tags have any bits in common

Definition at line 77 of file asn1_obj.h.

77 {
78 return (static_cast<uint32_t>(x) & static_cast<uint32_t>(y)) != 0;
79}

◆ inverse_mod()

BigInt Botan::inverse_mod ( const BigInt & x,
const BigInt & modulus )

Modular inversion. This algorithm is const time with respect to x, as long as x is less than modulus. It also avoids leaking information about the modulus, except that it does leak which of 3 categories the modulus is in: an odd integer, a power of 2, or some other even number, and if the modulus is even, leaks the power of 2 which divides the modulus.

Parameters
xa positive integer
modulusa positive integer
Returns
y st (x*y) % modulus == 1 or 0 if no such value

Definition at line 382 of file mod_inv.cpp.

382 {
383 BOTAN_ARG_CHECK(mod.signum() > 0, "Modulus must be positive");
384 BOTAN_ARG_CHECK(n.signum() >= 0, "Value cannot be negative");
385
386 if(n.is_zero() || (n.is_even() && mod.is_even())) {
387 return BigInt::zero();
388 }
389
390 if(n >= mod) {
391 return inverse_mod(ct_modulo(n, mod), mod);
392 }
393
394 return inverse_mod_general(n, mod).value_or(BigInt::zero());
395}
static BigInt zero()
Definition bigint.h:50
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition mod_inv.cpp:382

References BOTAN_ARG_CHECK, ct_modulo(), inverse_mod(), inverse_mod_general(), Botan::BigInt::is_even(), Botan::BigInt::is_zero(), Botan::BigInt::signum(), and Botan::BigInt::zero().

Referenced by inverse_mod().

◆ inverse_mod_general()

std::optional< BigInt > BOTAN_TEST_API Botan::inverse_mod_general ( const BigInt & x,
const BigInt & m )

Compute the inverse of x modulo some integer m

Returns nullopt if no such integer exists eg if gcd(x, m) > 1

This algorithm is const time with respect to x, aside from its length. It also avoids leaking information about the modulus m, except that it does leak which of 3 categories the modulus is in:

  • An odd integer
  • A power of 2
  • Some even number not a power of 2

And if the modulus is even, it leaks the power of 2 which divides the modulus.

Parameters
xa positive integer less than m
ma positive integer

Throws Invalid_Argument if x or m are negative

Definition at line 175 of file mod_inv.cpp.

175 {
176 BOTAN_ARG_CHECK(x > 0, "x must be greater than zero");
177 BOTAN_ARG_CHECK(mod > 0, "mod must be greater than zero");
178 BOTAN_ARG_CHECK(x < mod, "x must be less than m");
179
180 // Easy case where gcd > 1 so no inverse exists
181 if(x.is_even() && mod.is_even()) {
182 return std::nullopt;
183 }
184
185 if(mod.is_odd()) {
186 BigInt z = inverse_mod_odd_modulus(x, mod);
187 if(z.is_zero()) {
188 return std::nullopt;
189 } else {
190 return z;
191 }
192 }
193
194 // If x is even and mod is even we already returned 0
195 // If x is even and mod is odd we jumped directly to odd-modulus algo
197
198 const size_t mod_lz = low_zero_bits(mod);
199 BOTAN_ASSERT_NOMSG(mod_lz > 0);
200 const size_t mod_bits = mod.bits();
201 BOTAN_ASSERT_NOMSG(mod_bits > mod_lz);
202
203 if(mod_lz == mod_bits - 1) {
204 // In this case we are performing an inversion modulo 2^k
205 auto z = inverse_mod_pow2(x, mod_lz);
206 if(z.is_zero()) {
207 return std::nullopt;
208 } else {
209 return z;
210 }
211 }
212
213 if(mod_lz == 1) {
214 /*
215 Inversion modulo 2*o is an easier special case of CRT
216
217 This is exactly the main CRT flow below but taking advantage of
218 the fact that any odd number ^-1 modulo 2 is 1. As a result both
219 inv_2k and c can be taken to be 1, m2k is 2, and h is always
220 either 0 or 1, and its value depends only on the low bit of inv_o.
221
222 This is worth special casing because we generate RSA primes such
223 that phi(n) is of this form. However this only works for keys
224 that we generated in this way; pre-existing keys will typically
225 fall back to the general algorithm below.
226 */
227
228 const BigInt o = mod >> 1;
229 const BigInt inv_o = inverse_mod_odd_modulus(ct_modulo(x, o), o);
230
231 // No modular inverse in this case:
232 if(inv_o == 0) {
233 return std::nullopt;
234 }
235
236 BigInt h = inv_o;
237 h.ct_cond_add(!inv_o.get_bit(0), o);
238 return h;
239 }
240
241 /*
242 * In this case we are performing an inversion modulo 2^k*o for
243 * some k >= 2 and some odd (not necessarily prime) integer.
244 * Compute the inversions modulo 2^k and modulo o, then combine them
245 * using CRT, which is possible because 2^k and o are relatively prime.
246 */
247
248 const BigInt o = mod >> mod_lz;
249 const BigInt inv_o = inverse_mod_odd_modulus(ct_modulo(x, o), o);
250 const BigInt inv_2k = inverse_mod_pow2(x, mod_lz);
251
252 // No modular inverse in this case:
253 if(inv_o == 0 || inv_2k == 0) {
254 return std::nullopt;
255 }
256
257 const BigInt m2k = BigInt::power_of_2(mod_lz);
258 // Compute the CRT parameter
259 const BigInt c = inverse_mod_pow2(o, mod_lz);
260
261 // This should never happen; o is odd so gcd is 1 and inverse mod 2^k exists
262 BOTAN_ASSERT_NOMSG(c.signum() != 0);
263
264 // Compute h = c*(inv_2k-inv_o) mod 2^k
265 BigInt h = c * (inv_2k - inv_o);
266 const bool h_neg = h.signum() < 0;
267 h.set_sign(BigInt::Positive);
268 h.mask_bits(mod_lz);
269 const bool h_nonzero = h.signum() != 0;
270 h.ct_cond_assign(h_nonzero && h_neg, m2k - h);
271
272 // Return result inv_o + h * o
273 h *= o;
274 h += inv_o;
275 return h;
276}
void ct_cond_add(bool predicate, const BigInt &value)
Definition bigint.cpp:452
bool is_odd() const
Definition bigint.h:487
size_t low_zero_bits(const BigInt &n)
Definition numthry.cpp:194

References Botan::BigInt::bits(), BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, Botan::BigInt::ct_cond_add(), Botan::BigInt::ct_cond_assign(), ct_modulo(), Botan::BigInt::get_bit(), Botan::BigInt::is_even(), Botan::BigInt::is_odd(), Botan::BigInt::is_zero(), low_zero_bits(), Botan::BigInt::mask_bits(), Botan::BigInt::Positive, Botan::BigInt::power_of_2(), Botan::BigInt::set_sign(), and Botan::BigInt::signum().

Referenced by botan_mp_mod_inverse(), compute_rsa_secret_exponent(), and inverse_mod().

◆ inverse_mod_public_prime()

BigInt BOTAN_TEST_API Botan::inverse_mod_public_prime ( const BigInt & x,
const BigInt & p )

Compute the inverse of x modulo a public prime p

This algorithm is constant time with respect to x. The prime p is assumed to be public.

Parameters
xa positive integer less than p
pan odd prime
Returns
y such that (x*y) % p == 1

This always returns a result since any integer in [1,p) has an inverse modulo a prime p.

This function assumes as a precondition that p truly is prime; the results may not be correct if this does not hold.

Throws Invalid_Argument if x is less than or equal to zero, or if p is even or less than 3.

Definition at line 290 of file mod_inv.cpp.

290 {
291 BOTAN_ARG_CHECK(p.signum() > 0, "Modulus must be positive");
292 BOTAN_ARG_CHECK(x.signum() > 0, "Input must be positive");
293 BOTAN_ARG_CHECK(x < p, "Input must be less than modulus");
294 BOTAN_ARG_CHECK(p.is_odd() && p > 1, "Primes are odd integers greater than 1");
295
296 // TODO possibly use FLT, or the algorithm presented for this case in
297 // Handbook of Elliptic and Hyperelliptic Curve Cryptography
298
299 return inverse_mod_odd_modulus(x, p);
300}

References BOTAN_ARG_CHECK, Botan::BigInt::is_odd(), and Botan::BigInt::signum().

Referenced by Botan::DL_Group::inverse_mod_p(), Botan::DL_Group::inverse_mod_q(), Botan::EC_Scalar_Data_BN::invert(), and Botan::EC_Scalar_Data_BN::invert_vartime().

◆ inverse_mod_rsa_public_modulus()

BigInt Botan::inverse_mod_rsa_public_modulus ( const BigInt & x,
const BigInt & n )

Compute the inverse of x modulo a public RSA modulus n

This algorithm is constant time with respect to x. The RSA modulus is assumed to be public.

Parameters
xa positive integer less than n
na RSA public modulus
Returns
y such that (x*y) % n == 1

This always returns a result since any integer in [1,n) has an inverse modulo a RSA public modulus n, unless you have happened to guess one of the factors at random. In the unlikely event of this occurring, Internal_Error will be thrown.

Definition at line 302 of file mod_inv.cpp.

302 {
303 BOTAN_ARG_CHECK(n.signum() > 0 && n.is_odd(), "RSA public modulus must be odd and positive");
304 BOTAN_ARG_CHECK(x.signum() > 0 && x < n, "Input must be positive and less than RSA modulus");
305 BigInt z = inverse_mod_odd_modulus(x, n);
306 BOTAN_ASSERT(z.signum() != 0, "Accidentally factored the public modulus"); // whoops
307 return z;
308}

References BOTAN_ARG_CHECK, BOTAN_ASSERT, Botan::BigInt::is_odd(), and Botan::BigInt::signum().

◆ inverse_mod_secret_prime()

BigInt BOTAN_TEST_API Botan::inverse_mod_secret_prime ( const BigInt & x,
const BigInt & p )

Compute the inverse of x modulo a secret prime p

This algorithm is constant time with respect to x and p, aside from leaking the length of p. (In particular it should not leak the length of x, if x is shorter)

Parameters
xa positive integer less than p
pan odd prime
Returns
y such that (x*y) % p == 1

This always returns a result since any integer in [1,p) has an inverse modulo a prime p.

This function assumes as a precondition that p truly is prime; the results may not be correct if this does not hold.

Throws Invalid_Argument if x is less than or equal to zero, or if p is even or less than 3.

Definition at line 278 of file mod_inv.cpp.

278 {
279 BOTAN_ARG_CHECK(p.signum() > 0, "Modulus must be positive");
280 BOTAN_ARG_CHECK(x.signum() > 0, "Input must be positive");
281 BOTAN_ARG_CHECK(x < p, "Input must be less than modulus");
282 BOTAN_ARG_CHECK(CT::driveby_unpoison(p.is_odd()) && p > 1, "Primes are odd integers greater than 1");
283
284 // TODO possibly use FLT, or the algorithm presented for this case in
285 // Handbook of Elliptic and Hyperelliptic Curve Cryptography
286
287 return inverse_mod_odd_modulus(x, p);
288}

References BOTAN_ARG_CHECK, Botan::CT::driveby_unpoison(), Botan::BigInt::is_odd(), and Botan::BigInt::signum().

Referenced by Botan::RSA_PrivateKey::check_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and Botan::RSA_PrivateKey::RSA_PrivateKey().

◆ invert_field_element()

template<typename C>
auto Botan::invert_field_element ( const typename C::FieldElement & fe)
inlineconstexpr

Field inversion

Uses the specialized fe_invert2 if available, or otherwise the standard (FLT-based) field inversion.

Definition at line 36 of file pcurves_algos.h.

36 {
37 if constexpr(curve_supports_fe_invert2<C>) {
38 return C::fe_invert2(fe) * fe;
39 } else {
40 return fe.invert();
41 }
42}

Referenced by map_to_curve_sswu(), SSWU_C2(), to_affine(), to_affine_batch(), and to_affine_x().

◆ is_ascii_control_char()

BOTAN_TEST_API bool Botan::is_ascii_control_char ( char c)

Return true if c is a control character (0x00..0x1F) or DEL (0x7F)

Definition at line 198 of file charset.cpp.

198 {
199 const uint8_t b = static_cast<uint8_t>(c);
200 return b < 0x20 || b == 0x7F;
201}

Referenced by format_char_for_display().

◆ is_bailie_psw_probable_prime() [1/2]

bool BOTAN_TEST_API Botan::is_bailie_psw_probable_prime ( const BigInt & n)

Perform Bailie-PSW primality test

This variant creates the Montgomery parameters internally, and accepts any non-negative integer (returning false for even or tiny values).

Parameters
nthe positive integer to test
Returns
true if n seems probably prime, false if n is composite

Definition at line 465 of file primality.cpp.

465 {
466 if(n == 2) {
467 return true;
468 } else if(n <= 1 || CT::driveby_unpoison(n.is_even())) {
469 return false;
470 }
471
472 return bailie_psw_test(n, Montgomery_Params(n), false);
473}

References Botan::CT::driveby_unpoison(), and Botan::BigInt::is_even().

◆ is_bailie_psw_probable_prime() [2/2]

bool BOTAN_TEST_API Botan::is_bailie_psw_probable_prime ( const BigInt & n,
const Montgomery_Params & monty_n )

Perform Bailie-PSW primality test

This is a combination of Miller-Rabin with base 2 and a Lucas test. No known composite integer passes both tests, though it is conjectured that infinitely many composite counterexamples exist.

Parameters
nthe positive integer to test
monty_npre-created Montgomery parameters for n
Returns
true if n seems probably prime, false if n is composite

Definition at line 457 of file primality.cpp.

457 {
458 return bailie_psw_test(n, monty_n, false);
459}

◆ is_bailie_psw_probable_prime_vartime() [1/2]

bool BOTAN_TEST_API Botan::is_bailie_psw_probable_prime_vartime ( const BigInt & n)

Perform Bailie-PSW primality test, taking variable time depending on n

This variant creates the Montgomery parameters internally, and accepts any non-negative integer (returning false for even or tiny values).

Warning
only use this if n is public
Parameters
nthe positive integer to test
Returns
true if n seems probably prime, false if n is composite

Definition at line 475 of file primality.cpp.

475 {
476 if(n == 2) {
477 return true;
478 } else if(n <= 1 || n.is_even()) {
479 return false;
480 }
481
482 return bailie_psw_test(n, Montgomery_Params(n), true);
483}

References Botan::BigInt::is_even().

◆ is_bailie_psw_probable_prime_vartime() [2/2]

bool BOTAN_TEST_API Botan::is_bailie_psw_probable_prime_vartime ( const BigInt & n,
const Montgomery_Params & monty_n )

Perform Bailie-PSW primality test, taking variable time depending on n

Warning
only use this if n is public
Parameters
nthe positive integer to test
monty_npre-created Montgomery parameters for n
Returns
true if n seems probably prime, false if n is composite

Definition at line 461 of file primality.cpp.

461 {
462 return bailie_psw_test(n, monty_n, true);
463}

Referenced by Botan::EC_Group::EC_Group(), and Botan::EC_Group::register_custom_group().

◆ is_generalizable_to() [1/2]

template<typename GeneralVariantT, typename SpecialT>
bool Botan::is_generalizable_to ( const SpecialT & )
constexprnoexcept

◆ is_generalizable_to() [2/2]

template<typename GeneralVariantT, typename... SpecialTs>
bool Botan::is_generalizable_to ( const std::variant< SpecialTs... > & )
constexprnoexcept

Definition at line 76 of file stl_util.h.

76 {
77 return (std::is_constructible_v<GeneralVariantT, SpecialTs> && ...);
78}

◆ is_lucas_probable_prime()

bool BOTAN_TEST_API Botan::is_lucas_probable_prime ( const BigInt & n,
const Montgomery_Params & monty_n )

Perform Lucas primality test

See also
FIPS 186-4 C.3.3
Warning
it is possible to construct composite integers which pass this test alone.
Parameters
nthe positive integer to test
monty_npre-created Montgomery parameters for n
Returns
true if n seems probably prime, false if n is composite

Definition at line 449 of file primality.cpp.

449 {
450 return lucas_test(n, monty_n, false);
451}

◆ is_lucas_probable_prime_vartime()

bool BOTAN_TEST_API Botan::is_lucas_probable_prime_vartime ( const BigInt & n,
const Montgomery_Params & monty_n )

Perform Lucas primality test, taking variable time depending on n

See also
FIPS 186-4 C.3.3
Warning
only use this if n is public
Parameters
nthe positive integer to test
monty_npre-created Montgomery parameters for n
Returns
true if n seems probably prime, false if n is composite

Definition at line 453 of file primality.cpp.

453 {
454 return lucas_test(n, monty_n, true);
455}

◆ is_miller_rabin_lucas_probable_prime()

bool BOTAN_TEST_API Botan::is_miller_rabin_lucas_probable_prime ( const BigInt & n,
const Montgomery_Params & monty_n,
RandomNumberGenerator & rng,
size_t t )

Perform t iterations of a Miller-Rabin primality test with random bases, followed by a Lucas test.

If a thread pool is available and the work is large enough, the tests run in parallel, after a single Miller-Rabin test in the calling thread has rejected most composites.

Parameters
nthe positive integer to test
monty_npre-created Montgomery parameters for n
Random Number Generatorsa random number generator
tnumber of Miller-Rabin tests to perform
Returns
result of primality test

Definition at line 499 of file primality.cpp.

502 {
503 return miller_rabin_lucas_test(n, monty_n, rng, test_iterations, false);
504}

◆ is_miller_rabin_lucas_probable_prime_vartime()

bool BOTAN_TEST_API Botan::is_miller_rabin_lucas_probable_prime_vartime ( const BigInt & n,
const Montgomery_Params & monty_n,
RandomNumberGenerator & rng,
size_t t )

Perform t iterations of a Miller-Rabin primality test with random bases, followed by a Lucas test, taking variable time depending on n

Warning
only use this if n is public
Parameters
nthe positive integer to test
monty_npre-created Montgomery parameters for n
Random Number Generatorsa random number generator
tnumber of Miller-Rabin tests to perform
Returns
result of primality test

Definition at line 506 of file primality.cpp.

509 {
510 return miller_rabin_lucas_test(n, monty_n, rng, test_iterations, true);
511}

◆ is_miller_rabin_probable_prime()

bool BOTAN_TEST_API Botan::is_miller_rabin_probable_prime ( const BigInt & n,
const Montgomery_Params & monty_n,
RandomNumberGenerator & rng,
size_t t )

Perform t iterations of a Miller-Rabin primality test with random bases

Parameters
nthe positive integer to test
monty_npre-created Montgomery parameters for n
Random Number Generatorsa random number generator
tnumber of tests to perform
Returns
result of primality test

Definition at line 485 of file primality.cpp.

488 {
489 return miller_rabin_test(n, monty_n, rng, test_iterations, false);
490}

Referenced by generate_rsa_prime().

◆ is_miller_rabin_probable_prime_vartime()

bool BOTAN_TEST_API Botan::is_miller_rabin_probable_prime_vartime ( const BigInt & n,
const Montgomery_Params & monty_n,
RandomNumberGenerator & rng,
size_t t )

Perform t iterations of a Miller-Rabin primality test with random bases, taking variable time depending on n

Warning
only use this if n is public
Parameters
nthe positive integer to test
monty_npre-created Montgomery parameters for n
Random Number Generatorsa random number generator
tnumber of tests to perform
Returns
result of primality test

Definition at line 492 of file primality.cpp.

495 {
496 return miller_rabin_test(n, monty_n, rng, test_iterations, true);
497}

◆ is_passhash9_alg_supported()

bool Botan::is_passhash9_alg_supported ( uint8_t alg_id)

Check if the PRF used with PBKDF2 is supported

Parameters
alg_idalg_id used in generate_passhash9()

Definition at line 129 of file passhash9.cpp.

129 {
130 if(get_pbkdf_prf(alg_id)) {
131 return true;
132 }
133 return false;
134}

◆ is_perfect_square()

BigInt Botan::is_perfect_square ( const BigInt & x)

Test if the positive integer x is a perfect square ie if there exists some positive integer y st y*y == x See FIPS 186-4 sec C.4

Returns
0 if the integer is not a perfect square, otherwise returns the positive y st y*y == x

Definition at line 352 of file numthry.cpp.

352 {
353 if(C < 1) {
354 throw Invalid_Argument("is_perfect_square requires C >= 1");
355 }
356
357 constexpr size_t WB = WordInfo<word>::bits;
358
359 // The root r is less than 2^(bits(C)/2), and the remainder at most 8*r + 3
360 const size_t n = C.sig_words() / 2 + 2;
361
362 secure_vector<word> c(C._data(), C._data() + C.sig_words());
364 secure_vector<word> rem(n);
367
368 CT::poison(c);
369
370 for(size_t i = (C.bits() + 1) / 2; i > 0; --i) {
371 // Bring down the next two bits of C
372 bigint_shl1(rem.data(), n, n, 2);
373 rem[0] |= (c[(2 * i - 2) / WB] >> ((2 * i - 2) % WB)) & 3;
374
375 // If rem >= 4*r + 1 then the next bit of the root is set
376 copy_mem(t.data(), r.data(), n);
377 bigint_shl1(t.data(), n, n, 2);
378 t[0] |= 1;
379
380 const word next_bit = bigint_sub3(u.data(), rem.data(), n, t.data(), n) ^ 1;
381 CT::conditional_assign_mem(next_bit, rem.data(), u.data(), n);
382
383 bigint_shl1(r.data(), n, n, 1);
384 r[0] |= next_bit;
385 }
386
387 // C is a perfect square iff the remainder is zero
388 (~CT::all_zeros(rem.data(), n)).if_set_zero_out(r.data(), n);
389 CT::unpoison(r);
390
391 return BigInt::_from_words(r);
392}
constexpr auto bigint_sub3(W z[], const W x[], size_t x_size, const W y[], size_t y_size) -> W
Definition mp_core.h:196
constexpr void bigint_shl1(W x[], size_t x_size, size_t x_words, size_t shift)
Definition mp_core.h:313

References Botan::BigInt::_data(), Botan::BigInt::_from_words(), bigint_shl1(), bigint_sub3(), Botan::BigInt::bits(), Botan::CT::conditional_assign_mem(), copy_mem(), Botan::CT::poison(), Botan::BigInt::sig_words(), and Botan::CT::unpoison().

◆ is_power_of_2()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr bool Botan::is_power_of_2 ( T arg)
constexpr

Power of 2 test. T should be an unsigned integer type

Parameters
argan integer value
Returns
true iff arg is 2^n for some n > 0

Definition at line 62 of file bit_ops.h.

62 {
63 return (arg != 0) && (arg != 1) && ((arg & static_cast<T>(arg - 1)) == 0);
64}

References BOTAN_FORCE_INLINE.

Referenced by operator%(), Botan::BigInt::operator%=(), Botan::BigInt::operator/=(), Botan::Scrypt::Scrypt(), and Botan::CTR_BE::seek().

◆ is_prime()

bool Botan::is_prime ( const BigInt & n,
RandomNumberGenerator & rng,
size_t prob = 64,
bool is_random = false )

Check for primality

This uses probabilistic algorithms - there is some non-zero (but very low) probability that this function will return true even if n is actually composite.

Parameters
na positive integer to test for primality
Random Number Generatorsa random number generator
probchance of false positive is bounded by 1/2**prob
is_randomtrue if n was randomly chosen by us
Returns
true if all primality tests passed, otherwise false

Definition at line 449 of file numthry.cpp.

449 {
450 return is_prime_impl(n, rng, prob, is_random, false);
451}

Referenced by botan_mp_is_prime(), Botan::RSA_PrivateKey::check_key(), and random_safe_prime().

◆ is_prime_vartime()

bool BOTAN_TEST_API Botan::is_prime_vartime ( const BigInt & n,
RandomNumberGenerator & rng,
size_t prob,
bool is_random )

Check for primality, taking variable time depending on n

This performs the same tests as is_prime, but uses variable time algorithms throughout and so is faster.

Warning
only use this if n is public
Parameters
na positive integer to test for primality
Random Number Generatorsa random number generator
probchance of false positive is bounded by 1/2**prob
is_randomtrue if n was randomly chosen by us
Returns
true if all primality tests passed, otherwise false

Definition at line 453 of file numthry.cpp.

453 {
454 return is_prime_impl(n, rng, prob, is_random, true);
455}

Referenced by Botan::DL_Group::DL_Group(), generate_dsa_primes(), Botan::DL_Group::verify_group(), and Botan::EC_Group::verify_group().

◆ is_sub_element_of()

std::optional< uint32_t > Botan::is_sub_element_of ( const OID & oid,
std::initializer_list< uint32_t > prefix )
inline

Definition at line 22 of file x509_utils.h.

22 {
23 const auto& c = oid.get_components();
24
25 if(c.size() != prefix.size() + 1) {
26 return {};
27 }
28
29 if(!std::equal(c.begin(), c.end() - 1, prefix.begin(), prefix.end())) {
30 return {};
31 }
32
33 return c[c.size() - 1];
34}
const std::vector< uint32_t > & get_components() const
Definition asn1_obj.h:530

References Botan::OID::get_components().

Referenced by Botan::X509_DN::lookup_ub().

◆ is_unicode_control_char()

BOTAN_TEST_API bool Botan::is_unicode_control_char ( uint32_t cp)

Return true if the Unicode code point cp is a control character: a C0 control (U+0000..U+001F), DEL (U+007F), or a C1 control (U+0080..U+009F)

Definition at line 203 of file charset.cpp.

203 {
204 return cp < 0x20 || (cp >= 0x7F && cp <= 0x9F);
205}

Referenced by escape_control_chars(), and operator<<().

◆ is_valid_utf8()

bool Botan::is_valid_utf8 ( std::string_view str)

Return true if this string seems to contain a valid sequence of UTF-8

Definition at line 108 of file charset.cpp.

108 {
109 try {
110 size_t pos = 0;
111 while(pos < utf8.size()) {
112 const uint32_t c = next_utf8_codepoint(utf8, pos);
113 BOTAN_UNUSED(c);
114 }
115 } catch(Decoding_Error&) {
116 return false;
117 }
118 return true;
119}

References BOTAN_UNUSED, and next_utf8_codepoint().

◆ jacobi()

int32_t Botan::jacobi ( BigInt a,
BigInt n )

Compute the Jacobi symbol. If n is prime, this is equivalent to the Legendre symbol.

See also
http://mathworld.wolfram.com/JacobiSymbol.html
Parameters
ais a non-negative integer
nis an odd integer > 1
Returns
(n / m)

Definition at line 119 of file numthry.cpp.

119 {
120 BOTAN_ARG_CHECK(n.is_odd() && n >= 3, "Argument n must be an odd integer >= 3");
121
122 if(a < 0 || a >= n) {
123 a %= n;
124 }
125
126 if(a == 0) {
127 return 0;
128 }
129 if(a == 1) {
130 return 1;
131 }
132
133 int32_t s = 1;
134
135 for(;;) {
136 const size_t e = low_zero_bits(a);
137 a >>= e;
138 const word n_mod_8 = n.word_at(0) % 8;
139 const word n_mod_4 = n_mod_8 % 4;
140
141 if(e % 2 == 1 && (n_mod_8 == 3 || n_mod_8 == 5)) {
142 s = -s;
143 }
144
145 if(n_mod_4 == 3 && a % 4 == 3) {
146 s = -s;
147 }
148
149 /*
150 * The HAC presentation of the algorithm uses recursion, which is not
151 * desirable or necessary.
152 *
153 * Instead we loop accumulating the product of the various jacobi()
154 * subcomputations into s, until we reach algorithm termination, which
155 * occurs in one of two ways.
156 *
157 * If a == 1 then the recursion has completed; we can return the value of s.
158 *
159 * Otherwise, after swapping and reducing, check for a == 0 [this value is
160 * called `n1` in HAC's presentation]. This would imply that jacobi(n1,a1)
161 * would have the value 0, due to Line 1 in HAC 2.149, in which case the
162 * entire product is zero, and we can immediately return that result.
163 */
164
165 if(a == 1) {
166 return s;
167 }
168
169 std::swap(a, n);
170
172
173 a %= n;
174
175 if(a == 0) {
176 return 0;
177 }
178 }
179}
word word_at(size_t n) const
Definition bigint.h:601

References BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, Botan::BigInt::is_odd(), low_zero_bits(), and Botan::BigInt::word_at().

Referenced by Botan::DL_Group::DL_Group(), and sqrt_modulo_prime().

◆ keccak_absorb_padded_strings_encoding()

template<absorbing_object T, typename... Ts>
size_t Botan::keccak_absorb_padded_strings_encoding ( T & sink,
size_t padding_mod,
Ts... byte_strings )

This is a combination of the functions encode_string() and bytepad() defined in NIST SP.800-185 Section 2.3. Additionally, the result is directly streamed into the provided XOF to avoid unnecessary memory allocation or a byte vector.

Parameters
sinkthe XOF or byte vector to absorb the byte_strings into
padding_modthe modulus value to create a padding for (NIST calls this 'w')
byte_stringsa variable-length list of byte strings to be encoded and absorbed into the given xof
Returns
the number of bytes absorbed into the xof

Definition at line 91 of file keccak_helpers.h.

91 {
92 BOTAN_ASSERT_NOMSG(padding_mod > 0);
93
94 // used as temporary storage for all integer encodings in this function
95 std::array<uint8_t, keccak_max_int_encoding_size()> int_encoding_buffer{};
96
97 // absorbs byte strings and counts the number of absorbed bytes
98 size_t bytes_absorbed = 0;
99 auto absorb = [&](std::span<const uint8_t> bytes) {
100 if constexpr(updatable_object<T>) {
101 sink.update(bytes);
102 } else if constexpr(appendable_object<T>) {
103 sink.insert(sink.end(), bytes.begin(), bytes.end());
104 }
105 bytes_absorbed += bytes.size();
106 };
107
108 // encodes a given string and absorbs it into the XOF straight away
109 const auto encode_string_and_absorb = [&](std::span<const uint8_t> bytes) {
110 absorb(keccak_int_left_encode(int_encoding_buffer, bytes.size() * 8));
111 absorb(bytes);
112 };
113
114 // absorbs as many zero-bytes as requested into the XOF
115 const auto absorb_padding = [&](size_t padding_bytes) {
116 for(size_t i = 0; i < padding_bytes; ++i) {
117 const uint8_t zero_byte = 0;
118 absorb({&zero_byte, 1});
119 }
120 };
121
122 // implementation of bytepad(encode_string(Ts) || ...) that absorbs the result
123 // staight into the given xof
124 absorb(keccak_int_left_encode(int_encoding_buffer, padding_mod));
125 (encode_string_and_absorb(byte_strings), ...);
126 // SP.800-185 Section 2.3.3 bytepad: "while len(z)/8 mod w != 0: z = z || 00000000"
127 absorb_padding((padding_mod - (bytes_absorbed % padding_mod)) % padding_mod);
128
129 return bytes_absorbed;
130}
std::span< const uint8_t > keccak_int_left_encode(std::span< uint8_t > out, size_t x)
constexpr size_t keccak_max_int_encoding_size()

References BOTAN_ASSERT_NOMSG, keccak_absorb_padded_strings_encoding(), keccak_int_left_encode(), and keccak_max_int_encoding_size().

Referenced by keccak_absorb_padded_strings_encoding().

◆ keccak_chi()

template<typename W>
BOTAN_FORCE_INLINE W Botan::keccak_chi ( const W & x,
const W & y,
const W & z )

Definition at line 39 of file keccak_perm_round.h.

39 {
40 if constexpr(std::unsigned_integral<W>) {
41 return x ^ (~y & z);
42 } else {
43 return W::chi(x, y, z);
44 }
45}

References BOTAN_FORCE_INLINE.

Referenced by Keccak_Permutation_round().

◆ keccak_int_encoding_size()

BOTAN_TEST_API size_t Botan::keccak_int_encoding_size ( size_t x)
Returns
the required bytes for encodings of keccak_int_left_encode() or keccak_int_right_encode() given an integer x

Definition at line 55 of file keccak_helpers.cpp.

55 {
56 return int_encoding_size(x) + 1 /* the length tag */;
57}

◆ keccak_int_left_encode()

BOTAN_TEST_API std::span< const uint8_t > Botan::keccak_int_left_encode ( std::span< uint8_t > buffer,
size_t x )

Integer encoding defined in NIST SP.800-185 that can be unambiguously parsed from the beginning of the string.

This function does not allocate any memory and requires the caller to provide a sufficiently large buffer. For a given x, this will need exactly keccak_int_encoding_size() bytes. For an arbitrary x it will generate keccak_max_int_encoding_size() bytes at most.

Parameters
bufferbuffer to write the left-encoding of x to. It is assumed that the buffer will hold at least keccak_int_encoding_size() bytes.
xthe integer to be left-encoded
Returns
the byte span that represents the bytes written to buffer.

Definition at line 42 of file keccak_helpers.cpp.

42 {
43 BOTAN_ASSERT_NOMSG(!out.empty());
44 out[0] = encode(out.last(out.size() - 1), x);
45 return out.first(out[0] + 1 /* the length tag */);
46}

References BOTAN_ASSERT_NOMSG.

Referenced by keccak_absorb_padded_strings_encoding().

◆ keccak_int_right_encode()

BOTAN_TEST_API std::span< const uint8_t > Botan::keccak_int_right_encode ( std::span< uint8_t > out,
size_t x )

Integer encoding defined in NIST SP.800-185 that can be unambiguously parsed from the end of the string.

This function does not allocate any memory and requires the caller to provide a sufficiently large buffer. For a given x, this will need exactly keccak_int_encoding_size() bytes. For an arbitrary x it will generate keccak_max_int_encoding_size() bytes at most.

Parameters
outbuffer to write the right-encoding of x to. It is assumed that the buffer will hold at least keccak_int_encoding_size() bytes.
xthe integer to be right-encoded
Returns
the byte span that represents the bytes written to buffer.

Definition at line 48 of file keccak_helpers.cpp.

48 {
49 const auto bytes_needed = encode(out, x);
50 BOTAN_ASSERT_NOMSG(out.size() >= bytes_needed + size_t(1));
51 out[bytes_needed] = bytes_needed;
52 return out.first(bytes_needed + 1 /* the length tag */);
53}

References BOTAN_ASSERT_NOMSG.

◆ keccak_iota()

template<typename W>
BOTAN_FORCE_INLINE W Botan::keccak_iota ( uint64_t rc)

Definition at line 48 of file keccak_perm_round.h.

48 {
49 if constexpr(std::unsigned_integral<W>) {
50 return rc;
51 } else {
52 return W::splat(rc);
53 }
54}

References BOTAN_FORCE_INLINE.

Referenced by Keccak_Permutation_round().

◆ keccak_max_int_encoding_size()

size_t Botan::keccak_max_int_encoding_size ( )
constexpr
Returns
the maximum required bytes for encodings of keccak_int_left_encode() or keccak_int_right_encode()

Definition at line 65 of file keccak_helpers.h.

65 {
66 return sizeof(size_t) + 1 /* the length tag */;
67}

Referenced by keccak_absorb_padded_strings_encoding().

◆ keccak_mb_absorb_x4()

BOTAN_FN_ISA_SIMD_4X64 void Botan::keccak_mb_absorb_x4 ( uint64_t * states,
const uint8_t *const * blocks,
size_t rate_words,
size_t nblocks )

Definition at line 70 of file hash_engine_keccak_avx2.cpp.

73 {
74 SIMD_4x64 A[25];
75 SIMD_4x64 T[25];
76
77 for(size_t w = 0; w != 25; ++w) {
78 A[w] = SIMD_4x64::load_le(states + 4 * w);
79 }
80
81 for(size_t b = 0; b != nblocks; ++b) {
82 absorb_block(A, blocks + 4 * b, rate_words);
83
84 for(size_t i = 0; i != 24; i += 2) {
87 }
88 }
89
90 for(size_t w = 0; w != 25; ++w) {
91 A[w].store_le(states + 4 * w);
92 }
93}
void BOTAN_FN_ISA_SIMD_4X64 store_le(uint64_t out[4]) const
Definition simd_4x64.h:72
static BOTAN_FN_ISA_SIMD_4X64 SIMD_4x64 load_le(const void *in)
Definition simd_4x64.h:45
BOTAN_FORCE_INLINE void Keccak_Permutation_round(W T[25], const W A[25], uint64_t RC)
constexpr uint64_t KECCAK_RC[24]

References Keccak_Permutation_round(), KECCAK_RC, Botan::SIMD_4x64::load_le(), and Botan::SIMD_4x64::store_le().

Referenced by create_keccak_mb_engine().

◆ keccak_mb_absorb_x8()

BOTAN_FN_ISA_SIMD_8X64 void Botan::keccak_mb_absorb_x8 ( uint64_t * states,
const uint8_t *const * blocks,
size_t rate_words,
size_t nblocks )

Definition at line 37 of file hash_engine_keccak_avx512.cpp.

40 {
41 SIMD_8x64 A[25];
42 SIMD_8x64 T[25];
43
44 for(size_t w = 0; w != 25; ++w) {
45 A[w] = SIMD_8x64::load_le(states + 8 * w);
46 }
47
48 // The whole strip is staged into word-major lane order with scalar
49 // loads and stores first; unlike an unpack based transpose these do
50 // not compete with the permutation for the vector ports
51 BOTAN_ASSERT_NOMSG(nblocks <= KECCAK_MB_ABSORB_BLOCKS && rate_words <= 25);
52
53 alignas(64) uint64_t staged[KECCAK_MB_ABSORB_BLOCKS * 25 * 8];
54 for(size_t b = 0; b != nblocks; ++b) {
55 for(size_t l = 0; l != 8; ++l) {
56 const uint8_t* src = blocks[8 * b + l];
57 for(size_t w = 0; w != rate_words; ++w) {
58 staged[(b * rate_words + w) * 8 + l] = load_le<uint64_t>(src, w);
59 }
60 }
61 }
62
63 for(size_t b = 0; b != nblocks; ++b) {
64 for(size_t w = 0; w != rate_words; ++w) {
65 A[w] ^= SIMD_8x64::load_le(staged + (b * rate_words + w) * 8);
66 }
67
68 for(size_t i = 0; i != 24; i += 2) {
71 }
72 }
73
74 for(size_t w = 0; w != 25; ++w) {
75 A[w].store_le(states + 8 * w);
76 }
77}
void store_le(uint64_t out[8]) const
Definition simd_8x64.h:82
static BOTAN_FN_ISA_SIMD_8X64 SIMD_8x64 load_le(const void *in)
Definition simd_8x64.h:51
constexpr size_t KECCAK_MB_ABSORB_BLOCKS

References BOTAN_ASSERT_NOMSG, KECCAK_MB_ABSORB_BLOCKS, Keccak_Permutation_round(), KECCAK_RC, load_le(), Botan::SIMD_8x64::load_le(), and Botan::SIMD_8x64::store_le().

Referenced by create_keccak_mb_engine().

◆ keccak_mb_permute_x4()

BOTAN_FN_ISA_SIMD_4X64 void Botan::keccak_mb_permute_x4 ( uint64_t * states)

Definition at line 52 of file hash_engine_keccak_avx2.cpp.

52 {
53 SIMD_4x64 A[25];
54 SIMD_4x64 T[25];
55
56 for(size_t w = 0; w != 25; ++w) {
57 A[w] = SIMD_4x64::load_le(states + 4 * w);
58 }
59
60 for(size_t i = 0; i != 24; i += 2) {
63 }
64
65 for(size_t w = 0; w != 25; ++w) {
66 A[w].store_le(states + 4 * w);
67 }
68}

References Keccak_Permutation_round(), KECCAK_RC, Botan::SIMD_4x64::load_le(), and Botan::SIMD_4x64::store_le().

Referenced by create_keccak_mb_engine().

◆ keccak_mb_permute_x8()

BOTAN_FN_ISA_SIMD_8X64 void Botan::keccak_mb_permute_x8 ( uint64_t * states)

Definition at line 19 of file hash_engine_keccak_avx512.cpp.

19 {
20 SIMD_8x64 A[25];
21 SIMD_8x64 T[25];
22
23 for(size_t w = 0; w != 25; ++w) {
24 A[w] = SIMD_8x64::load_le(states + 8 * w);
25 }
26
27 for(size_t i = 0; i != 24; i += 2) {
30 }
31
32 for(size_t w = 0; w != 25; ++w) {
33 A[w].store_le(states + 8 * w);
34 }
35}

References Keccak_Permutation_round(), KECCAK_RC, Botan::SIMD_8x64::load_le(), and Botan::SIMD_8x64::store_le().

Referenced by create_keccak_mb_engine().

◆ Keccak_Permutation_round()

template<typename W>
BOTAN_FORCE_INLINE void Botan::Keccak_Permutation_round ( W T[25],
const W A[25],
uint64_t RC )

Definition at line 57 of file keccak_perm_round.h.

57 {
58 const W C0 = A[0] ^ A[5] ^ A[10] ^ A[15] ^ A[20];
59 const W C1 = A[1] ^ A[6] ^ A[11] ^ A[16] ^ A[21];
60 const W C2 = A[2] ^ A[7] ^ A[12] ^ A[17] ^ A[22];
61 const W C3 = A[3] ^ A[8] ^ A[13] ^ A[18] ^ A[23];
62 const W C4 = A[4] ^ A[9] ^ A[14] ^ A[19] ^ A[24];
63
64 const W D0 = keccak_rotl<1>(C0) ^ C3;
65 const W D1 = keccak_rotl<1>(C1) ^ C4;
66 const W D2 = keccak_rotl<1>(C2) ^ C0;
67 const W D3 = keccak_rotl<1>(C3) ^ C1;
68 const W D4 = keccak_rotl<1>(C4) ^ C2;
69
70 const W B00 = A[0] ^ D1;
71 const W B01 = keccak_rotl<44>(A[6] ^ D2);
72 const W B02 = keccak_rotl<43>(A[12] ^ D3);
73 const W B03 = keccak_rotl<21>(A[18] ^ D4);
74 const W B04 = keccak_rotl<14>(A[24] ^ D0);
75 T[0] = keccak_chi(B00, B01, B02) ^ keccak_iota<W>(RC);
76 T[1] = keccak_chi(B01, B02, B03);
77 T[2] = keccak_chi(B02, B03, B04);
78 T[3] = keccak_chi(B03, B04, B00);
79 T[4] = keccak_chi(B04, B00, B01);
80
81 const W B05 = keccak_rotl<28>(A[3] ^ D4);
82 const W B06 = keccak_rotl<20>(A[9] ^ D0);
83 const W B07 = keccak_rotl<3>(A[10] ^ D1);
84 const W B08 = keccak_rotl<45>(A[16] ^ D2);
85 const W B09 = keccak_rotl<61>(A[22] ^ D3);
86 T[5] = keccak_chi(B05, B06, B07);
87 T[6] = keccak_chi(B06, B07, B08);
88 T[7] = keccak_chi(B07, B08, B09);
89 T[8] = keccak_chi(B08, B09, B05);
90 T[9] = keccak_chi(B09, B05, B06);
91
92 const W B10 = keccak_rotl<1>(A[1] ^ D2);
93 const W B11 = keccak_rotl<6>(A[7] ^ D3);
94 const W B12 = keccak_rotl<25>(A[13] ^ D4);
95 const W B13 = keccak_rotl<8>(A[19] ^ D0);
96 const W B14 = keccak_rotl<18>(A[20] ^ D1);
97 T[10] = keccak_chi(B10, B11, B12);
98 T[11] = keccak_chi(B11, B12, B13);
99 T[12] = keccak_chi(B12, B13, B14);
100 T[13] = keccak_chi(B13, B14, B10);
101 T[14] = keccak_chi(B14, B10, B11);
102
103 const W B15 = keccak_rotl<27>(A[4] ^ D0);
104 const W B16 = keccak_rotl<36>(A[5] ^ D1);
105 const W B17 = keccak_rotl<10>(A[11] ^ D2);
106 const W B18 = keccak_rotl<15>(A[17] ^ D3);
107 const W B19 = keccak_rotl<56>(A[23] ^ D4);
108 T[15] = keccak_chi(B15, B16, B17);
109 T[16] = keccak_chi(B16, B17, B18);
110 T[17] = keccak_chi(B17, B18, B19);
111 T[18] = keccak_chi(B18, B19, B15);
112 T[19] = keccak_chi(B19, B15, B16);
113
114 const W B20 = keccak_rotl<62>(A[2] ^ D3);
115 const W B21 = keccak_rotl<55>(A[8] ^ D4);
116 const W B22 = keccak_rotl<39>(A[14] ^ D0);
117 const W B23 = keccak_rotl<41>(A[15] ^ D1);
118 const W B24 = keccak_rotl<2>(A[21] ^ D2);
119 T[20] = keccak_chi(B20, B21, B22);
120 T[21] = keccak_chi(B21, B22, B23);
121 T[22] = keccak_chi(B22, B23, B24);
122 T[23] = keccak_chi(B23, B24, B20);
123 T[24] = keccak_chi(B24, B20, B21);
124}
BOTAN_FORCE_INLINE W keccak_iota(uint64_t rc)
BOTAN_FORCE_INLINE W keccak_rotl(const W &v)
BOTAN_FORCE_INLINE W keccak_chi(const W &x, const W &y, const W &z)

References BOTAN_FORCE_INLINE, keccak_chi(), keccak_iota(), and keccak_rotl().

Referenced by keccak_mb_absorb_x4(), keccak_mb_absorb_x8(), keccak_mb_permute_x4(), keccak_mb_permute_x8(), and Botan::Keccak_Permutation::permute().

◆ keccak_rotl()

template<size_t R, typename W>
BOTAN_FORCE_INLINE W Botan::keccak_rotl ( const W & v)

Definition at line 30 of file keccak_perm_round.h.

30 {
31 if constexpr(std::unsigned_integral<W>) {
32 return rotl<R>(v);
33 } else {
34 return v.template rotl<R>();
35 }
36}
BOTAN_FORCE_INLINE constexpr T rotl(T input)
Definition rotate.h:23

References BOTAN_FORCE_INLINE, and rotl().

Referenced by Keccak_Permutation_round().

◆ key_constraints_to_string()

std::string Botan::key_constraints_to_string ( Key_Constraints c)
inline

Definition at line 43 of file pkix_types.h.

43 {
44 return c.to_string();
45}
std::string to_string() const

References key_constraints_to_string().

Referenced by key_constraints_to_string().

◆ latin1_to_utf8()

BOTAN_TEST_API std::string Botan::latin1_to_utf8 ( std::span< const uint8_t > chars)

Definition at line 190 of file charset.cpp.

190 {
191 std::string s;
192 for(const uint8_t b : chars) {
193 append_utf8_for(s, static_cast<uint32_t>(b));
194 }
195 return s;
196}

Referenced by Botan::ASN1_String::decode_from().

◆ lcm()

BigInt Botan::lcm ( const BigInt & x,
const BigInt & y )

Least common multiple

Parameters
xa positive integer
ya positive integer
Returns
z, smallest integer such that z % x == 0 and z % y == 0

Definition at line 296 of file numthry.cpp.

296 {
297 if(a == b) {
298 return a;
299 }
300
301 auto ab = a * b;
302 ab.set_sign(BigInt::Positive); // ignore the signs of a & b
303 const auto g = gcd(a, b);
304 return ct_divide(ab, g);
305}

References ct_divide(), gcd(), Botan::BigInt::Positive, and Botan::BigInt::set_sign().

Referenced by Botan::RSA_PrivateKey::check_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and Botan::RSA_PrivateKey::RSA_PrivateKey().

◆ lex_to_gray()

gf2m Botan::lex_to_gray ( gf2m lex)
inline

Definition at line 38 of file code_based_util.h.

38 {
39 return (lex >> 1) ^ lex;
40}

Referenced by syndrome_init().

◆ lmots_compute_pubkey_from_sig()

BOTAN_TEST_API LMOTS_K Botan::lmots_compute_pubkey_from_sig ( const LMOTS_Signature & sig,
const LMS_Message & msg,
const LMS_Identifier & identifier,
LMS_Tree_Node_Idx q )

Compute a public key candidate for an OTS-signature-message pair and the OTS instance parameters.

Defined in RFC 8554 4.6 - Algorithm 4b

Definition at line 481 of file lm_ots.cpp.

484 {
485 const auto params = LMOTS_Params::create_or_throw(sig.algorithm_type());
486
487 // Alg. 4b 3.
488
489 const auto Q_with_cksm = gen_Q_with_cksm(params, identifier, q, sig.C(), msg);
490
491 const uint16_t p = params.p();
492 const size_t n = params.n();
493
494 secure_vector<uint8_t> nodes(p * n);
495 std::vector<uint8_t> a(p);
496 for(uint16_t i = 0; i < p; ++i) {
497 a[i] = coef(Q_with_cksm, i, params);
498 copy_mem(std::span(nodes).subspan(i * n, n), sig.y(i));
499 }
500
501 const auto engine = Hash_Engine::create_or_throw(params.hash_name());
502 Batch_Chain_Generator chain_gen(*engine, identifier, q, p);
503
504 std::vector<uint16_t> active;
505 std::vector<std::span<uint8_t>> outputs;
506 std::vector<std::span<const uint8_t>> inputs;
507 active.reserve(p);
508 outputs.reserve(p);
509 inputs.reserve(p);
510
511 // Chain i continues from position a[i] up to the top
512 for(uint8_t j = 0; j < params.coef_max(); ++j) {
513 active.clear();
514 outputs.clear();
515 inputs.clear();
516 for(uint16_t i = 0; i < p; ++i) {
517 if(a[i] <= j) {
518 active.push_back(i);
519 const auto node = std::span(nodes).subspan(i * n, n);
520 outputs.push_back(node);
521 inputs.push_back(node);
522 }
523 }
524 if(!active.empty()) {
525 chain_gen.process(active, j, outputs, inputs);
526 }
527 }
528
529 // Prefill the final hash object
530 const auto pk_hash = params.hash();
531 pk_hash->update(identifier);
532 pk_hash->update(store_be(q));
533 pk_hash->update(store_be(D_PBLC));
534 pk_hash->update(nodes);
535 // Alg. 4b 4.
536 return pk_hash->final<LMOTS_K>();
537}
static LMOTS_Params create_or_throw(LMOTS_Algorithm_Type type)
Create the LM-OTS parameters from a known algorithm type.
Definition lm_ots.cpp:131
StrongSpan< const LMOTS_Node > y(uint16_t chain_idx) const
Returns the part of the signature for chain_idx.
Definition lm_ots.cpp:264
LMOTS_Algorithm_Type algorithm_type() const
Returns the LM-OTS algorithm type.
Definition lm_ots.h:196
std::span< const uint8_t > C() const
The n-byte randomizer of the signature.
Definition lm_ots.h:201
Strong< std::vector< uint8_t >, struct LMOTS_K_ > LMOTS_K
The K value from the LM-OTS public key.
Definition lm_ots.h:39

References Botan::LMOTS_Signature::algorithm_type(), Botan::LMOTS_Signature::C(), copy_mem(), Botan::Hash_Engine::create_or_throw(), Botan::LMOTS_Params::create_or_throw(), store_be(), and Botan::LMOTS_Signature::y().

◆ lmots_compute_pubkeys()

BOTAN_TEST_API void Botan::lmots_compute_pubkeys ( std::span< uint8_t > out_ks,
const LMOTS_Params & params,
const LMS_Identifier & identifier,
LMS_Tree_Node_Idx first_q,
size_t count,
const LMS_Seed & seed,
Hash_Engine & engine )

Compute the public key hash values K (RFC 8554 4.3) of count consecutive LM-OTS instances beginning at first_q, deriving the instances' secrets from seed. The hashing is batched across all instances' chains.

Definition at line 424 of file lm_ots.cpp.

430 {
431 BOTAN_ASSERT_NOMSG(out_ks.size() == count * params.n());
432
433 const uint16_t p = params.p();
434 const size_t n = params.n();
435 const size_t lanes = count * p;
436 BOTAN_ASSERT_NOMSG(lanes <= 0xFFFF);
437
438 secure_vector<uint8_t> nodes(lanes * n);
439
440 std::vector<uint16_t> lane_ids(lanes);
441 std::vector<std::span<uint8_t>> outputs(lanes);
442 std::vector<std::span<const uint8_t>> inputs(lanes);
443 for(size_t l = 0; l != lanes; ++l) {
444 lane_ids[l] = static_cast<uint16_t>(l);
445 outputs[l] = std::span(nodes).subspan(l * n, n);
446 inputs[l] = std::span<const uint8_t>(seed.get());
447 }
448
449 Batch_Chain_Generator chain_gen(engine, identifier, first_q, count, p);
450
451 // Derive the secret chain inputs (x[] in RFC 8554 4.2)
452 chain_gen.process(lane_ids, 0xff, outputs, inputs);
453
454 // Walk all chains of all instances to the top in lock-step
455 for(size_t l = 0; l != lanes; ++l) {
456 inputs[l] = outputs[l];
457 }
458 for(uint8_t j = 0; j < params.coef_max(); ++j) {
459 chain_gen.process(lane_ids, j, outputs, inputs);
460 }
461
462 // Compute each instance's K over its chain ends (RFC 8554 4.3)
463 const size_t k_prefix_len = identifier.size() + sizeof(uint32_t) + sizeof(uint16_t);
464 std::vector<uint8_t> k_prefixes(count * k_prefix_len);
465 std::vector<std::span<uint8_t>> k_outs(count);
466 std::vector<std::span<const uint8_t>> k_prefix_spans(count);
467 std::vector<std::span<const uint8_t>> k_nodes(count);
468 for(size_t i = 0; i != count; ++i) {
469 const auto prefix_span = std::span(k_prefixes).subspan(i * k_prefix_len, k_prefix_len);
470 BufferStuffer prefix(prefix_span);
471 prefix.append(identifier);
472 prefix.append(store_be(LMS_Tree_Node_Idx(first_q.get() + static_cast<uint32_t>(i))));
473 prefix.append(store_be(D_PBLC));
474 k_prefix_spans[i] = prefix_span;
475 k_outs[i] = out_ks.subspan(i * n, n);
476 k_nodes[i] = std::span(nodes).subspan(i * p * n, p * n);
477 }
478 engine.batch_hash(k_outs, k_prefix_spans, k_nodes);
479}
void batch_hash(std::span< std::span< uint8_t > > outputs, std::span< std::span< const uint8_t > > inputs)
Definition hash_engine.h:57
uint8_t coef_max() const
The maximum the winternitz coefficients can have.
Definition lm_ots.h:139
size_t n() const
The number of bytes of the output of the hash function.
Definition lm_ots.h:129
uint16_t p() const
The number of n-byte string elements that make up the LM-OTS signature.
Definition lm_ots.h:144
Strong< uint32_t, struct LMS_Tree_Node_Idx_, EnableArithmeticWithPlainNumber > LMS_Tree_Node_Idx
The index of a node within a specific LMS tree layer.
Definition lm_ots.h:49

References Botan::BufferStuffer::append(), Botan::Hash_Engine::batch_hash(), BOTAN_ASSERT_NOMSG, Botan::LMOTS_Params::coef_max(), Botan::detail::Strong_Base< T >::get(), Botan::LMOTS_Params::n(), Botan::LMOTS_Params::p(), Botan::detail::Container_Strong_Adapter_Base< T >::size(), and store_be().

◆ load_be()

template<typename OutT = detail::AutoDetect, typename... ParamTs>
auto Botan::load_be ( ParamTs &&... params)
inlineconstexpr

Load "something" in big endian byte order See the documentation of this file for more details.

Definition at line 504 of file loadstor.h.

504 {
505 return detail::load_any<std::endian::big, OutT>(std::forward<ParamTs>(params)...);
506}
constexpr WrappedOutT load_any(InR &&in_range)
Definition loadstor.h:278

References Botan::detail::load_any().

Referenced by Botan::IPv6Address::as_ipv4(), base58_check_decode(), bytes_to_words(), check_passhash9(), Botan::SHA_256::compress_digest(), Botan::SHA_512::compress_digest(), Botan::SHA_1::compress_n(), Botan::SM3::compress_n(), Botan::Whirlpool::compress_n(), Botan::AlternativeName::decode_from(), Botan::TLS::Session::decrypt(), Botan::CryptoBox::decrypt_bin(), Botan::Blowfish::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::Noekeon::decrypt_n(), Botan::SEED::decrypt_n(), Botan::SHACAL2::decrypt_n(), Botan::Blowfish::encrypt_n(), Botan::CAST_128::encrypt_n(), Botan::Noekeon::encrypt_n(), Botan::SEED::encrypt_n(), Botan::SHACAL2::encrypt_n(), Botan::IPv4Subnet::from_address_and_mask(), Botan::HSS_LMS_PrivateKeyInternal::from_bytes_or_throw(), Botan::HSS_LMS_PublicKeyInternal::from_bytes_or_throw(), Botan::HSS_Signature::from_bytes_or_throw(), Botan::LMOTS_Signature::from_bytes_or_throw(), Botan::LMS_PublicKey::from_bytes_or_throw(), Botan::LMS_Signature::from_bytes_or_throw(), Botan::TLS::Signature_Scheme::from_string(), Botan::HOTP::generate_hotp(), Botan::TLS::TLS_Data_Reader::get_elem(), Botan::IPv4Address::IPv4Address(), Botan::TLS::Record_TLS::legacy_version(), nist_key_unwrap(), nist_key_unwrap_padded(), Botan::TLS::Record_TLS::payload_length(), Botan::TLS::Server_Hello_12_Shim::random_signals_downgrade(), Botan::TLS::Server_Hello_13::random_signals_downgrade(), Botan::CTR_BE::seek(), Botan::TLS::Server_Impl_13::send_new_session_tickets(), ucs2_to_utf8(), ucs4_to_utf8(), and whirlpool_rc().

◆ load_block()

template<bool BSWAP>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_SIMD_4X32 SIMD_4x32 Botan::load_block ( const uint8_t in[])

Load a block in the reflected GHASH convention (BSWAP == true) or the natural POLYVAL convention (BSWAP == false)

Definition at line 87 of file polyval_fn.h.

87 {
88 if constexpr(BSWAP) {
90 } else {
91 return SIMD_4x32::load_le(in);
92 }
93}
BOTAN_FN_ISA_SIMD_4X32 SIMD_4x32 reverse_all_bytes() const
Definition simd_4x32.h:536

References BOTAN_FORCE_INLINE, Botan::SIMD_4x32::load_le(), and Botan::SIMD_4x32::reverse_all_bytes().

◆ load_le()

template<typename OutT = detail::AutoDetect, typename... ParamTs>
auto Botan::load_le ( ParamTs &&... params)
inlineconstexpr

Load "something" in little endian byte order See the documentation of this file for more details.

Definition at line 495 of file loadstor.h.

495 {
496 return detail::load_any<std::endian::little, OutT>(std::forward<ParamTs>(params)...);
497}

References Botan::detail::load_any().

Referenced by base58_decode(), Botan::BlindedScalarBits< C, WindowBits+1 >::BlindedScalarBits(), Botan::Gf448Elem::bytes_are_canonical_representation(), Botan::MD4::compress_n(), Botan::MD5::compress_n(), Botan::RIPEMD_160::compress_n(), Botan::Classic_McEliece_Field_Ordering::create_field_ordering(), Botan::Sodium::crypto_core_hsalsa20(), Botan::GCM_SIV_Mode::ctr_xor(), Botan::X25519_FE::decode(), Botan::GOST_28147_89::decrypt_n(), Botan::Kuznyechik::decrypt_n(), Botan::Serpent::decrypt_n(), Botan::Threefish_512::decrypt_n(), Botan::Twofish::decrypt_n(), Botan::Ed25519_FieldElement::deserialize(), Botan::FrodoMatrix::deserialize(), Botan::GOST_28147_89::encrypt_n(), Botan::Kuznyechik::encrypt_n(), Botan::Serpent::encrypt_n(), Botan::Threefish_512::encrypt_n(), Botan::Twofish::encrypt_n(), Botan::Dilithium_Algos::expand_A(), Botan::Classic_McEliece_Minimal_Polynomial::from_bytes(), generate_rsa_prime(), Botan::Gf448Elem::Gf448Elem(), keccak_mb_absorb_x8(), Botan::Kyber_Algos::load_le3(), Botan::FrodoMatrix::mul_add_as_plus_e(), Botan::FrodoMatrix::mul_add_sa_plus_e(), random_prime(), Botan::detail::FullWordBounds< SpongeT >::read_from(), Botan::detail::PartialWordBounds< SpongeT >::read_from(), Botan::FrodoMatrix::sample(), Botan::Dilithium_Algos::sample_in_ball(), Botan::Salsa20::set_iv_bytes(), Botan::Threefish_512::set_tweak(), Botan::Sodium::sodium_free(), Botan::bitvector_base< secure_allocator >::subvector(), Botan::CRYSTALS::unpack(), whirlpool_rc(), and xts_compute_tweak_block().

◆ load_private_key()

std::unique_ptr< Private_Key > Botan::load_private_key ( const AlgorithmIdentifier & alg_id,
std::span< const uint8_t > key_bits )

Definition at line 297 of file pk_algs.cpp.

298 {
299 const std::string alg_name = [&]() -> std::string {
300 if(const auto name = alg_id.oid().registered_name()) {
301 const std::vector<std::string> alg_info = split_on(*name, '/');
302 if(!alg_info.empty()) {
303 return alg_info[0];
304 }
305 }
306
307 throw Decoding_Error(
308 fmt("Private key decoding failed, no algorithm associated with {}", alg_id.oid().to_string()));
309 }();
310
311#if defined(BOTAN_HAS_RSA)
312 if(alg_name == "RSA") {
313 return std::make_unique<RSA_PrivateKey>(alg_id, key_bits);
314 }
315#endif
316
317#if defined(BOTAN_HAS_X25519)
318 if(alg_name == "X25519" || alg_name == "Curve25519") {
319 return std::make_unique<X25519_PrivateKey>(alg_id, key_bits);
320 }
321#endif
322
323#if defined(BOTAN_HAS_X448)
324 if(alg_name == "X448") {
325 return std::make_unique<X448_PrivateKey>(alg_id, key_bits);
326 }
327#endif
328
329#if defined(BOTAN_HAS_ECDSA)
330 if(alg_name == "ECDSA") {
331 return std::make_unique<ECDSA_PrivateKey>(alg_id, key_bits);
332 }
333#endif
334
335#if defined(BOTAN_HAS_ECDH)
336 if(alg_name == "ECDH") {
337 return std::make_unique<ECDH_PrivateKey>(alg_id, key_bits);
338 }
339#endif
340
341#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
342 if(alg_name == "DH") {
343 return std::make_unique<DH_PrivateKey>(alg_id, key_bits);
344 }
345#endif
346
347#if defined(BOTAN_HAS_DSA)
348 if(alg_name == "DSA") {
349 return std::make_unique<DSA_PrivateKey>(alg_id, key_bits);
350 }
351#endif
352
353#if defined(BOTAN_HAS_FRODOKEM)
354 if(alg_name == "FrodoKEM" || alg_name.starts_with("FrodoKEM-") || alg_name.starts_with("eFrodoKEM-")) {
355 return std::make_unique<FrodoKEM_PrivateKey>(alg_id, key_bits);
356 }
357#endif
358
359#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
360 if(alg_name == "Kyber" || alg_name.starts_with("Kyber-")) {
361 return std::make_unique<Kyber_PrivateKey>(alg_id, key_bits);
362 }
363#endif
364
365#if defined(BOTAN_HAS_ML_KEM)
366 if(alg_name.starts_with("ML-KEM-")) {
367 return std::make_unique<ML_KEM_PrivateKey>(alg_id, key_bits);
368 }
369#endif
370
371#if defined(BOTAN_HAS_MCELIECE)
372 if(alg_name == "McEliece") {
373 return std::make_unique<McEliece_PrivateKey>(alg_id, key_bits);
374 }
375#endif
376
377#if defined(BOTAN_HAS_ECGDSA)
378 if(alg_name == "ECGDSA") {
379 return std::make_unique<ECGDSA_PrivateKey>(alg_id, key_bits);
380 }
381#endif
382
383#if defined(BOTAN_HAS_ECKCDSA)
384 if(alg_name == "ECKCDSA") {
385 return std::make_unique<ECKCDSA_PrivateKey>(alg_id, key_bits);
386 }
387#endif
388
389#if defined(BOTAN_HAS_ED25519)
390 if(alg_name == "Ed25519") {
391 return std::make_unique<Ed25519_PrivateKey>(alg_id, key_bits);
392 }
393#endif
394
395#if defined(BOTAN_HAS_ED448)
396 if(alg_name == "Ed448") {
397 return std::make_unique<Ed448_PrivateKey>(alg_id, key_bits);
398 }
399#endif
400
401#if defined(BOTAN_HAS_GOST_34_10_2001)
402 if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
403 return std::make_unique<GOST_3410_PrivateKey>(alg_id, key_bits);
404 }
405#endif
406
407#if defined(BOTAN_HAS_SM2)
408 if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
409 return std::make_unique<SM2_PrivateKey>(alg_id, key_bits);
410 }
411#endif
412
413#if defined(BOTAN_HAS_ELGAMAL)
414 if(alg_name == "ElGamal") {
415 return std::make_unique<ElGamal_PrivateKey>(alg_id, key_bits);
416 }
417#endif
418
419#if defined(BOTAN_HAS_XMSS_RFC8391)
420 if(alg_name == "XMSS") {
421 return std::make_unique<XMSS_PrivateKey>(alg_id, key_bits);
422 }
423#endif
424
425#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
426 if(alg_name == "Dilithium" || alg_name.starts_with("Dilithium-")) {
427 return std::make_unique<Dilithium_PrivateKey>(alg_id, key_bits);
428 }
429#endif
430
431#if defined(BOTAN_HAS_ML_DSA)
432 if(alg_name.starts_with("ML-DSA-")) {
433 return std::make_unique<ML_DSA_PrivateKey>(alg_id, key_bits);
434 }
435#endif
436
437#if defined(BOTAN_HAS_HSS_LMS)
438 if(alg_name == "HSS-LMS-Private-Key") {
439 return std::make_unique<HSS_LMS_PrivateKey>(alg_id, key_bits);
440 }
441#endif
442
443#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
444 if(alg_name == "SPHINCS+" || alg_name.starts_with("SphincsPlus-")) {
445 return std::make_unique<SphincsPlus_PrivateKey>(alg_id, key_bits);
446 }
447#endif
448
449#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
450 if(alg_name.starts_with("SLH-DSA-") || alg_name.starts_with("Hash-SLH-DSA-")) {
451 return std::make_unique<SLH_DSA_PrivateKey>(alg_id, key_bits);
452 }
453#endif
454
455#if defined(BOTAN_HAS_CLASSICMCELIECE)
456 if(alg_name.starts_with("ClassicMcEliece")) {
457 return std::make_unique<Classic_McEliece_PrivateKey>(alg_id, key_bits);
458 }
459#endif
460
461 throw Decoding_Error(fmt("Unknown or unavailable public key algorithm '{}'", alg_name));
462}
const OID & oid() const
Definition asn1_obj.h:688
std::optional< std::string > registered_name() const
Definition asn1_oid.cpp:149
std::string to_string() const
Definition asn1_oid.cpp:123

References fmt(), name, Botan::AlgorithmIdentifier::oid(), Botan::OID::registered_name(), split_on(), and Botan::OID::to_string().

◆ load_public_key()

std::unique_ptr< Public_Key > Botan::load_public_key ( const AlgorithmIdentifier & alg_id,
std::span< const uint8_t > key_bits )

Definition at line 130 of file pk_algs.cpp.

131 {
132 const std::string alg_name = [&]() -> std::string {
133 if(const auto name = alg_id.oid().registered_name()) {
134 const std::vector<std::string> alg_info = split_on(*name, '/');
135 if(!alg_info.empty()) {
136 return alg_info[0];
137 }
138 }
139
140 throw Decoding_Error(
141 fmt("Public key decoding failed, no algorithm associated with {}", alg_id.oid().to_string()));
142 }();
143
144#if defined(BOTAN_HAS_RSA)
145 if(alg_name == "RSA") {
146 return std::make_unique<RSA_PublicKey>(alg_id, key_bits);
147 }
148#endif
149
150#if defined(BOTAN_HAS_X25519)
151 if(alg_name == "X25519" || alg_name == "Curve25519") {
152 return std::make_unique<X25519_PublicKey>(alg_id, key_bits);
153 }
154#endif
155
156#if defined(BOTAN_HAS_X448)
157 if(alg_name == "X448") {
158 return std::make_unique<X448_PublicKey>(alg_id, key_bits);
159 }
160#endif
161
162#if defined(BOTAN_HAS_MCELIECE)
163 if(alg_name == "McEliece") {
164 return std::make_unique<McEliece_PublicKey>(alg_id, key_bits);
165 }
166#endif
167
168#if defined(BOTAN_HAS_FRODOKEM)
169 if(alg_name == "FrodoKEM" || alg_name.starts_with("FrodoKEM-") || alg_name.starts_with("eFrodoKEM-")) {
170 return std::make_unique<FrodoKEM_PublicKey>(alg_id, key_bits);
171 }
172#endif
173
174#if defined(BOTAN_HAS_KYBER) || defined(BOTAN_HAS_KYBER_90S)
175 if(alg_name == "Kyber" || alg_name.starts_with("Kyber-")) {
176 return std::make_unique<Kyber_PublicKey>(alg_id, key_bits);
177 }
178#endif
179
180#if defined(BOTAN_HAS_ML_KEM)
181 if(alg_name.starts_with("ML-KEM-")) {
182 return std::make_unique<ML_KEM_PublicKey>(alg_id, key_bits);
183 }
184#endif
185
186#if defined(BOTAN_HAS_ECDSA)
187 if(alg_name == "ECDSA") {
188 return std::make_unique<ECDSA_PublicKey>(alg_id, key_bits);
189 }
190#endif
191
192#if defined(BOTAN_HAS_ECDH)
193 if(alg_name == "ECDH") {
194 return std::make_unique<ECDH_PublicKey>(alg_id, key_bits);
195 }
196#endif
197
198#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
199 if(alg_name == "DH") {
200 return std::make_unique<DH_PublicKey>(alg_id, key_bits);
201 }
202#endif
203
204#if defined(BOTAN_HAS_DSA)
205 if(alg_name == "DSA") {
206 return std::make_unique<DSA_PublicKey>(alg_id, key_bits);
207 }
208#endif
209
210#if defined(BOTAN_HAS_ELGAMAL)
211 if(alg_name == "ElGamal") {
212 return std::make_unique<ElGamal_PublicKey>(alg_id, key_bits);
213 }
214#endif
215
216#if defined(BOTAN_HAS_ECGDSA)
217 if(alg_name == "ECGDSA") {
218 return std::make_unique<ECGDSA_PublicKey>(alg_id, key_bits);
219 }
220#endif
221
222#if defined(BOTAN_HAS_ECKCDSA)
223 if(alg_name == "ECKCDSA") {
224 return std::make_unique<ECKCDSA_PublicKey>(alg_id, key_bits);
225 }
226#endif
227
228#if defined(BOTAN_HAS_ED25519)
229 if(alg_name == "Ed25519") {
230 return std::make_unique<Ed25519_PublicKey>(alg_id, key_bits);
231 }
232#endif
233
234#if defined(BOTAN_HAS_ED448)
235 if(alg_name == "Ed448") {
236 return std::make_unique<Ed448_PublicKey>(alg_id, key_bits);
237 }
238#endif
239
240#if defined(BOTAN_HAS_GOST_34_10_2001)
241 if(alg_name == "GOST-34.10" || alg_name == "GOST-34.10-2012-256" || alg_name == "GOST-34.10-2012-512") {
242 return std::make_unique<GOST_3410_PublicKey>(alg_id, key_bits);
243 }
244#endif
245
246#if defined(BOTAN_HAS_SM2)
247 if(alg_name == "SM2" || alg_name == "SM2_Sig" || alg_name == "SM2_Enc") {
248 return std::make_unique<SM2_PublicKey>(alg_id, key_bits);
249 }
250#endif
251
252#if defined(BOTAN_HAS_XMSS_RFC8391)
253 if(alg_name == "XMSS") {
254 return std::make_unique<XMSS_PublicKey>(alg_id, key_bits);
255 }
256#endif
257
258#if defined(BOTAN_HAS_DILITHIUM) || defined(BOTAN_HAS_DILITHIUM_AES)
259 if(alg_name == "Dilithium" || alg_name.starts_with("Dilithium-")) {
260 return std::make_unique<Dilithium_PublicKey>(alg_id, key_bits);
261 }
262#endif
263
264#if defined(BOTAN_HAS_ML_DSA)
265 if(alg_name.starts_with("ML-DSA-")) {
266 return std::make_unique<ML_DSA_PublicKey>(alg_id, key_bits);
267 }
268#endif
269
270#if defined(BOTAN_HAS_HSS_LMS)
271 if(alg_name == "HSS-LMS") {
272 return std::make_unique<HSS_LMS_PublicKey>(alg_id, key_bits);
273 }
274#endif
275
276#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
277 if(alg_name == "SPHINCS+" || alg_name.starts_with("SphincsPlus-")) {
278 return std::make_unique<SphincsPlus_PublicKey>(alg_id, key_bits);
279 }
280#endif
281
282#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
283 if(alg_name.starts_with("SLH-DSA-") || alg_name.starts_with("Hash-SLH-DSA-")) {
284 return std::make_unique<SLH_DSA_PublicKey>(alg_id, key_bits);
285 }
286#endif
287
288#if defined(BOTAN_HAS_CLASSICMCELIECE)
289 if(alg_name.starts_with("ClassicMcEliece")) {
290 return std::make_unique<Classic_McEliece_PublicKey>(alg_id, key_bits);
291 }
292#endif
293
294 throw Decoding_Error(fmt("Unknown or unavailable public key algorithm '{}'", alg_name));
295}

References fmt(), name, Botan::AlgorithmIdentifier::oid(), Botan::OID::registered_name(), split_on(), and Botan::OID::to_string().

Referenced by Botan::TLS::Hybrid_KEM_PublicKey::load_for_group(), and Botan::X509::load_key().

◆ lock()

◆ low_zero_bits()

size_t Botan::low_zero_bits ( const BigInt & x)

Count the low zero bits of an integer

Parameters
xan integer
Returns
count of the low zero bits in x, or, equivalently, the largest value of n such that 2^n divides x evenly. Returns zero if x is equal to zero.

Definition at line 194 of file numthry.cpp.

194 {
195 size_t low_zero = 0;
196
197 auto seen_nonempty_word = CT::Mask<word>::cleared();
198
199 for(size_t i = 0; i != n.size(); ++i) {
200 const word x = n.word_at(i);
201
202 // ctz(0) will return sizeof(word)
203 const size_t tz_x = ctz(x);
204
205 // if x > 0 we want to count tz_x in total but not any
206 // further words, so set the mask after the addition
207 low_zero += seen_nonempty_word.if_not_set_return(tz_x);
208
209 seen_nonempty_word |= CT::Mask<word>::expand(x);
210 }
211
212 // if we saw no words with x > 0 then n == 0 and the value we have
213 // computed is meaningless. Instead return BigInt::zero() in that case.
214 return static_cast<size_t>(seen_nonempty_word.if_set_return(low_zero));
215}
static constexpr Mask< T > cleared()
Definition ct_utils.h:392
BOTAN_FORCE_INLINE constexpr size_t ctz(T n)
Definition bit_ops.h:115

References Botan::CT::Mask< T >::cleared(), ctz(), Botan::CT::Mask< T >::expand(), Botan::BigInt::size(), and Botan::BigInt::word_at().

Referenced by inverse_mod_general(), jacobi(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and sqrt_modulo_prime().

◆ majority()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::majority ( T a,
T b,
T c )
constexpr

Definition at line 223 of file bit_ops.h.

223 {
224 /*
225 Considering each bit of a, b, c individually
226
227 If a xor b is set, then c is the deciding vote.
228
229 If a xor b is not set then either a and b are both set or both unset.
230 In either case the value of c doesn't matter, and examining b (or a)
231 allows us to determine which case we are in.
232 */
233 return choose(a ^ b, c, b);
234}
BOTAN_FORCE_INLINE constexpr T choose(T mask, T a, T b)
Definition bit_ops.h:217

References BOTAN_FORCE_INLINE, and choose().

Referenced by Botan::SHA1_F::F3(), R2(), SHA2_32_F(), SHA2_32_F(), SHA2_64_F(), and SHA2_64_F().

◆ make_commoncrypto_block_cipher()

std::unique_ptr< BlockCipher > Botan::make_commoncrypto_block_cipher ( std::string_view name)

Definition at line 133 of file commoncrypto_block.cpp.

133 {
134 try {
136 return std::make_unique<CommonCrypto_BlockCipher>(name, opts);
137 } catch(CommonCrypto_Error& e) {
138 return nullptr;
139 }
140}

References commoncrypto_opts_from_algo_name(), make_commoncrypto_block_cipher(), and name.

Referenced by Botan::BlockCipher::create(), and make_commoncrypto_block_cipher().

◆ make_commoncrypto_cipher_mode()

std::unique_ptr< Cipher_Mode > Botan::make_commoncrypto_cipher_mode ( std::string_view name,
Cipher_Dir direction )

Definition at line 215 of file commoncrypto_mode.cpp.

215 {
216 try {
218 return std::make_unique<CommonCrypto_Cipher_Mode>(name, direction, opts);
219 } catch(CommonCrypto_Error& e) {
220 return nullptr;
221 }
222}
CommonCryptor_Opts commoncrypto_opts_from_algo(std::string_view algo)

References commoncrypto_opts_from_algo(), make_commoncrypto_cipher_mode(), and name.

Referenced by Botan::Cipher_Mode::create(), and make_commoncrypto_cipher_mode().

◆ make_commoncrypto_hash()

std::unique_ptr< HashFunction > Botan::make_commoncrypto_hash ( std::string_view name)

Definition at line 88 of file commoncrypto_hash.cpp.

88 {
89#define MAKE_COMMONCRYPTO_HASH_3(name, hash, ctx) \
90 std::unique_ptr<HashFunction>(new CommonCrypto_HashFunction<CC_##ctx##_CTX>({std::string(name), \
91 CC_##hash##_DIGEST_LENGTH, \
92 CC_##hash##_BLOCK_BYTES, \
93 CC_##hash##_Init, \
94 CC_##hash##_Update, \
95 CC_##hash##_Final}));
96
97#define MAKE_COMMONCRYPTO_HASH_2(name, id) MAKE_COMMONCRYPTO_HASH_3(name, id, id)
98
99#define MAKE_COMMONCRYPTO_HASH_1(id) MAKE_COMMONCRYPTO_HASH_2(#id, id)
100
101#if defined(BOTAN_HAS_SHA2_32)
102 if(name == "SHA-224")
103 return MAKE_COMMONCRYPTO_HASH_3(name, SHA224, SHA256);
104 if(name == "SHA-256")
105 return MAKE_COMMONCRYPTO_HASH_2(name, SHA256);
106#endif
107#if defined(BOTAN_HAS_SHA2_64)
108 if(name == "SHA-384")
109 return MAKE_COMMONCRYPTO_HASH_3(name, SHA384, SHA512);
110 if(name == "SHA-512")
111 return MAKE_COMMONCRYPTO_HASH_2(name, SHA512);
112#endif
113
114#if defined(BOTAN_HAS_SHA1)
115 if(name == "SHA-1")
116 return MAKE_COMMONCRYPTO_HASH_2(name, SHA1);
117#endif
118
119 return nullptr;
120}
#define MAKE_COMMONCRYPTO_HASH_2(name, id)
#define MAKE_COMMONCRYPTO_HASH_3(name, hash, ctx)

References MAKE_COMMONCRYPTO_HASH_2, MAKE_COMMONCRYPTO_HASH_3, and name.

Referenced by Botan::HashFunction::create().

◆ make_compressor()

Compression_Algorithm * Botan::make_compressor ( std::string_view type)
inline

Create a compression algorithm by name

Parameters
typethe algorithm to create
Returns
the new object, or nullptr if not available

Definition at line 160 of file compression.h.

160 {
161 return Compression_Algorithm::create(type).release();
162}
static std::unique_ptr< Compression_Algorithm > create(std::string_view algo_spec)

References Botan::Compression_Algorithm::create(), and make_compressor().

Referenced by make_compressor().

◆ make_decompressor()

Decompression_Algorithm * Botan::make_decompressor ( std::string_view type)
inline

Create a decompression algorithm by name

Parameters
typethe algorithm to create
Returns
the new object, or nullptr if not available

Definition at line 170 of file compression.h.

170 {
171 return Decompression_Algorithm::create(type).release();
172}
static std::unique_ptr< Decompression_Algorithm > create(std::string_view algo_spec)

References Botan::Decompression_Algorithm::create(), and make_decompressor().

Referenced by make_decompressor().

◆ make_monty_exp_avx512()

std::unique_ptr< Montgomery_Exponentiation_State > Botan::make_monty_exp_avx512 ( const Montgomery_Int & g,
size_t window_bits )

Montgomery exponentiation using AVX-512 IFMA

Returns nullptr if the CPU or the size of the modulus is not supported

Definition at line 611 of file monty_exp_avx512.cpp.

611 {
612 const size_t vectors = (ifma_digits(g._params().p().bits()) + 7) / 8;
613
614 switch(vectors) {
615 case 2: /* 415 - 830 bits */
616 return make_monty_exp<2>(g, window_bits);
617 case 3: /* 831 - 1246 bits */
618 return make_monty_exp<3>(g, window_bits);
619 case 4: /* 1247 - 1662 bits */
620 return make_monty_exp<4>(g, window_bits);
621 case 5: /* 1663 - 2078 bits */
622 return make_monty_exp<5>(g, window_bits);
623 case 6: /* 2079 - 2494 bits */
624 return make_monty_exp<6>(g, window_bits);
625 case 7: /* 2495 - 2910 bits */
626 return make_monty_exp<7>(g, window_bits);
627 case 8: /* 2911 - 3326 bits */
628 return make_monty_exp<8>(g, window_bits);
629 case 9: /* 3327 - 3742 bits */
630 return make_monty_exp<9>(g, window_bits);
631 case 10: /* 3743 - 4158 bits */
632 return make_monty_exp<10>(g, window_bits);
633 default:
634 // Moduli under 415 bits or over 4158 bits do not seem of practical interest
635 return nullptr;
636 }
637}
const Montgomery_Params & _params() const
Definition monty.h:216
const BigInt & p() const
Definition monty.h:41

References Botan::Montgomery_Int::_params(), Botan::BigInt::bits(), make_monty_exp_avx512(), and Botan::Montgomery_Params::p().

Referenced by make_monty_exp_avx512(), and monty_precompute().

◆ make_uint16()

uint16_t Botan::make_uint16 ( uint8_t i0,
uint8_t i1 )
inlineconstexpr

Make a uint16_t from two bytes

Parameters
i0the first byte
i1the second byte
Returns
i0 || i1

Definition at line 92 of file loadstor.h.

92 {
93 return static_cast<uint16_t>((static_cast<uint16_t>(i0) << 8) | i1);
94}

Referenced by Botan::TLS::Certificate_Request_12::Certificate_Request_12(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), Botan::ML_KEM_Symmetric_Primitives::init_XOF(), Botan::TLS::TLS_Data_Reader::peek_uint16_t(), random_gf2m(), Botan::RTSS_Share::reconstruct(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::set_associated_data_n(), and Botan::IPv6Address::to_string().

◆ make_uint32()

uint32_t Botan::make_uint32 ( uint8_t i0,
uint8_t i1,
uint8_t i2,
uint8_t i3 )
inlineconstexpr

Make a uint32_t from four bytes

Parameters
i0the first byte
i1the second byte
i2the third byte
i3the fourth byte
Returns
i0 || i1 || i2 || i3

Definition at line 104 of file loadstor.h.

104 {
105 return ((static_cast<uint32_t>(i0) << 24) | (static_cast<uint32_t>(i1) << 16) | (static_cast<uint32_t>(i2) << 8) |
106 (static_cast<uint32_t>(i3)));
107}

Referenced by Botan::TLS::Certificate_12::Certificate_12(), Botan::TLS::Certificate_Status::Certificate_Status(), Botan::TLS::Stream_Handshake_IO::get_next_record(), Botan::TLS::TLS_Data_Reader::get_uint24_t(), Botan::TLS::TLS_Data_Reader::get_uint32_t(), and Botan::McEliece_PrivateKey::McEliece_PrivateKey().

◆ make_uint64()

uint64_t Botan::make_uint64 ( uint8_t i0,
uint8_t i1,
uint8_t i2,
uint8_t i3,
uint8_t i4,
uint8_t i5,
uint8_t i6,
uint8_t i7 )
inlineconstexpr

Make a uint64_t from eight bytes

Parameters
i0the first byte
i1the second byte
i2the third byte
i3the fourth byte
i4the fifth byte
i5the sixth byte
i6the seventh byte
i7the eighth byte
Returns
i0 || i1 || i2 || i3 || i4 || i5 || i6 || i7

Definition at line 121 of file loadstor.h.

122 {
123 return ((static_cast<uint64_t>(i0) << 56) | (static_cast<uint64_t>(i1) << 48) | (static_cast<uint64_t>(i2) << 40) |
124 (static_cast<uint64_t>(i3) << 32) | (static_cast<uint64_t>(i4) << 24) | (static_cast<uint64_t>(i5) << 16) |
125 (static_cast<uint64_t>(i6) << 8) | (static_cast<uint64_t>(i7)));
126}

◆ map_remove_if()

template<typename T, typename Pred>
void Botan::map_remove_if ( Pred pred,
T & assoc )

Definition at line 54 of file stl_util.h.

54 {
55 auto i = assoc.begin();
56 while(i != assoc.end()) {
57 if(pred(i->first)) {
58 assoc.erase(i++);
59 } else {
60 i++;
61 }
62 }
63}

Referenced by Botan::TLS::Channel_Impl_12::activate_session().

◆ map_to_curve_sswu()

template<typename C>
auto Botan::map_to_curve_sswu ( const typename C::FieldElement & u) -> typename C::AffinePoint
inline

Map to curve (SSWU)

See RFC 9380 ("Hashing to Elliptic Curves") section 6.6.2

Definition at line 1874 of file pcurves_impl.h.

1874 {
1875 CT::poison(u);
1876 const auto z_u2 = C::SSWU_Z * u.square(); // z * u^2
1877 const auto z2_u4 = z_u2.square();
1878 const auto tv1 = invert_field_element<C>(z2_u4 + z_u2);
1879 auto x1 = SSWU_C1<C>() * (C::FieldElement::one() + tv1);
1880 x1.conditional_assign(tv1.is_zero(), SSWU_C2<C>());
1881 const auto x2 = z_u2 * x1;
1882
1883 // By design one of gx1 and gx2 must be a quadratic residue
1886
1887 const auto use_y1 = y1.has_value();
1888
1889 const auto x = C::FieldElement::choose(use_y1, x1, x2);
1890 const auto y =
1891 C::FieldElement::choose(use_y1, y1.value_or(C::FieldElement::zero()), y2.value_or(C::FieldElement::zero()));
1892
1893 auto pt = typename C::AffinePoint(x, y.correct_sign(u.is_even()));
1894
1895 CT::unpoison(pt);
1896 return pt;
1897}
constexpr Choice has_value() const
Return true if this Option contains a value.
Definition ct_utils.h:669
constexpr T value_or(T other) const
Definition ct_utils.h:693
constexpr CT::Option< typename C::FieldElement > sqrt_field_element(const typename C::FieldElement &fe)
const auto & SSWU_C1()
constexpr auto invert_field_element(const typename C::FieldElement &fe)
const auto & SSWU_C2()

References Botan::CT::Option< T >::has_value(), invert_field_element(), Botan::CT::poison(), sqrt_field_element(), SSWU_C1(), SSWU_C2(), Botan::CT::unpoison(), and Botan::CT::Option< T >::value_or().

Referenced by hash_to_curve_sswu().

◆ mceliece_decrypt() [1/3]

secure_vector< uint8_t > Botan::mceliece_decrypt ( secure_vector< gf2m > & error_pos,
const uint8_t * ciphertext,
size_t ciphertext_len,
const McEliece_PrivateKeyInternal & key )

p_err_pos_len must point to the available length of error_pos on input, the function will set it to the actual number of errors returned in the error_pos array

Definition at line 146 of file goppa_code.cpp.

149 {
150 const size_t dimension = key.dimension();
151 const size_t codimension = key.codimension();
152 const uint32_t t = key.goppa_polyn().get_degree();
153 polyn_gf2m syndrome_polyn(key.goppa_polyn().get_sp_field()); // init as zero polyn
154 const unsigned unused_pt_bits = dimension % 8;
155 const uint8_t unused_pt_bits_mask = (1 << unused_pt_bits) - 1;
156
157 if(ciphertext_len != (key.code_length() + 7) / 8) {
158 throw Invalid_Argument("wrong size of McEliece ciphertext");
159 }
160 const size_t cleartext_len = (key.message_word_bit_length() + 7) / 8;
161
162 if(cleartext_len != bit_size_to_byte_size(dimension)) {
163 throw Invalid_Argument("mce-decryption: wrong length of cleartext buffer");
164 }
165
166 secure_vector<uint32_t> syndrome_vec(bit_size_to_32bit_size(codimension));
167 matrix_arr_mul(key.H_coeffs(),
168 key.code_length(),
169 bit_size_to_32bit_size(codimension),
170 ciphertext,
171 syndrome_vec.data(),
172 syndrome_vec.size());
173
174 secure_vector<uint8_t> syndrome_byte_vec(bit_size_to_byte_size(codimension));
175 const size_t syndrome_byte_vec_size = syndrome_byte_vec.size();
176 for(size_t i = 0; i < syndrome_byte_vec_size; i++) {
177 syndrome_byte_vec[i] = static_cast<uint8_t>(syndrome_vec[i / 4] >> (8 * (i % 4)));
178 }
179
180 syndrome_polyn =
181 polyn_gf2m(t - 1, syndrome_byte_vec.data(), bit_size_to_byte_size(codimension), key.goppa_polyn().get_sp_field());
182
183 syndrome_polyn.get_degree();
184 error_pos = goppa_decode(syndrome_polyn, key.goppa_polyn(), key.sqrtmod(), key.Linv());
185
186 const size_t nb_err = error_pos.size();
187
188 secure_vector<uint8_t> cleartext(cleartext_len);
189 copy_mem(cleartext.data(), ciphertext, cleartext_len);
190
191 for(size_t i = 0; i < nb_err; i++) {
192 const gf2m current = error_pos[i];
193
194 if(current >= cleartext_len * 8) {
195 // an invalid position, this shouldn't happen
196 continue;
197 }
198 cleartext[current / 8] ^= (1 << (current % 8));
199 }
200
201 if(unused_pt_bits > 0) {
202 cleartext[cleartext_len - 1] &= unused_pt_bits_mask;
203 }
204
205 return cleartext;
206}
const std::vector< polyn_gf2m > & sqrtmod() const
const std::vector< uint32_t > & H_coeffs() const
const std::vector< gf2m > & Linv() const
const polyn_gf2m & goppa_polyn() const
int get_degree() const
std::shared_ptr< GF2m_Field > get_sp_field() const
Definition polyn_gf2m.h:79
size_t bit_size_to_byte_size(size_t bit_size)

References bit_size_to_32bit_size(), bit_size_to_byte_size(), Botan::McEliece_PrivateKeyInternal::code_length(), Botan::McEliece_PrivateKeyInternal::codimension(), copy_mem(), Botan::McEliece_PrivateKeyInternal::dimension(), Botan::polyn_gf2m::get_degree(), Botan::polyn_gf2m::get_sp_field(), Botan::McEliece_PrivateKeyInternal::goppa_polyn(), Botan::McEliece_PrivateKeyInternal::H_coeffs(), Botan::McEliece_PrivateKeyInternal::Linv(), Botan::McEliece_PrivateKeyInternal::message_word_bit_length(), and Botan::McEliece_PrivateKeyInternal::sqrtmod().

◆ mceliece_decrypt() [2/3]

void Botan::mceliece_decrypt ( secure_vector< uint8_t > & plaintext,
secure_vector< uint8_t > & error_mask,
const uint8_t ciphertext[],
size_t ciphertext_len,
const McEliece_PrivateKeyInternal & key )

Definition at line 122 of file goppa_code.cpp.

126 {
127 secure_vector<gf2m> error_pos;
128 plaintext = mceliece_decrypt(error_pos, ciphertext, ciphertext_len, key);
129
130 const size_t code_length = key.code_length();
131 secure_vector<uint8_t> result((code_length + 7) / 8);
132 for(auto&& pos : error_pos) {
133 if(pos >= code_length) {
134 throw Invalid_Argument("error position larger than code size");
135 }
136 result[pos / 8] |= (1 << (pos % 8));
137 }
138
139 error_mask = result;
140}
void mceliece_decrypt(secure_vector< uint8_t > &plaintext_out, secure_vector< uint8_t > &error_mask_out, const secure_vector< uint8_t > &ciphertext, const McEliece_PrivateKeyInternal &key)

References Botan::McEliece_PrivateKeyInternal::code_length(), and mceliece_decrypt().

◆ mceliece_decrypt() [3/3]

void Botan::mceliece_decrypt ( secure_vector< uint8_t > & plaintext_out,
secure_vector< uint8_t > & error_mask_out,
const secure_vector< uint8_t > & ciphertext,
const McEliece_PrivateKeyInternal & key )

Definition at line 115 of file goppa_code.cpp.

118 {
119 mceliece_decrypt(plaintext_out, error_mask_out, ciphertext.data(), ciphertext.size(), key);
120}

References mceliece_decrypt().

Referenced by Botan::McEliece_PrivateKey::check_key(), mceliece_decrypt(), and mceliece_decrypt().

◆ mceliece_encrypt()

void Botan::mceliece_encrypt ( secure_vector< uint8_t > & ciphertext_out,
secure_vector< uint8_t > & error_mask_out,
const secure_vector< uint8_t > & plaintext,
const McEliece_PublicKeyInternal & key,
RandomNumberGenerator & rng )

Definition at line 119 of file mceliece.cpp.

123 {
124 const uint16_t code_length = static_cast<uint16_t>(key.code_length());
125
126 secure_vector<uint8_t> error_mask = create_random_error_vector(code_length, key.t(), rng);
127
128 secure_vector<uint8_t> ciphertext = mult_by_pubkey(plaintext, key.public_matrix(), key.code_length(), key.t());
129
130 ciphertext ^= error_mask;
131
132 ciphertext_out.swap(ciphertext);
133 error_mask_out.swap(error_mask);
134}
const std::vector< uint8_t > & public_matrix() const

References Botan::McEliece_PublicKeyInternal::code_length(), Botan::McEliece_PublicKeyInternal::public_matrix(), and Botan::McEliece_PublicKeyInternal::t().

Referenced by Botan::McEliece_PrivateKey::check_key().

◆ mceliece_validate_key_params()

McEliece_Params Botan::mceliece_validate_key_params ( size_t code_length,
size_t t )

Definition at line 168 of file mceliece_key.cpp.

168 {
169 if(!mceliece_params_are_supported(code_length, t)) {
170 throw Decoding_Error("Unsupported McEliece parameters");
171 }
172
173 const size_t ext_deg = ceil_log2(code_length);
174 if(ext_deg < 2 || ext_deg > 15) {
175 throw Decoding_Error("McEliece code length out of supported range");
176 }
177
178 const size_t codimension = ext_deg * t;
179 if(codimension >= code_length) {
180 throw Decoding_Error("McEliece parameters are inconsistent");
181 }
182
183 const size_t dimension = code_length - codimension;
184 const size_t words_per_matrix_row = bit_size_to_32bit_size(codimension);
185 const size_t public_matrix_bytes = dimension * words_per_matrix_row * sizeof(uint32_t);
186
187 return McEliece_Params{code_length, t, ext_deg, codimension, dimension, words_per_matrix_row, public_matrix_bytes};
188}

References bit_size_to_32bit_size(), and ceil_log2().

Referenced by Botan::McEliece_PublicKey::check_key(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), and mceliece_validate_keygen_params().

◆ mceliece_validate_keygen_params()

McEliece_Params Botan::mceliece_validate_keygen_params ( size_t code_length,
size_t t )

Definition at line 190 of file mceliece_key.cpp.

190 {
191 // Requesting unsupported parameters for key generation is a caller error
192 // rather than malformed key material
193 if(!mceliece_params_are_supported(code_length, t)) {
194 throw Invalid_Argument("Unsupported McEliece parameters");
195 }
196 return mceliece_validate_key_params(code_length, t);
197}
McEliece_Params mceliece_validate_key_params(size_t code_length, size_t t)

References mceliece_validate_key_params().

Referenced by generate_mceliece_key(), and Botan::McEliece_PrivateKey::McEliece_PrivateKey().

◆ mceliece_work_factor()

size_t Botan::mceliece_work_factor ( size_t code_size,
size_t t )

Estimate work factor for McEliece

Returns
estimated security level for these key parameters

Definition at line 90 of file mce_workfactor.cpp.

90 {
91 const size_t k = n - ceil_log2(n) * t;
92
93 double min = cout_total(n, k, t, 0, 0); // correspond a p=1
94 for(size_t p = 0; p != t / 2; ++p) {
95 const double lwf = best_wf(n, k + 1, t, p);
96 if(lwf < 0) {
97 break;
98 }
99
100 min = std::min(min, lwf);
101 }
102
103 return static_cast<size_t>(min);
104}

References ceil_log2().

Referenced by Botan::McEliece_PublicKey::estimated_strength().

◆ measure_cost()

template<typename F>
uint64_t Botan::measure_cost ( uint64_t trial_msec,
F func )

Estimate the cost, in nanoseconds, of a single invocation of func

Runs func repeatedly for roughly trial_msec (but always at least a few times) and returns the fastest invocation observed. Interference from other processes or threads can only ever make an invocation slower, so the minimum is the best estimate of the cost of the work itself. Each invocation is timed using the CPU time of the calling thread where available, otherwise using a monotonic clock.

Definition at line 34 of file time_utils.h.

34 {
35#if defined(BOTAN_TARGET_OS_HAS_SYSTEM_CLOCK)
36 auto steady_ns = []() -> uint64_t {
37 const auto now = std::chrono::steady_clock::now().time_since_epoch();
38 return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(now).count());
39 };
40
41 auto thread_cpu_ns = []() -> std::optional<uint64_t> {
42 #if defined(BOTAN_HAS_OS_UTILS)
44 #else
45 return std::nullopt;
46 #endif
47 };
48
49 bool use_cpu_time = thread_cpu_ns().has_value();
50
51 const auto sample_ns = [&]() -> uint64_t {
52 if(use_cpu_time) {
53 return thread_cpu_ns().value_or(0);
54 }
55 return steady_ns();
56 };
57
58 constexpr size_t min_samples = 3;
59 const uint64_t trial_nsec = trial_msec * 1000000;
60 const uint64_t trial_start = steady_ns();
61
62 uint64_t best = std::numeric_limits<uint64_t>::max();
63 size_t samples = 0;
64
65 for(;;) {
66 const uint64_t start = sample_ns();
67 func();
68 const uint64_t end = sample_ns();
69
70 if(end > start) {
71 best = std::min(best, end - start);
72 samples += 1;
73 } else if(use_cpu_time) {
74 // The thread CPU clock cannot resolve a single invocation
75 use_cpu_time = false;
76 }
77
78 if(samples >= min_samples && (steady_ns() - trial_start) >= trial_nsec) {
79 return best;
80 }
81 }
82
83#else
84 BOTAN_UNUSED(trial_msec, func);
85 throw Not_Implemented("No system clock available");
86#endif
87}
std::optional< uint64_t > BOTAN_TEST_API get_thread_cpu_time_ns()
Definition os_utils.cpp:345

References BOTAN_UNUSED, and Botan::OS::get_thread_cpu_time_ns().

Referenced by Botan::Argon2_Family::tune_params(), Botan::Bcrypt_PBKDF_Family::tune_params(), Botan::PKCS12_KDF_Family::tune_params(), Botan::RFC4880_S2K_Family::tune_params(), and Botan::Scrypt_Family::tune_params().

◆ mgf1_mask()

void Botan::mgf1_mask ( HashFunction & hash,
std::span< const uint8_t > input,
std::span< uint8_t > output )

MGF1 from PKCS #1 v2.0

Parameters
Hasheshash function to use
input- the input buffer
output- the output buffer. The buffer is XORed with the output of MGF1.

Definition at line 15 of file mgf1.cpp.

15 {
16 uint32_t counter = 0;
17
18 const size_t hlen = hash.output_length();
19
20 BOTAN_ASSERT_NOMSG(hlen > 0);
21
22 std::vector<uint8_t> buffer(hlen);
23 while(!output.empty()) {
24 hash.update(input);
25 hash.update_be(counter);
26 hash.final(buffer);
27
28 const size_t xored = std::min<size_t>(buffer.size(), output.size());
29 xor_buf(output.first(xored), std::span{buffer}.first(xored));
30 output = output.subspan(xored);
31
32 ++counter;
33 }
34}
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
Definition mem_ops.h:403

References BOTAN_ASSERT_NOMSG, Botan::Buffered_Computation::final(), Botan::Buffered_Computation::output_length(), Botan::Buffered_Computation::update(), Botan::Buffered_Computation::update_be(), and xor_buf().

◆ miller_rabin_test_iterations()

size_t Botan::miller_rabin_test_iterations ( size_t n_bits,
size_t prob,
bool random )

Return required number of Miller-Rabin tests in order to reach the specified probability of error.

Parameters
n_bitsthe bit-length of the integer being tested
probchance of false positive is bounded by 1/2**prob
randomis set if (and only if) the integer was randomly generated by us and thus cannot have been maliciously constructed.

Definition at line 513 of file primality.cpp.

513 {
514 // Cap prob at 512 bits as _way_ more than enough; a random fault causing
515 // false accept is much more likely to occur than an actual 2^-512 event is.
516
517 prob = std::min<size_t>(512, prob);
518
519 const size_t base = (prob + 2) / 2; // worst case 4^-t error rate
520
521 /*
522 * If the candidate prime was maliciously constructed, we can't rely
523 * on arguments based on p being random.
524 */
525 if(!random) {
526 return base;
527 }
528
529 /*
530 * For randomly chosen numbers we can use the estimates from
531 * http://www.math.dartmouth.edu/~carlp/PDF/paper88.pdf
532 *
533 * These values are derived from the inequality for p(k,t) given on
534 * the second page.
535 */
536 if(prob <= 128) {
537 if(n_bits >= 1536) {
538 return 4; // < 2^-133
539 }
540 if(n_bits >= 1024) {
541 return 6; // < 2^-133
542 }
543 if(n_bits >= 512) {
544 return 12; // < 2^-129
545 }
546 if(n_bits >= 256) {
547 return 29; // < 2^-128
548 }
549 }
550
551 /*
552 If the user desires a smaller error probability than we have
553 precomputed error estimates for, just fall back to using the worst
554 case error rate.
555 */
556 return base;
557}

Referenced by generate_rsa_prime().

◆ mod_small_primes() [1/2]

std::vector< word > Botan::mod_small_primes ( const BigInt & n,
size_t num_primes )

Compute the residues of n modulo the first num_primes small odd primes

Returns a vector r of length num_primes where r[i] == n % PRIMES[i]

This is constant time with respect to the value of n; the primes are public, and num_primes and the word length of n are leaked.

Parameters
na non-negative integer
num_primesnumber of primes to reduce by, at most PRIME_TABLE_SIZE

Definition at line 493 of file primes.cpp.

493 {
494 BOTAN_ARG_CHECK(num_primes > 0 && num_primes <= PRIME_TABLE_SIZE, "Invalid num_primes");
495 BOTAN_ARG_CHECK(n.signum() >= 0, "The argument n must be non-negative");
496
497 const auto& divisors = Small_Prime_Divisors::instance();
498
499 std::vector<word> residues(num_primes);
500
501 const size_t n_words = n.sig_words();
502
503 size_t i = 0;
504 for(size_t g = 0; g != SMALL_PRIME_GROUPS.size(); ++g) {
505 if(i >= num_primes) {
506 break;
507 }
508
509 const auto div_product = divisors.group(g);
510 const size_t group_end = std::min<size_t>(i + SMALL_PRIME_GROUPS[g].second, num_primes);
511
512 // First compute n modulo the group product
513 word n_mod_product = 0;
514 for(size_t w = n_words; w > 0; --w) {
515 n_mod_product = div_product.mod_2to1(n_mod_product, n._data()[w - 1]);
516 }
517
518 // Then extract the individual remainders using word arithmetic
519 while(i != group_end) {
520 residues[i] = divisors.prime(i).mod_2to1(0, n_mod_product);
521 ++i;
522 }
523 }
524
525 return residues;
526}
const size_t PRIME_TABLE_SIZE
Definition numthry.h:177

References Botan::BigInt::_data(), BOTAN_ARG_CHECK, PRIME_TABLE_SIZE, Botan::BigInt::sig_words(), and Botan::BigInt::signum().

◆ mod_small_primes() [2/2]

std::vector< word > Botan::mod_small_primes ( uint64_t x,
size_t num_primes )

Compute the residues of x modulo the first num_primes small odd primes

Returns a vector r of length num_primes where r[i] == x % PRIMES[i]

This is constant time with respect to the value of x

Parameters
xa 64-bit integer
num_primesnumber of primes to reduce by, at most PRIME_TABLE_SIZE

Definition at line 528 of file primes.cpp.

528 {
529 BOTAN_ARG_CHECK(num_primes > 0 && num_primes <= PRIME_TABLE_SIZE, "Invalid num_primes");
530
531 const auto& divisors = Small_Prime_Divisors::instance();
532
533 constexpr size_t x_words = 64 / WordInfo<word>::bits;
534
535 std::vector<word> residues(num_primes);
536 for(size_t i = 0; i != num_primes; ++i) {
537 const auto div_p = divisors.prime(i);
538 word r = 0;
539 for(size_t w = x_words; w > 0; --w) {
540 r = div_p.mod_2to1(r, static_cast<word>(x >> (WordInfo<word>::bits * (w - 1))));
541 }
542 residues[i] = r;
543 }
544 return residues;
545}

References BOTAN_ARG_CHECK, and PRIME_TABLE_SIZE.

◆ modular_inverse()

template<std::integral T, std::integral T2 = next_longer_int_t<T>>
T Botan::modular_inverse ( T q,
T2 m = T2(1) << sizeof(T) * 8 )
consteval

Calculate the modular multiplacative inverse of q modulo m. By default, this assumes m to be 2^bitlength of T for application in a Montgomery reduction.

Definition at line 97 of file pqcrystals_helpers.h.

97 {
98 return static_cast<T>(extended_euclidean_algorithm<T2>(q, m).u);
99}
consteval eea_result< T > extended_euclidean_algorithm(T a, T b)

References extended_euclidean_algorithm().

◆ montgomery_R()

template<std::integral T>
T Botan::montgomery_R ( T q)
consteval

Definition at line 44 of file pqcrystals_helpers.h.

44 {
45 using T_unsigned = std::make_unsigned_t<T>;
47 return (T2(1) << (sizeof(T) * 8)) % q;
48}
std::conditional_t< sizeof(T)==1, uint16_t, std::conditional_t< sizeof(T)==2, uint32_t, std::conditional_t< sizeof(T)==4, uint64_t, void > > > next_longer_uint_t

Referenced by montgomery_R2().

◆ montgomery_R2()

template<std::integral T>
T Botan::montgomery_R2 ( T q)
consteval

Definition at line 52 of file pqcrystals_helpers.h.

52 {
53 using T2 = next_longer_int_t<T>;
54 return (static_cast<T2>(montgomery_R(q)) * static_cast<T2>(montgomery_R(q))) % q;
55}
consteval T montgomery_R(T q)
std::conditional_t< sizeof(T)==1, int16_t, std::conditional_t< sizeof(T)==2, int32_t, std::conditional_t< sizeof(T)==4, int64_t, void > > > next_longer_int_t

References montgomery_R().

◆ monty_execute()

BOTAN_TEST_API Montgomery_Int Botan::monty_execute ( const Montgomery_Exponentiation_State & precomputed_state,
const BigInt & k,
size_t max_k_bits )

Definition at line 163 of file monty_exp.cpp.

165 {
166 return precomputed_state.exponentiation(k, max_k_bits);
167}
virtual Montgomery_Int exponentiation(const BigInt &k, size_t max_k_bits) const =0

References Botan::Montgomery_Exponentiation_State::exponentiation(), and monty_execute().

Referenced by monty_execute(), and monty_exp().

◆ monty_execute_vartime()

BOTAN_TEST_API Montgomery_Int Botan::monty_execute_vartime ( const Montgomery_Exponentiation_State & precomputed_state,
const BigInt & k )

Definition at line 169 of file monty_exp.cpp.

169 {
170 return precomputed_state.exponentiation_vartime(k);
171}
virtual Montgomery_Int exponentiation_vartime(const BigInt &k) const =0

References Botan::Montgomery_Exponentiation_State::exponentiation_vartime(), and monty_execute_vartime().

Referenced by monty_execute_vartime(), and monty_exp_vartime().

◆ monty_exp()

Montgomery_Int Botan::monty_exp ( const Montgomery_Params & params_p,
const BigInt & g,
const BigInt & k,
size_t max_k_bits )
inline

Definition at line 70 of file monty_exp.h.

73 {
74 const auto precomputed = monty_precompute(params_p, g, 4);
75 return monty_execute(*precomputed, k, max_k_bits);
76}
std::shared_ptr< const Montgomery_Exponentiation_State > monty_precompute(const Montgomery_Int &g, size_t window_bits)
Montgomery_Int monty_execute(const Montgomery_Exponentiation_State &precomputed_state, const BigInt &k, size_t max_k_bits)

References monty_execute(), and monty_precompute().

Referenced by power_mod().

◆ monty_exp_vartime()

Montgomery_Int Botan::monty_exp_vartime ( const Montgomery_Params & params_p,
const BigInt & g,
const BigInt & k )
inline

Definition at line 78 of file monty_exp.h.

78 {
79 const auto precomputed = monty_precompute(params_p, g, 4);
80 return monty_execute_vartime(*precomputed, k);
81}
Montgomery_Int monty_execute_vartime(const Montgomery_Exponentiation_State &precomputed_state, const BigInt &k)

References monty_execute_vartime(), and monty_precompute().

Referenced by sqrt_modulo_prime().

◆ monty_inverse()

template<WordType W>
auto Botan::monty_inverse ( W a) -> W
inlineconstexpr

Definition at line 866 of file mp_core.h.

866 {
867 BOTAN_ARG_CHECK(CT::driveby_unpoison(a % 2 == 1), "Cannot compute Montgomery inverse of an even integer");
868
869 // Newton's Method, following https://lemire.me/blog/2017/09/18/computing-the-inverse-of-odd-integers/
870
871 constexpr size_t iter = WordInfo<W>::bits == 64 ? 4 : 3;
872
873 // Initial guess provides 5 bits of accuracy
874 W r = (3 * a) ^ 2;
875
876 // Each iteration doubles the accuracy
877 for(size_t i = 0; i != iter; ++i) {
878 r = r * (2 - r * a);
879 }
880
881 // Now invert in addition space
882 r = (WordInfo<W>::max - r) + 1;
883
884 return r;
885}

References BOTAN_ARG_CHECK, and Botan::CT::driveby_unpoison().

◆ monty_multi_exp()

Montgomery_Int Botan::monty_multi_exp ( const Montgomery_Params & params_p,
const BigInt & x,
const BigInt & z1,
const BigInt & y,
const BigInt & z2 )

Return (x^z1 * y^z2) % p

Definition at line 173 of file monty_exp.cpp.

174 {
175 if(z1.signum() < 0 || z2.signum() < 0) {
176 throw Invalid_Argument("multi_exponentiate exponents must be positive");
177 }
178
179 // The exponents are consumed two bits at a time
180 const size_t max_z1z2 = std::max(z1.bits(), z2.bits());
181 const size_t z_bits = 2 * ceil_division<size_t>(max_z1z2, 2);
182
183 secure_vector<word> ws(2 * params_p.p_words());
184
185 const Montgomery_Int one = Montgomery_Int::one(params_p);
186
187 const Montgomery_Int x1(params_p, x_bn);
188 const Montgomery_Int x2 = x1.square(ws);
189 const Montgomery_Int x3 = x2.mul(x1, ws);
190
191 const Montgomery_Int y1(params_p, y_bn);
192 const Montgomery_Int y2 = y1.square(ws);
193 const Montgomery_Int y3 = y2.mul(y1, ws);
194
195 const Montgomery_Int y1x1 = y1.mul(x1, ws);
196 const Montgomery_Int y1x2 = y1.mul(x2, ws);
197 const Montgomery_Int y1x3 = y1.mul(x3, ws);
198
199 const Montgomery_Int y2x1 = y2.mul(x1, ws);
200 const Montgomery_Int y2x2 = y2.mul(x2, ws);
201 const Montgomery_Int y2x3 = y2.mul(x3, ws);
202
203 const Montgomery_Int y3x1 = y3.mul(x1, ws);
204 const Montgomery_Int y3x2 = y3.mul(x2, ws);
205 const Montgomery_Int y3x3 = y3.mul(x3, ws);
206
207 // NOLINTNEXTLINE(*-const-correctness) bug in clang-tidy
208 const Montgomery_Int* M[16] = {&one,
209 &x1, // 0001
210 &x2, // 0010
211 &x3, // 0011
212 &y1, // 0100
213 &y1x1,
214 &y1x2,
215 &y1x3,
216 &y2, // 1000
217 &y2x1,
218 &y2x2,
219 &y2x3,
220 &y3, // 1100
221 &y3x1,
222 &y3x2,
223 &y3x3};
224
225 Montgomery_Int H = one;
226
227 for(size_t i = 0; i != z_bits; i += 2) {
228 if(i > 0) {
229 H.square_this_n_times(ws, 2);
230 }
231
232 const uint32_t z1_b = z1.get_substring(z_bits - i - 2, 2);
233 const uint32_t z2_b = z2.get_substring(z_bits - i - 2, 2);
234
235 const uint32_t z12 = (4 * z2_b) + z1_b;
236
237 if(z12 > 0) {
238 H.mul_by(*M[z12], ws);
239 }
240 }
241
242 return H;
243}
uint32_t get_substring(size_t offset, size_t length) const
Definition bigint.cpp:240
static Montgomery_Int one(const Montgomery_Params &params)
Definition monty.cpp:237
size_t p_words() const
Definition monty.h:58
BOTAN_FORCE_INLINE constexpr T ceil_division(T a, T b)
Definition bit_ops.h:167

References Botan::BigInt::bits(), ceil_division(), Botan::BigInt::get_substring(), monty_multi_exp(), Botan::Montgomery_Int::mul(), Botan::Montgomery_Int::mul_by(), Botan::Montgomery_Int::one(), Botan::Montgomery_Params::p_words(), Botan::BigInt::signum(), Botan::Montgomery_Int::square(), and Botan::Montgomery_Int::square_this_n_times().

Referenced by monty_multi_exp(), and Botan::DL_Group::multi_exponentiate().

◆ monty_precompute() [1/2]

BOTAN_TEST_API std::shared_ptr< const Montgomery_Exponentiation_State > Botan::monty_precompute ( const Montgomery_Int & g,
size_t window_bits )

Definition at line 135 of file monty_exp.cpp.

135 {
136 if(window_bits == 0) {
137 window_bits = 4;
138 }
139
140 if(window_bits < 1 || window_bits > 12) { // really even 8 is too large ...
141 throw Invalid_Argument("Invalid window bits for Montgomery exponentiation");
142 }
143
144#if defined(BOTAN_HAS_MONTY_EXP_AVX512)
146 if(auto state = make_monty_exp_avx512(g, window_bits)) {
147 return state;
148 }
149 }
150#endif
151
152 return std::make_shared<const Montgomery_Exponentiation_Generic>(g, window_bits);
153}
std::unique_ptr< Montgomery_Exponentiation_State > make_monty_exp_avx512(const Montgomery_Int &g, size_t window_bits)

References Botan::CPUFeature::AVX512, Botan::CPUID::has(), make_monty_exp_avx512(), and monty_precompute().

Referenced by monty_exp(), monty_exp_vartime(), monty_precompute(), and monty_precompute().

◆ monty_precompute() [2/2]

BOTAN_TEST_API std::shared_ptr< const Montgomery_Exponentiation_State > Botan::monty_precompute ( const Montgomery_Params & params,
const BigInt & g,
size_t window_bits )

Definition at line 155 of file monty_exp.cpp.

157 {
158 BOTAN_ARG_CHECK(g.signum() >= 0 && g < params.p(), "Montgomery exponentiation base integer out of range");
159 const Montgomery_Int monty_g(params, g);
160 return monty_precompute(monty_g, window_bits);
161}

References BOTAN_ARG_CHECK, monty_precompute(), Botan::Montgomery_Params::p(), and Botan::BigInt::signum().

◆ monty_redc()

template<WordType W, size_t N>
auto Botan::monty_redc ( const std::array< W, 2 *N > & z,
const std::array< W, N > & p,
W p_dash ) -> std::array< W, N >
inlineconstexpr

Definition at line 109 of file pcurves_util.h.

110 {
111 static_assert(N >= 1);
112
113 std::array<W, N> ws; // NOLINT(*-member-init)
114 std::array<W, N> r; // NOLINT(*-member-init)
115
116 // Conditional ok: the parameter size is public
117 if(!std::is_constant_evaluated()) {
118 // This range ensures we cover fields of 256, 384 and 512 bits for both 32 and 64 bit words
119 if constexpr(N == 4) {
120 bigint_monty_redc_4(r.data(), z.data(), p.data(), p_dash, ws.data());
121 return r;
122 } else if constexpr(N == 6) {
123 bigint_monty_redc_6(r.data(), z.data(), p.data(), p_dash, ws.data());
124 return r;
125 } else if constexpr(N == 8) {
126 bigint_monty_redc_8(r.data(), z.data(), p.data(), p_dash, ws.data());
127 return r;
128 } else if constexpr(N == 12) {
129 bigint_monty_redc_12(r.data(), z.data(), p.data(), p_dash, ws.data());
130 return r;
131 } else if constexpr(N == 16) {
132 bigint_monty_redc_16(r.data(), z.data(), p.data(), p_dash, ws.data());
133 return r;
134 }
135 }
136
137 word3<W> accum;
138
139 accum.add(z[0]);
140
141 ws[0] = accum.monty_step(p[0], p_dash);
142
143 for(size_t i = 1; i != N; ++i) {
144 for(size_t j = 0; j < i; ++j) {
145 accum.mul(ws[j], p[i - j]);
146 }
147
148 accum.add(z[i]);
149
150 ws[i] = accum.monty_step(p[0], p_dash);
151 }
152
153 for(size_t i = 0; i != N - 1; ++i) {
154 for(size_t j = i + 1; j != N; ++j) {
155 accum.mul(ws[j], p[N + i - j]);
156 }
157
158 accum.add(z[N + i]);
159
160 ws[i] = accum.extract();
161 }
162
163 accum.add(z[2 * N - 1]);
164
165 ws[N - 1] = accum.extract();
166 // w1 is the final part, which is not stored in the workspace
167 const W w1 = accum.extract();
168
169 bigint_monty_maybe_sub<N>(r.data(), w1, ws.data(), p.data());
170
171 return r;
172}

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), bigint_monty_redc_12(), bigint_monty_redc_16(), bigint_monty_redc_4(), bigint_monty_redc_6(), bigint_monty_redc_8(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step(), and Botan::word3< W >::mul().

Referenced by Botan::MontgomeryRep< Params >::redc().

◆ monty_redc_pdash1()

template<WordType W, size_t N>
auto Botan::monty_redc_pdash1 ( const std::array< W, 2 *N > & z,
const std::array< W, N > & p ) -> std::array< W, N >
inlineconstexpr

Definition at line 65 of file pcurves_util.h.

65 {
66 static_assert(N >= 1);
67
68 std::array<W, N> ws; // NOLINT(*-member-init);
69 std::array<W, N> r; // NOLINT(*-member-init)
70
71 word3<W> accum;
72
73 accum.add(z[0]);
74
75 ws[0] = accum.monty_step_pdash1();
76
77 for(size_t i = 1; i != N; ++i) {
78 for(size_t j = 0; j < i; ++j) {
79 accum.mul(ws[j], p[i - j]);
80 }
81
82 accum.add(z[i]);
83
84 ws[i] = accum.monty_step_pdash1();
85 }
86
87 for(size_t i = 0; i != N - 1; ++i) {
88 for(size_t j = i + 1; j != N; ++j) {
89 accum.mul(ws[j], p[N + i - j]);
90 }
91
92 accum.add(z[N + i]);
93
94 ws[i] = accum.extract();
95 }
96
97 accum.add(z[2 * N - 1]);
98
99 ws[N - 1] = accum.extract();
100 // w1 is the final part, which is not stored in the workspace
101 const W w1 = accum.extract();
102
103 bigint_monty_maybe_sub<N>(r.data(), w1, ws.data(), p.data());
104
105 return r;
106}
constexpr W monty_step_pdash1()
Definition mp_asmi.h:682

References Botan::word3< W >::add(), bigint_monty_maybe_sub(), Botan::word3< W >::extract(), Botan::word3< W >::monty_step_pdash1(), and Botan::word3< W >::mul().

Referenced by Botan::MontgomeryRep< Params >::redc().

◆ montygomery_r()

template<WordType W, size_t N>
std::array< W, N > Botan::montygomery_r ( const std::array< W, N > & p)
inlineconsteval

Definition at line 49 of file pcurves_util.h.

49 {
50 std::array<W, N + 1> x = {};
51 x[N] = 1;
52 return reduce_mod(x, p);
53}
consteval std::array< W, N > reduce_mod(const std::array< W, XN > &x, const std::array< W, N > &p)

References reduce_mod().

◆ mul2_exec()

template<typename C, size_t WindowBits, typename BlindedScalar, typename Blinding>
C::ProjectivePoint Botan::mul2_exec ( const SharedZPointTable< C > & table,
const BlindedScalar & x,
const BlindedScalar & y,
const Blinding & blinding )

Definition at line 658 of file pcurves_mul.h.

661 {
662 const size_t Windows = (x.bits() + WindowBits - 1) / WindowBits;
663
664 auto accum = [&]() {
665 const size_t w_1 = x.get_window((Windows - 1) * WindowBits);
666 const size_t w_2 = y.get_window((Windows - 1) * WindowBits);
667 const size_t window = w_1 + (w_2 << WindowBits);
668 auto pt = C::ProjectivePoint::from_affine(table.ct_select(window));
669 blinding.randomize_rep(pt, 0);
670 return pt;
671 }();
672
673 for(size_t i = 1; i != Windows; ++i) {
674 accum = accum.dbl_n_iso(table.a(), WindowBits);
675
676 const size_t w_1 = x.get_window((Windows - i - 1) * WindowBits);
677 const size_t w_2 = y.get_window((Windows - i - 1) * WindowBits);
678 const size_t window = w_1 + (w_2 << WindowBits);
679 accum = C::ProjectivePoint::add_mixed_iso(accum, table.ct_select(window), table.a());
680
681 // Conditional ok: loop iteration count is public
682 if(i < Blinding::Rerandomizations) {
683 blinding.randomize_rep(accum, i);
684 }
685 }
686
687 // Map back from the isomorphic curve
688 return typename C::ProjectivePoint(accum.x(), accum.y(), accum.z() * table.z());
689}
const FieldElement & z() const
AffinePoint ct_select(size_t idx) const
const FieldElement & a() const

References Botan::SharedZPointTable< C >::a(), Botan::SharedZPointTable< C >::ct_select(), and Botan::SharedZPointTable< C >::z().

Referenced by varpoint_mul2().

◆ mul2_setup()

template<typename C, size_t WindowBits>
std::vector< typename C::ProjectivePoint > Botan::mul2_setup ( const typename C::AffinePoint & p,
const typename C::AffinePoint & q )

Definition at line 596 of file pcurves_mul.h.

597 {
598 static_assert(WindowBits >= 1 && WindowBits <= 4);
599
600 // 2^(2*W) elements, less the identity element
601 constexpr size_t TableSize = (1 << (2 * WindowBits)) - 1;
602 constexpr size_t WindowSize = (1 << WindowBits);
603
604 std::vector<typename C::ProjectivePoint> table;
605 table.reserve(TableSize);
606
607 for(size_t i = 0; i != TableSize; ++i) {
608 const size_t t_i = (i + 1);
609 const size_t p_i = t_i % WindowSize;
610 const size_t q_i = (t_i >> WindowBits) % WindowSize;
611
612 // Conditionals ok: all based on t_i/p_i/q_i which in turn are derived from public i
613
614 // Returns x_i * x + y_i * y
615 const auto next_tbl_e = [&]() {
616 if(p_i % 2 == 0 && q_i % 2 == 0) {
617 // Where possible using doubling (eg indices 1, 7, 9 in
618 // the table above)
619 return table[(t_i / 2) - 1].dbl();
620 } else if(p_i > 0 && q_i > 0) {
621 // A combination of p and q
622 if(p_i == 1) {
623 return p + table[(q_i << WindowBits) - 1];
624 } else if(q_i == 1) {
625 return table[p_i - 1] + q;
626 } else {
627 return table[p_i - 1] + table[(q_i << WindowBits) - 1];
628 }
629 } else if(p_i > 0 && q_i == 0) {
630 // A multiple of p without a q component
631 if(p_i == 1) {
632 // Just p
633 return C::ProjectivePoint::from_affine(p);
634 } else {
635 // p * p_{i-1}
636 return p + table[p_i - 1 - 1];
637 }
638 } else if(p_i == 0 && q_i > 0) {
639 if(q_i == 1) {
640 // Just q
641 return C::ProjectivePoint::from_affine(q);
642 } else {
643 // q * q_{i-1}
644 return q + table[((q_i - 1) << WindowBits) - 1];
645 }
646 } else {
648 }
649 };
650
651 table.emplace_back(next_tbl_e());
652 }
653
654 return table;
655}
#define BOTAN_ASSERT_UNREACHABLE()
Definition assert.h:173

References BOTAN_ASSERT_UNREACHABLE.

Referenced by varpoint_mul2().

◆ mul64x64_128()

void Botan::mul64x64_128 ( uint64_t a,
uint64_t b,
uint64_t * lo,
uint64_t * hi )
inlineconstexpr

Perform a 64x64->128 bit multiplication

Definition at line 24 of file mul128.h.

24 {
25 if(!std::is_constant_evaluated()) {
26#if defined(BOTAN_BUILD_COMPILER_IS_MSVC) && defined(BOTAN_TARGET_ARCH_IS_X86_64)
27 *lo = _umul128(a, b, hi);
28 return;
29
30#elif defined(BOTAN_BUILD_COMPILER_IS_MSVC) && defined(BOTAN_TARGET_ARCH_IS_ARM64)
31 *lo = a * b;
32 *hi = __umulh(a, b);
33 return;
34#endif
35 }
36
37#if defined(BOTAN_TARGET_HAS_NATIVE_UINT128)
38 const uint128_t r = static_cast<uint128_t>(a) * b;
39 *hi = (r >> 64) & 0xFFFFFFFFFFFFFFFF;
40 *lo = (r) & 0xFFFFFFFFFFFFFFFF;
41#else
42
43 /*
44 * Do a 64x64->128 multiply using four 32x32->64 multiplies plus
45 * some adds and shifts.
46 */
47 const size_t HWORD_BITS = 32;
48 const uint32_t HWORD_MASK = 0xFFFFFFFF;
49
50 const uint32_t a_hi = (a >> HWORD_BITS);
51 const uint32_t a_lo = (a & HWORD_MASK);
52 const uint32_t b_hi = (b >> HWORD_BITS);
53 const uint32_t b_lo = (b & HWORD_MASK);
54
55 const uint64_t x0 = static_cast<uint64_t>(a_hi) * b_hi;
56 const uint64_t x1 = static_cast<uint64_t>(a_lo) * b_hi;
57 const uint64_t x2 = static_cast<uint64_t>(a_hi) * b_lo;
58 const uint64_t x3 = static_cast<uint64_t>(a_lo) * b_lo;
59
60 // this cannot overflow as (2^32-1)^2 + 2^32-1 + 2^32-1 = 2^64-1
61 const uint64_t middle = x2 + (x3 >> HWORD_BITS) + (x1 & HWORD_MASK);
62
63 // likewise these cannot overflow
64 *hi = x0 + (middle >> HWORD_BITS) + (x1 >> HWORD_BITS);
65 *lo = (middle << HWORD_BITS) + (x3 & HWORD_MASK);
66#endif
67}
donna128 uint128_t
Definition x25519_fe.h:37

Referenced by operator*().

◆ mul_a24()

Gf448Elem Botan::mul_a24 ( const Gf448Elem & a)

Multiply a field element by the Curve448 constant a24 = 39081.

Definition at line 439 of file curve448_gf.cpp.

439 {
440 Gf448Elem res(0);
441 gf_mul_a24(res.words(), a.words());
442 return res;
443}
std::span< uint64_t, WORDS_448 > words()
Accessor to the internal words of the GF element.

References Botan::Gf448Elem::words().

Referenced by Botan::Ed448Point::decode(), Botan::Ed448Point::operator+(), and x448().

◆ mul_mod()

template<WordType W, size_t N>
std::array< W, N > Botan::mul_mod ( const std::array< W, N > & x,
const std::array< W, N > & y,
const std::array< W, N > & p )
inlineconsteval

Definition at line 56 of file pcurves_util.h.

58 {
59 std::array<W, 2 * N> z = {};
60 comba_mul<N>(z.data(), x.data(), y.data());
61 return reduce_mod(z, p);
62}
constexpr void comba_mul(W z[2 *N], const W x[N], const W y[N])
Definition mp_core.h:981

References comba_mul(), and reduce_mod().

◆ mul_or_throw()

template<std::unsigned_integral T>
T Botan::mul_or_throw ( T a,
T b,
std::string_view msg )
constexpr

Multiply a and b, throwing Invalid_Argument with message msg if the multiplication would overflow.

TODO(Botan4) add std::source_location argument

Definition at line 81 of file int_utils.h.

81 {
82 if(auto r = checked_mul(a, b)) {
83 return r.value();
84 } else {
85 throw Invalid_Argument(msg);
86 }
87}

References checked_mul().

Referenced by Botan::Scrypt::derive_key(), Botan::bitvector_base< secure_allocator >::from_bytes(), hex_encode(), and Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::output_length().

◆ multi_exponentiate()

EC_Point Botan::multi_exponentiate ( const EC_Point & p1,
const BigInt & z1,
const EC_Point & p2,
const BigInt & z2 )

ECC point multiexponentiation - not constant time!

Parameters
p1a point
z1a scalar
p2a point
z2a scalar
Returns
(p1 * z1 + p2 * z2)

Definition at line 36 of file point_mul.cpp.

36 {
37 const EC_Point_Multi_Point_Precompute xy_mul(x, y);
38 return xy_mul.multi_exp(z1, z2);
39}

References Botan::EC_Point_Multi_Point_Precompute::multi_exp().

◆ mulx_polyval()

BOTAN_FORCE_INLINE SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 Botan::mulx_polyval ( const SIMD_4x32 & h)

Definition at line 104 of file polyval_fn.h.

104 {
105 const auto V = SIMD_4x32(0x00000001, 0x00000000, 0x00000000, 0xc2000000);
106
107 // Bitmask set iff the top bit of h is set
108 const auto mask = h.top_bit_mask();
109
110 // Extract the top bits of the words and move them into place as the low bit of the next word
111 const auto top_bits = h.shr<31>().shift_elems_left<1>();
112
113 // The main shift, adding back in the top bits that are otherwise lost
114 const auto shifted_h = h.shl<1>() | top_bits;
115
116 return shifted_h ^ (mask & V);
117}
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 top_bit_mask() const
Definition simd_4x32.h:905
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 shr() const noexcept
Definition simd_4x32.h:485
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 shl() const noexcept
Definition simd_4x32.h:467

References BOTAN_FORCE_INLINE, Botan::SIMD_4x32::shl(), Botan::SIMD_4x32::shr(), and Botan::SIMD_4x32::top_bit_mask().

◆ next_utf8_codepoint()

uint32_t Botan::next_utf8_codepoint ( std::string_view utf8,
size_t & pos )

Decode the UTF-8 code point beginning at utf8[pos], advancing pos past it

Exceptions
Decoding_Errorif the bytes at pos are not a valid UTF-8 sequence

Definition at line 53 of file charset.cpp.

53 {
54 const auto read_continuation = [&]() -> uint32_t {
55 if(pos >= utf8.size()) {
56 throw Decoding_Error("Invalid UTF-8 sequence");
57 }
58 const uint8_t b = static_cast<uint8_t>(utf8[pos++]);
59 if((b & 0xC0) != 0x80) {
60 throw Decoding_Error("Invalid UTF-8 sequence");
61 }
62 return b & 0x3F;
63 };
64
65 if(pos >= utf8.size()) {
66 throw Decoding_Error("Invalid UTF-8 sequence");
67 }
68 const uint8_t lead = static_cast<uint8_t>(utf8[pos++]);
69 uint32_t c = 0;
70
71 if(lead <= 0x7F) {
72 c = lead;
73 } else if((lead & 0xE0) == 0xC0) {
74 c = (lead & 0x1F) << 6;
75 c |= read_continuation();
76 if(c < 0x80) {
77 throw Decoding_Error("Overlong UTF-8 sequence");
78 }
79 } else if((lead & 0xF0) == 0xE0) {
80 c = (lead & 0x0F) << 12;
81 c |= read_continuation() << 6;
82 c |= read_continuation();
83 if(c < 0x800) {
84 throw Decoding_Error("Overlong UTF-8 sequence");
85 }
86 } else if((lead & 0xF8) == 0xF0) {
87 c = (lead & 0x07) << 18;
88 c |= read_continuation() << 12;
89 c |= read_continuation() << 6;
90 c |= read_continuation();
91 if(c < 0x10000) {
92 throw Decoding_Error("Overlong UTF-8 sequence");
93 }
94 } else {
95 throw Decoding_Error("Invalid UTF-8 sequence");
96 }
97
98 if(c > 0x10FFFF) {
99 throw Decoding_Error("UTF-8 sequence encodes value outside Unicode range");
100 }
101 if(c >= 0xD800 && c < 0xE000) {
102 throw Decoding_Error("UTF-8 sequence encodes surrogate code point");
103 }
104
105 return c;
106}

Referenced by escape_control_chars(), is_valid_utf8(), operator<<(), utf8_to_ucs2(), and utf8_to_ucs4().

◆ nibble_to_hex()

char Botan::nibble_to_hex ( uint8_t b)
inlineconstexpr

Map the low four bits of b to an uppercase hex digit ('0'..'9','A'..'F')

Definition at line 76 of file charset.h.

76 {
77 const uint8_t n = b & 0x0F;
78 return static_cast<char>(n < 10 ? '0' + n : 'A' + (n - 10));
79}

Referenced by escape_control_chars(), format_char_for_display(), and operator<<().

◆ nist_key_unwrap() [1/2]

secure_vector< uint8_t > Botan::nist_key_unwrap ( const uint8_t input[],
size_t input_len,
const BlockCipher & bc )

KW (key unwrap). See RFC 3394 and NIST SP800-38F

Parameters
inputthe value to be decrypted, output of nist_key_wrap
input_lenlength of input
bca keyed 128-bit block cipher that will be used to decrypt input
Returns
input decrypted under NIST key wrap algorithm Throws an exception if decryption fails.

Definition at line 117 of file nist_keywrap.cpp.

117 {
118 if(bc.block_size() != 16) {
119 throw Invalid_Argument("NIST key wrap algorithm requires a 128-bit cipher");
120 }
121
122 if(input_len < 16 || input_len % 8 != 0) {
123 throw Invalid_Argument("Bad input size for NIST key unwrap");
124 }
125
126 const uint64_t ICV = 0xA6A6A6A6A6A6A6A6;
127
128 uint64_t ICV_out = 0;
130
131 if(input_len == 16) {
132 secure_vector<uint8_t> block(input, input + input_len);
133 bc.decrypt(block);
134
135 ICV_out = load_be<uint64_t>(block.data(), 0);
136 R.resize(8);
137 copy_mem(R.data(), block.data() + 8, 8);
138 } else {
139 R = raw_nist_key_unwrap(input, input_len, bc, ICV_out);
140 }
141
142 if(ICV_out != ICV) {
143 throw Invalid_Authentication_Tag("NIST key unwrap failed");
144 }
145
146 return R;
147}
void decrypt(const uint8_t in[], uint8_t out[]) const
virtual size_t block_size() const =0

References Botan::BlockCipher::block_size(), copy_mem(), Botan::BlockCipher::decrypt(), and load_be().

Referenced by botan_nist_kw_dec(), nist_key_unwrap(), and rfc3394_keyunwrap().

◆ nist_key_unwrap() [2/2]

secure_vector< uint8_t > Botan::nist_key_unwrap ( std::span< const uint8_t > input,
const BlockCipher & bc )
inline

KW (key unwrap). See RFC 3394 and NIST SP800-38F

Parameters
inputthe value to be decrypted, output of nist_key_wrap
bca keyed 128-bit block cipher that will be used to decrypt input
Returns
input decrypted under NIST key wrap algorithm Throws an exception if decryption fails.

Definition at line 55 of file nist_keywrap.h.

55 {
56 return nist_key_unwrap(input.data(), input.size(), bc);
57}
secure_vector< uint8_t > nist_key_unwrap(const uint8_t input[], size_t input_len, const BlockCipher &bc)

References nist_key_unwrap().

◆ nist_key_unwrap_padded() [1/2]

secure_vector< uint8_t > Botan::nist_key_unwrap_padded ( const uint8_t input[],
size_t input_len,
const BlockCipher & bc )

KWP (key unwrap with padding). See RFC 5649 and NIST SP800-38F

Parameters
inputthe value to be decrypted, output of nist_key_wrap
input_lenlength of input
bca keyed 128-bit block cipher that will be used to decrypt input
Returns
input decrypted under NIST key wrap algorithm Throws an exception if decryption fails.

Definition at line 174 of file nist_keywrap.cpp.

174 {
175 if(bc.block_size() != 16) {
176 throw Invalid_Argument("NIST key wrap algorithm requires a 128-bit cipher");
177 }
178
179 if(input_len < 16 || input_len % 8 != 0) {
180 throw Invalid_Argument("Bad input size for NIST key unwrap");
181 }
182
183 uint64_t ICV_out = 0;
185
186 if(input_len == 16) {
187 secure_vector<uint8_t> block(input, input + input_len);
188 bc.decrypt(block);
189
190 ICV_out = load_be<uint64_t>(block.data(), 0);
191 R.resize(8);
192 copy_mem(R.data(), block.data() + 8, 8);
193 } else {
194 R = raw_nist_key_unwrap(input, input_len, bc, ICV_out);
195 }
196
197 /*
198 The padded key wrap ICV is 0xA65959A6 || uint32(plaintext_length).
199
200 We know the expected ICV almost entirely: the top 32 bits are the
201 fixed constant and the bottom 32 bits encode the original plaintext
202 length, which is R.size() minus 0 to 7 bytes of padding. Compute
203 the ICV we'd expect for the zero-padding case and subtract ICV_out;
204 for a valid unwrap the difference is at most 7, and equals the padding.
205 For an invalid unwrap the unsigned subtraction wraps to a value > 7
206 (checked below), so the modular arithmetic here is intentional.
207 */
208 const uint64_t expected_ICV_max = 0xA65959A600000000 | static_cast<uint32_t>(R.size());
209 const uint64_t padding = expected_ICV_max - ICV_out;
210
211 if(padding > 7) {
212 throw Invalid_Authentication_Tag("NIST key unwrap failed");
213 }
214
215 // Verify padding bytes are zero
216 const uint64_t last_block = load_be<uint64_t>(R.data() + R.size() - 8, 0);
217 const uint64_t padding_mask = (static_cast<uint64_t>(1) << (padding * 8)) - 1;
218 if((last_block & padding_mask) != 0) {
219 throw Invalid_Authentication_Tag("NIST key unwrap failed");
220 }
221
222 R.resize(R.size() - static_cast<size_t>(padding));
223 return R;
224}

References Botan::BlockCipher::block_size(), copy_mem(), Botan::BlockCipher::decrypt(), and load_be().

Referenced by botan_nist_kw_dec(), Botan::Encrypted_PSK_Database::get(), Botan::Encrypted_PSK_Database::list_names(), and nist_key_unwrap_padded().

◆ nist_key_unwrap_padded() [2/2]

secure_vector< uint8_t > Botan::nist_key_unwrap_padded ( std::span< const uint8_t > input,
const BlockCipher & bc )
inline

KWP (key unwrap with padding). See RFC 5649 and NIST SP800-38F

Parameters
inputthe value to be decrypted, output of nist_key_wrap
bca keyed 128-bit block cipher that will be used to decrypt input
Returns
input decrypted under NIST key wrap algorithm Throws an exception if decryption fails.

Definition at line 97 of file nist_keywrap.h.

97 {
98 return nist_key_unwrap_padded(input.data(), input.size(), bc);
99}
secure_vector< uint8_t > nist_key_unwrap_padded(const uint8_t input[], size_t input_len, const BlockCipher &bc)

References nist_key_unwrap_padded().

◆ nist_key_wrap() [1/2]

std::vector< uint8_t > Botan::nist_key_wrap ( const uint8_t input[],
size_t input_len,
const BlockCipher & bc )

Key wrap. See RFC 3394 and NIST SP800-38F

Parameters
inputthe value to be encrypted
input_lenlength of input, must be a multiple of 8
bca keyed 128-bit block cipher that will be used to encrypt input
Returns
input encrypted under NIST key wrap algorithm

Definition at line 91 of file nist_keywrap.cpp.

91 {
92 if(bc.block_size() != 16) {
93 throw Invalid_Argument("NIST key wrap algorithm requires a 128-bit cipher");
94 }
95
96 if(input_len == 0 || input_len % 8 != 0) {
97 throw Invalid_Argument("Bad input size for NIST key wrap");
98 }
99
100 const uint64_t ICV = 0xA6A6A6A6A6A6A6A6;
101
102 if(input_len == 8) {
103 /*
104 * Special case for small inputs: if input == 8 bytes just use ECB
105 * (see RFC 3394 Section 2)
106 */
107 std::vector<uint8_t> block(16);
108 store_be(ICV, block.data());
109 copy_mem(block.data() + 8, input, input_len);
110 bc.encrypt(block);
111 return block;
112 } else {
113 return raw_nist_key_wrap(input, input_len, bc, ICV);
114 }
115}

References Botan::BlockCipher::block_size(), copy_mem(), Botan::BlockCipher::encrypt(), and store_be().

Referenced by botan_nist_kw_enc(), nist_key_wrap(), and rfc3394_keywrap().

◆ nist_key_wrap() [2/2]

std::vector< uint8_t > Botan::nist_key_wrap ( std::span< const uint8_t > input,
const BlockCipher & bc )
inline

Key wrap. See RFC 3394 and NIST SP800-38F

Parameters
inputthe value to be encrypted
bca keyed 128-bit block cipher that will be used to encrypt input
Returns
input encrypted under NIST key wrap algorithm

Definition at line 33 of file nist_keywrap.h.

33 {
34 return nist_key_wrap(input.data(), input.size(), bc);
35}
std::vector< uint8_t > nist_key_wrap(const uint8_t input[], size_t input_len, const BlockCipher &bc)

References nist_key_wrap().

◆ nist_key_wrap_padded() [1/2]

std::vector< uint8_t > Botan::nist_key_wrap_padded ( const uint8_t input[],
size_t input_len,
const BlockCipher & bc )

KWP (key wrap with padding). See RFC 5649 and NIST SP800-38F

Parameters
inputthe value to be encrypted
input_lenlength of input
bca keyed 128-bit block cipher that will be used to encrypt input
Returns
input encrypted under NIST key wrap algorithm

Definition at line 149 of file nist_keywrap.cpp.

149 {
150 if(bc.block_size() != 16) {
151 throw Invalid_Argument("NIST key wrap algorithm requires a 128-bit cipher");
152 }
153
154 if(input_len == 0) {
155 throw Invalid_Argument("NIST KWP cannot accept empty inputs");
156 }
157
158 const uint64_t ICV = 0xA65959A600000000 | static_cast<uint32_t>(input_len);
159
160 if(input_len <= 8) {
161 /*
162 * Special case for small inputs: if input <= 8 bytes just use ECB
163 */
164 std::vector<uint8_t> block(16);
165 store_be(ICV, block.data());
166 copy_mem(block.data() + 8, input, input_len);
167 bc.encrypt(block);
168 return block;
169 } else {
170 return raw_nist_key_wrap(input, input_len, bc, ICV);
171 }
172}

References Botan::BlockCipher::block_size(), copy_mem(), Botan::BlockCipher::encrypt(), and store_be().

Referenced by botan_nist_kw_enc(), Botan::Encrypted_PSK_Database::get(), nist_key_wrap_padded(), Botan::Encrypted_PSK_Database::remove(), and Botan::Encrypted_PSK_Database::set().

◆ nist_key_wrap_padded() [2/2]

std::vector< uint8_t > Botan::nist_key_wrap_padded ( std::span< const uint8_t > input,
const BlockCipher & bc )
inline

KWP (key wrap with padding). See RFC 5649 and NIST SP800-38F

Parameters
inputthe value to be encrypted
bca keyed 128-bit block cipher that will be used to encrypt input
Returns
input encrypted under NIST key wrap algorithm

Definition at line 75 of file nist_keywrap.h.

75 {
76 return nist_key_wrap_padded(input.data(), input.size(), bc);
77}
std::vector< uint8_t > nist_key_wrap_padded(const uint8_t input[], size_t input_len, const BlockCipher &bc)

References nist_key_wrap_padded().

◆ oaep_find_delim()

BOTAN_FUZZER_API CT::Option< size_t > Botan::oaep_find_delim ( std::span< const uint8_t > input,
std::span< const uint8_t > phash )

Definition at line 103 of file oaep.cpp.

103 {
104 // Too short to be valid, reject immediately
105 if(input.size() < 1 + 2 * phash.size()) {
106 return {};
107 }
108
109 size_t delim_idx = 2 * phash.size();
110 CT::Mask<uint8_t> waiting_for_delim = CT::Mask<uint8_t>::set();
112
113 for(const uint8_t ib : input.subspan(2 * phash.size())) {
114 const auto zero_m = CT::Mask<uint8_t>::is_zero(ib);
115 const auto one_m = CT::Mask<uint8_t>::is_equal(ib, 1);
116
117 const auto add_m = waiting_for_delim & zero_m;
118
119 bad_input_m |= waiting_for_delim & ~(zero_m | one_m);
120
121 delim_idx += add_m.if_set_return(1);
122
123 waiting_for_delim &= zero_m;
124 }
125
126 // If we never saw any non-zero byte, then it's not valid input
127 bad_input_m |= waiting_for_delim;
128
129 // If the P hash is wrong, then it's not valid
130 bad_input_m |= CT::is_not_equal(&input[phash.size()], phash.data(), phash.size());
131
132 delim_idx += 1;
133
134 const auto accept = !(bad_input_m.as_choice());
135
136 return CT::Option(delim_idx, accept);
137}
static constexpr Mask< T > set()
Definition ct_utils.h:387
constexpr CT::Mask< T > is_not_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:843

References Botan::CT::Mask< T >::as_choice(), Botan::CT::Mask< T >::cleared(), Botan::CT::Mask< T >::if_set_return(), Botan::CT::Mask< T >::is_equal(), Botan::CT::is_not_equal(), Botan::CT::Mask< T >::is_zero(), and Botan::CT::Mask< T >::set().

◆ odd_multiples_setup_vartime()

template<typename C, size_t W>
std::vector< typename C::AffinePoint > Botan::odd_multiples_setup_vartime ( const typename C::AffinePoint & p)

Definition at line 555 of file pcurves_mul.h.

555 {
556 static_assert(W >= 2 && W <= 7);
557
558 constexpr size_t TableSize = 1 << (W - 2);
559
560 std::vector<typename C::ProjectivePoint> table;
561 table.reserve(TableSize);
562
563 const auto p2 = C::ProjectivePoint::from_affine(p).dbl();
564
565 table.push_back(C::ProjectivePoint::from_affine(p));
566 for(size_t i = 1; i != TableSize; ++i) {
567 table.push_back(table[i - 1] + p2);
568 }
569
570 // Variable time batch conversion is fine since the point is public
571 return to_affine_batch<C, true>(table);
572}

References to_affine_batch().

Referenced by Botan::VartimeMul2Table< C, W >::VartimeMul2Table().

◆ operator!=() [1/11]

bool Botan::operator!= ( const AlgorithmIdentifier & x,
const AlgorithmIdentifier & y )

Compare two AlgorithmIdentifiers

Parameters
xthe first AlgorithmIdentifier
ythe second AlgorithmIdentifier
Returns
true if x is not equal to y

Definition at line 58 of file alg_id.cpp.

58 {
59 return !(x == y);
60}

◆ operator!=() [2/11]

bool Botan::operator!= ( const ASN1_Time & x,
const ASN1_Time & y )

Compare two times

Returns
true if x is not equal to y

Definition at line 307 of file asn1_time.cpp.

307 {
308 return (t1.cmp(t2) != 0);
309}

References Botan::ASN1_Time::cmp().

◆ operator!=() [3/11]

bool Botan::operator!= ( const BigInt & a,
const BigInt & b )
inline

Compare two integers

Parameters
athe first operand
bthe second operand
Returns
true if a is not equal to b

Definition at line 1320 of file bigint.h.

1320 {
1321 return !a.is_equal(b);
1322}
bool is_equal(const BigInt &n) const
Definition bigint.cpp:157

References Botan::BigInt::is_equal().

◆ operator!=() [4/11]

bool Botan::operator!= ( const BigInt & a,
word b )
inline

Compare an integer with a word

Parameters
athe first operand
bthe second operand
Returns
true if a is not equal to b

Definition at line 1380 of file bigint.h.

1380 {
1381 return (a.cmp_word(b) != 0);
1382}
int32_t cmp_word(word n) const
Definition bigint.cpp:123

References Botan::BigInt::cmp_word().

◆ operator!=() [5/11]

bool Botan::operator!= ( const CRL_Entry & lhs,
const CRL_Entry & rhs )

Test two CRL entries for inequality in at least one field.

Definition at line 68 of file crl_ent.cpp.

68 {
69 return !(a1 == a2);
70}

◆ operator!=() [6/11]

bool Botan::operator!= ( const EC_Group & lhs,
const EC_Group & rhs )
inline

Test if two groups describe different curves

Parameters
lhsthe first group
rhsthe second group
Returns
true if the two groups are not equal

Definition at line 926 of file ec_group.h.

926 {
927 return !(lhs == rhs);
928}

◆ operator!=() [7/11]

bool Botan::operator!= ( const OctetString & x,
const OctetString & y )

Compare two strings

Parameters
xan octet string
yan octet string
Returns
if x is not equal to y

Definition at line 92 of file symkey.cpp.

92 {
93 return !(s1 == s2);
94}

◆ operator!=() [8/11]

bool Botan::operator!= ( const OID & a,
const OID & b )
inline

Compare two OIDs.

Parameters
athe first OID
bthe second OID
Returns
true if a is not equal to b

Definition at line 561 of file asn1_obj.h.

561 {
562 return !(a == b);
563}

◆ operator!=() [9/11]

template<typename T, typename U>
bool Botan::operator!= ( const secure_allocator< T > & ,
const secure_allocator< U > &  )
inline

Compare two secure allocators

All instances are interchangeable, so this is always false.

Returns
always false

Definition at line 123 of file secmem.h.

123 {
124 return false;
125}

◆ operator!=() [10/11]

bool Botan::operator!= ( const X509_Certificate & cert1,
const X509_Certificate & cert2 )

Check two certificates for inequality

Parameters
cert1The first certificate
cert2The second certificate
Returns
true if the arguments represent different certificates, false if they are binary identical

Definition at line 891 of file x509cert.cpp.

891 {
892 return !(cert1 == cert2);
893}

◆ operator!=() [11/11]

bool Botan::operator!= ( const X509_DN & dn1,
const X509_DN & dn2 )

Definition at line 347 of file x509_dn.cpp.

347 {
348 return !(dn1 == dn2);
349}

◆ operator%() [1/2]

BigInt Botan::operator% ( const BigInt & x,
const BigInt & m )

Reduce an integer modulo another

Parameters
xthe value to reduce
mthe modulus
Returns
(x % m)

Definition at line 130 of file big_ops3.cpp.

130 {
131 if(mod.is_zero()) {
132 throw Invalid_Argument("BigInt::operator% divide by zero");
133 }
134 if(mod.signum() < 0) {
135 throw Invalid_Argument("BigInt::operator% modulus must be > 0");
136 }
137 if(n.signum() >= 0 && mod.signum() >= 0 && n < mod) {
138 return n;
139 }
140
141 if(mod.sig_words() == 1) {
142 return BigInt::from_word(n % mod.word_at(0));
143 }
144
145 BigInt q;
146 BigInt r;
147 ct_divide(n, mod, q, r);
148 return r;
149}
static BigInt from_word(word n)
Definition bigint.cpp:36

References ct_divide(), Botan::BigInt::from_word(), Botan::BigInt::is_zero(), Botan::BigInt::sig_words(), Botan::BigInt::signum(), and Botan::BigInt::word_at().

◆ operator%() [2/2]

word Botan::operator% ( const BigInt & x,
word m )

Reduce an integer modulo a word

Parameters
xthe value to reduce
mthe modulus
Returns
(x % m)

Definition at line 154 of file big_ops3.cpp.

154 {
155 if(mod == 0) {
156 throw Invalid_Argument("BigInt::operator% divide by zero");
157 }
158
159 if(mod == 1) {
160 return 0;
161 }
162
163 word remainder = 0;
164
165 if(n.signum() >= 0 && is_power_of_2(mod)) {
166 remainder = (n.word_at(0) & (mod - 1));
167 } else {
168 const auto redc_mod = divide_precomp<word>::setup_vartime(mod);
169 const size_t sw = n.sig_words();
170 for(size_t i = sw; i > 0; --i) {
171 remainder = redc_mod.mod_2to1(remainder, n.word_at(i - 1));
172 }
173 }
174
175 if(remainder != 0 && n.sign() == BigInt::Negative) {
176 return mod - remainder;
177 }
178 return remainder;
179}
BOTAN_FORCE_INLINE constexpr bool is_power_of_2(T arg)
Definition bit_ops.h:62

References is_power_of_2(), Botan::BigInt::Negative, Botan::divide_precomp< W >::setup_vartime(), Botan::BigInt::sig_words(), Botan::BigInt::sign(), Botan::BigInt::signum(), and Botan::BigInt::word_at().

◆ operator&() [1/5]

template<bitvectorish T1, bitvectorish T2>
auto Botan::operator& ( const T1 & lhs,
const T2 & rhs )

Definition at line 1449 of file bitvector.h.

1449 {
1450 auto res = detail::copy_lhs_allocator_aware(lhs, rhs);
1451 res &= rhs;
1452 return res;
1453}
constexpr auto copy_lhs_allocator_aware(const T1 &lhs, const T2 &)
Definition bitvector.h:1428

References Botan::detail::copy_lhs_allocator_aware().

◆ operator&() [2/5]

ECIES_Flags Botan::operator& ( ECIES_Flags a,
ECIES_Flags b )
inline

Definition at line 70 of file ecies.h.

70 {
71 return static_cast<ECIES_Flags>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
72}
ECIES_Flags
Definition ecies.h:44

◆ operator&() [3/5]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator& ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Bitwise AND of the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 573 of file strong_type.h.

573 {
574 return Strong<T, Tags...>(a.get() & b.get());
575}

References Botan::detail::Strong_Base< T >::get().

◆ operator&() [4/5]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator& ( Strong< T1, Tags... > a,
T2 b )
constexpr

Bitwise AND of the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 562 of file strong_type.h.

562 {
563 return Strong<T1, Tags...>(a.get() & b);
564}

References Botan::detail::Strong_Base< T >::get().

◆ operator&() [5/5]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator& ( T1 a,
Strong< T2, Tags... > b )
constexpr

Bitwise AND of the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 550 of file strong_type.h.

550 {
551 return Strong<T2, Tags...>(a & b.get());
552}

References Botan::detail::Strong_Base< T >::get().

◆ operator&=() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator&= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Bitwise AND in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 827 of file strong_type.h.

827 {
828 a.get() &= b.get();
829 return a;
830}

References Botan::detail::Strong_Base< T >::get().

◆ operator&=() [2/2]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator&= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Bitwise AND in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 815 of file strong_type.h.

815 {
816 a.get() &= b;
817 return a;
818}

References Botan::detail::Strong_Base< T >::get().

◆ operator*() [1/12]

EC_Point Botan::operator* ( const BigInt & scalar,
const EC_Point & point )
inline

Multiply a point by a scalar

Parameters
scalarthe scalar
pointthe point
Returns
(point * scalar)

Definition at line 449 of file ec_point.h.

449 {
450 return point.mul(scalar);
451}
EC_Point mul(const BigInt &scalar) const
Definition ec_point.cpp:497

References Botan::EC_Point::mul().

◆ operator*() [2/12]

BigInt Botan::operator* ( const BigInt & x,
const BigInt & y )

Multiply two integers

Parameters
xthe first factor
ythe second factor
Returns
(x * y)

Definition at line 57 of file big_ops3.cpp.

57 {
58 const size_t x_sw = x.sig_words();
59 const size_t y_sw = y.sig_words();
60
62
63 if(x_sw == 1 && y_sw > 0) {
64 bigint_linmul3(z.mutable_data(), y._data(), y_sw, x.word_at(0));
65 } else if(y_sw == 1 && x_sw > 0) {
66 bigint_linmul3(z.mutable_data(), x._data(), x_sw, y.word_at(0));
67 } else if(x_sw > 0 && y_sw > 0) {
68 secure_vector<word> workspace(z.size());
69
71 z.size(),
72 x._data(),
73 x.size(),
74 x_sw,
75 y._data(),
76 y.size(),
77 y_sw,
78 workspace.data(),
79 workspace.size());
80 }
81
82 z.cond_flip_sign(x_sw > 0 && y_sw > 0 && x.sign() != y.sign());
83
84 return z;
85}
word * mutable_data()
Definition bigint.h:712
size_t size() const
Definition bigint.h:681
void cond_flip_sign(bool predicate)
Definition bigint.cpp:524
Sign sign() const
Definition bigint.h:641

References Botan::BigInt::_data(), bigint_linmul3(), bigint_mul(), Botan::BigInt::cond_flip_sign(), Botan::BigInt::mutable_data(), Botan::BigInt::sig_words(), Botan::BigInt::sign(), Botan::BigInt::size(), Botan::BigInt::with_capacity(), and Botan::BigInt::word_at().

◆ operator*() [3/12]

BigInt Botan::operator* ( const BigInt & x,
word y )

Multiply an integer by a word

Parameters
xthe first factor
ythe second factor
Returns
(x * y)

Definition at line 90 of file big_ops3.cpp.

90 {
91 const size_t x_sw = x.sig_words();
92
93 BigInt z = BigInt::with_capacity(x_sw + 1);
94 bigint_linmul3(z.mutable_data(), x._data(), x_sw, y);
95 z.set_sign(x.sign());
96 return z;
97}
void set_sign(Sign sign)
Definition bigint.h:663

References Botan::BigInt::_data(), bigint_linmul3(), Botan::BigInt::mutable_data(), Botan::BigInt::set_sign(), Botan::BigInt::sig_words(), Botan::BigInt::sign(), and Botan::BigInt::with_capacity().

◆ operator*() [4/12]

template<std::integral T>
donna128 Botan::operator* ( const donna128 & x,
T y )
inlineconstexpr

Definition at line 95 of file donna128.h.

95 {
96 BOTAN_ARG_CHECK(x.hi() == 0, "High 64 bits of donna128 set to zero during multiply");
97
98 uint64_t lo = 0;
99 uint64_t hi = 0;
100 mul64x64_128(x.lo(), static_cast<uint64_t>(y), &lo, &hi);
101 return donna128(lo, hi);
102}
constexpr uint64_t hi() const
Definition donna128.h:85
constexpr void mul64x64_128(uint64_t a, uint64_t b, uint64_t *lo, uint64_t *hi)
Definition mul128.h:24

References BOTAN_ARG_CHECK, Botan::donna128::hi(), Botan::donna128::lo(), and mul64x64_128().

◆ operator*() [5/12]

EC_Point Botan::operator* ( const EC_Point & point,
const BigInt & scalar )
inline

Multiply a point by a scalar

Parameters
pointthe point
scalarthe scalar
Returns
(point * scalar)

Definition at line 439 of file ec_point.h.

439 {
440 return point.mul(scalar);
441}

References Botan::EC_Point::mul().

◆ operator*() [6/12]

Ed25519_FieldElement Botan::operator* ( const Ed25519_FieldElement & x,
const Ed25519_FieldElement & y )
inlineconstexpr

Definition at line 313 of file ed25519_fe.h.

313 {
314 return Ed25519_FieldElement::mul(x, y);
315}
static constexpr Ed25519_FieldElement mul(const Ed25519_FieldElement &a, const Ed25519_FieldElement &b)
Definition ed25519_fe.h:242

References Botan::Ed25519_FieldElement::mul().

◆ operator*() [7/12]

Ed448Point Botan::operator* ( const Scalar448 & lhs,
const Ed448Point & rhs )

Syntax sugar for scalar multiplication.

Definition at line 370 of file ed448_internal.cpp.

370 {
371 return rhs.scalar_mul(lhs);
372}
Ed448Point scalar_mul(const Scalar448 &scalar) const
Scalar multiplication.

References Botan::Ed448Point::scalar_mul().

◆ operator*() [8/12]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator* ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Multiply the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 468 of file strong_type.h.

468 {
469 return Strong<T, Tags...>(a.get() * b.get());
470}

References Botan::detail::Strong_Base< T >::get().

◆ operator*() [9/12]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator* ( Strong< T1, Tags... > a,
T2 b )
constexpr

Multiply the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 457 of file strong_type.h.

457 {
458 return Strong<T1, Tags...>(a.get() * b);
459}

References Botan::detail::Strong_Base< T >::get().

◆ operator*() [10/12]

template<std::integral T>
donna128 Botan::operator* ( T y,
const donna128 & x )
inlineconstexpr

Definition at line 105 of file donna128.h.

105 {
106 return x * y;
107}

◆ operator*() [11/12]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator* ( T1 a,
Strong< T2, Tags... > b )
constexpr

Multiply the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 445 of file strong_type.h.

445 {
446 return Strong<T2, Tags...>(a * b.get());
447}

References Botan::detail::Strong_Base< T >::get().

◆ operator*() [12/12]

BigInt Botan::operator* ( word x,
const BigInt & y )
inline

Multiply a word by an integer

Parameters
xthe first factor
ythe second factor
Returns
(x * y)

Definition at line 1252 of file bigint.h.

1252 {
1253 return y * x;
1254}

◆ operator*=() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator*= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Multiply in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 752 of file strong_type.h.

752 {
753 a.get() *= b.get();
754 return a;
755}

References Botan::detail::Strong_Base< T >::get().

◆ operator*=() [2/2]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator*= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Multiply in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 740 of file strong_type.h.

740 {
741 a.get() *= b;
742 return a;
743}

References Botan::detail::Strong_Base< T >::get().

◆ operator+() [1/11]

BigInt Botan::operator+ ( const BigInt & x,
const BigInt & y )
inline

Add two integers

Parameters
xthe first addend
ythe second addend
Returns
(x + y)

Definition at line 1186 of file bigint.h.

1186 {
1187 return BigInt::add2(x, y._data(), y.sig_words(), y.sign());
1188}
static BigInt add2(const BigInt &x, const word y[], size_t y_words, Sign y_sign)
Definition big_ops3.cpp:20

References Botan::BigInt::_data(), Botan::BigInt::add2(), Botan::BigInt::sig_words(), and Botan::BigInt::sign().

◆ operator+() [2/11]

BigInt Botan::operator+ ( const BigInt & x,
word y )
inline

Add a word to an integer

Parameters
xthe first addend
ythe second addend
Returns
(x + y)

Definition at line 1196 of file bigint.h.

1196 {
1197 return BigInt::add2(x, &y, 1, BigInt::Positive);
1198}

References Botan::BigInt::add2(), and Botan::BigInt::Positive.

◆ operator+() [3/11]

donna128 Botan::operator+ ( const donna128 & x,
const donna128 & y )
inlineconstexpr

Definition at line 109 of file donna128.h.

109 {
110 donna128 z = x;
111 z += y;
112 return z;
113}

◆ operator+() [4/11]

donna128 Botan::operator+ ( const donna128 & x,
uint64_t y )
inlineconstexpr

Definition at line 115 of file donna128.h.

115 {
116 donna128 z = x;
117 z += y;
118 return z;
119}

◆ operator+() [5/11]

EC_Point Botan::operator+ ( const EC_Point & lhs,
const EC_Point & rhs )
inline

Add two points

Parameters
lhsthe first point
rhsthe second point
Returns
(lhs + rhs)

Definition at line 417 of file ec_point.h.

417 {
418 EC_Point tmp(lhs);
419 return tmp += rhs;
420}

◆ operator+() [6/11]

Ed25519_FieldElement Botan::operator+ ( const Ed25519_FieldElement & x,
const Ed25519_FieldElement & y )
inlineconstexpr

Definition at line 305 of file ed25519_fe.h.

305 {
306 return Ed25519_FieldElement::add(x, y);
307}
static constexpr Ed25519_FieldElement add(const Ed25519_FieldElement &a, const Ed25519_FieldElement &b)
Definition ed25519_fe.h:212

References Botan::Ed25519_FieldElement::add().

◆ operator+() [7/11]

OctetString Botan::operator+ ( const OctetString & x,
const OctetString & y )

Concatenate two strings

Parameters
xan octet string
yan octet string
Returns
x concatenated with y

Definition at line 99 of file symkey.cpp.

99 {
101 out += k1.bits_of();
102 out += k2.bits_of();
103 return OctetString(out);
104}

References Botan::OctetString::bits_of(), and OctetString.

◆ operator+() [8/11]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator+ ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Add the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 398 of file strong_type.h.

398 {
399 return Strong<T, Tags...>(a.get() + b.get());
400}

References Botan::detail::Strong_Base< T >::get().

◆ operator+() [9/11]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator+ ( Strong< T1, Tags... > a,
T2 b )
constexpr

Add the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 387 of file strong_type.h.

387 {
388 return Strong<T1, Tags...>(a.get() + b);
389}

References Botan::detail::Strong_Base< T >::get().

◆ operator+() [10/11]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator+ ( T1 a,
Strong< T2, Tags... > b )
constexpr

Add the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 375 of file strong_type.h.

375 {
376 return Strong<T2, Tags...>(a + b.get());
377}

References Botan::detail::Strong_Base< T >::get().

◆ operator+() [11/11]

BigInt Botan::operator+ ( word x,
const BigInt & y )
inline

Add an integer to a word

Parameters
xthe first addend
ythe second addend
Returns
(x + y)

Definition at line 1206 of file bigint.h.

1206 {
1207 return y + x;
1208}

◆ operator++() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator++ ( Strong< T, Tags... > & a)
constexpr

Increment the wrapped value (prefix)

Parameters
athe strong type to modify
Returns
the value after the operation

Definition at line 925 of file strong_type.h.

925 {
926 ++a.get();
927 return a;
928}

References Botan::detail::Strong_Base< T >::get().

◆ operator++() [2/2]

template<std::integral T, typename... Tags>
auto Botan::operator++ ( Strong< T, Tags... > & a,
int  )
constexpr

Increment the wrapped value (postfix)

Parameters
athe strong type to modify
Returns
the value before the operation

Definition at line 913 of file strong_type.h.

913 {
914 auto tmp = a;
915 ++a.get();
916 return tmp;
917}

References Botan::detail::Strong_Base< T >::get().

Referenced by generate_dsa_primes().

◆ operator+=() [1/7]

template<typename T, typename Alloc, typename L>
std::vector< T, Alloc > & Botan::operator+= ( std::vector< T, Alloc > & out,
const std::pair< const T *, L > & in )

Append a (pointer, length) pair to a vector

Parameters
outthe vector to append to
inthe elements to append
Returns
reference to out

Definition at line 204 of file secmem.h.

204 {
205 if(in.second > 0) {
206 out.insert(out.end(), in.first, in.first + in.second);
207 }
208 return out;
209}

◆ operator+=() [2/7]

template<typename T, typename Alloc, typename L>
std::vector< T, Alloc > & Botan::operator+= ( std::vector< T, Alloc > & out,
const std::pair< T *, L > & in )

Append a (pointer, length) pair to a vector

Parameters
outthe vector to append to
inthe elements to append
Returns
reference to out

Definition at line 218 of file secmem.h.

218 {
219 if(in.second > 0) {
220 out.insert(out.end(), in.first, in.first + in.second);
221 }
222 return out;
223}

◆ operator+=() [3/7]

template<typename T, typename Alloc, typename Alloc2>
std::vector< T, Alloc > & Botan::operator+= ( std::vector< T, Alloc > & out,
const std::vector< T, Alloc2 > & in )

Append the contents of one vector to another

Parameters
outthe vector to append to
inthe vector to append
Returns
reference to out

Definition at line 168 of file secmem.h.

168 {
169 out.insert(out.end(), in.begin(), in.end());
170 return out;
171}

◆ operator+=() [4/7]

template<typename T, typename Alloc>
std::vector< T, Alloc > & Botan::operator+= ( std::vector< T, Alloc > & out,
std::span< const T > in )

Append the contents of a span to a vector

Parameters
outthe vector to append to
inthe elements to append
Returns
reference to out

Definition at line 180 of file secmem.h.

180 {
181 out.insert(out.end(), in.begin(), in.end());
182 return out;
183}

◆ operator+=() [5/7]

template<typename T, typename Alloc>
std::vector< T, Alloc > & Botan::operator+= ( std::vector< T, Alloc > & out,
T in )

Append a single element to a vector

Parameters
outthe vector to append to
inthe element to append
Returns
reference to out

Definition at line 192 of file secmem.h.

192 {
193 out.push_back(in);
194 return out;
195}

◆ operator+=() [6/7]

template<std::integral T, typename... Tags>
auto Botan::operator+= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Add to the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 702 of file strong_type.h.

702 {
703 a.get() += b.get();
704 return a;
705}

References Botan::detail::Strong_Base< T >::get().

◆ operator+=() [7/7]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator+= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Add to the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 690 of file strong_type.h.

690 {
691 a.get() += b;
692 return a;
693}

References Botan::detail::Strong_Base< T >::get().

◆ operator-() [1/9]

BigInt Botan::operator- ( const BigInt & x,
const BigInt & y )
inline

Subtract two integers

Parameters
xthe minuend
ythe subtrahend
Returns
(x - y)

Definition at line 1216 of file bigint.h.

1216 {
1217 return BigInt::add2(x, y._data(), y.sig_words(), y.reverse_sign());
1218}
Sign reverse_sign() const
Definition bigint.h:647

References Botan::BigInt::_data(), Botan::BigInt::add2(), Botan::BigInt::reverse_sign(), and Botan::BigInt::sig_words().

◆ operator-() [2/9]

BigInt Botan::operator- ( const BigInt & x,
word y )
inline

Subtract a word from an integer

Parameters
xthe minuend
ythe subtrahend
Returns
(x - y)

Definition at line 1226 of file bigint.h.

1226 {
1227 return BigInt::add2(x, &y, 1, BigInt::Negative);
1228}

References Botan::BigInt::add2(), and Botan::BigInt::Negative.

◆ operator-() [3/9]

EC_Point Botan::operator- ( const EC_Point & lhs)
inline

Negate a point

Parameters
lhsthe point to negate
Returns
the additive inverse of lhs

Definition at line 407 of file ec_point.h.

407 {
408 return EC_Point(lhs).negate();
409}
EC_Point & negate()
Definition ec_point.h:136

References Botan::EC_Point::negate().

◆ operator-() [4/9]

EC_Point Botan::operator- ( const EC_Point & lhs,
const EC_Point & rhs )
inline

Subtract one point from another

Parameters
lhsthe minuend
rhsthe subtrahend
Returns
(lhs - rhs)

Definition at line 428 of file ec_point.h.

428 {
429 EC_Point tmp(lhs);
430 return tmp -= rhs;
431}

◆ operator-() [5/9]

Ed25519_FieldElement Botan::operator- ( const Ed25519_FieldElement & x)
inlineconstexpr

Definition at line 317 of file ed25519_fe.h.

317 {
319}
static constexpr Ed25519_FieldElement negate(const Ed25519_FieldElement &a)
Definition ed25519_fe.h:232

References Botan::Ed25519_FieldElement::negate().

◆ operator-() [6/9]

Ed25519_FieldElement Botan::operator- ( const Ed25519_FieldElement & x,
const Ed25519_FieldElement & y )
inlineconstexpr

Definition at line 309 of file ed25519_fe.h.

309 {
310 return Ed25519_FieldElement::sub(x, y);
311}
static constexpr Ed25519_FieldElement sub(const Ed25519_FieldElement &a, const Ed25519_FieldElement &b)
Definition ed25519_fe.h:222

References Botan::Ed25519_FieldElement::sub().

◆ operator-() [7/9]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator- ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Subtract the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 433 of file strong_type.h.

433 {
434 return Strong<T, Tags...>(a.get() - b.get());
435}

References Botan::detail::Strong_Base< T >::get().

◆ operator-() [8/9]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator- ( Strong< T1, Tags... > a,
T2 b )
constexpr

Subtract the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 422 of file strong_type.h.

422 {
423 return Strong<T1, Tags...>(a.get() - b);
424}

References Botan::detail::Strong_Base< T >::get().

◆ operator-() [9/9]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator- ( T1 a,
Strong< T2, Tags... > b )
constexpr

Subtract the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 410 of file strong_type.h.

410 {
411 return Strong<T2, Tags...>(a - b.get());
412}

References Botan::detail::Strong_Base< T >::get().

◆ operator--() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator-- ( Strong< T, Tags... > & a)
constexpr

Decrement the wrapped value (prefix)

Parameters
athe strong type to modify
Returns
the value after the operation

Definition at line 948 of file strong_type.h.

948 {
949 --a.get();
950 return a;
951}

References Botan::detail::Strong_Base< T >::get().

◆ operator--() [2/2]

template<std::integral T, typename... Tags>
auto Botan::operator-- ( Strong< T, Tags... > & a,
int  )
constexpr

Decrement the wrapped value (postfix)

Parameters
athe strong type to modify
Returns
the value before the operation

Definition at line 936 of file strong_type.h.

936 {
937 auto tmp = a;
938 --a.get();
939 return tmp;
940}

References Botan::detail::Strong_Base< T >::get().

◆ operator-=() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator-= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Subtract from the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 727 of file strong_type.h.

727 {
728 a.get() -= b.get();
729 return a;
730}

References Botan::detail::Strong_Base< T >::get().

◆ operator-=() [2/2]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator-= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Subtract from the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 715 of file strong_type.h.

715 {
716 a.get() -= b;
717 return a;
718}

References Botan::detail::Strong_Base< T >::get().

◆ operator/() [1/5]

BigInt Botan::operator/ ( const BigInt & x,
const BigInt & d )

Divide two integers

Parameters
xthe dividend
dthe divisor
Returns
(x / d), rounded towards zero

Definition at line 102 of file big_ops3.cpp.

102 {
103 if(y.sig_words() == 1 && y.signum() >= 0) {
104 return x / y.word_at(0);
105 }
106
107 BigInt q;
108 BigInt r;
109 ct_divide(x, y, q, r);
110 return q;
111}

References ct_divide(), Botan::BigInt::sig_words(), Botan::BigInt::signum(), and Botan::BigInt::word_at().

◆ operator/() [2/5]

BigInt Botan::operator/ ( const BigInt & x,
word m )

Divide an integer by a word

Parameters
xthe dividend
mthe divisor
Returns
(x / m), rounded towards zero

Definition at line 116 of file big_ops3.cpp.

116 {
117 if(y == 0) {
118 throw Invalid_Argument("BigInt::operator/ divide by zero");
119 }
120
121 BigInt q;
122 word r = 0;
123 ct_divide_word(x, y, q, r);
124 return q;
125}

References ct_divide_word().

◆ operator/() [3/5]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator/ ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Divide the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 503 of file strong_type.h.

503 {
504 return Strong<T, Tags...>(a.get() / b.get());
505}

References Botan::detail::Strong_Base< T >::get().

◆ operator/() [4/5]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator/ ( Strong< T1, Tags... > a,
T2 b )
constexpr

Divide the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 492 of file strong_type.h.

492 {
493 return Strong<T1, Tags...>(a.get() / b);
494}

References Botan::detail::Strong_Base< T >::get().

◆ operator/() [5/5]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator/ ( T1 a,
Strong< T2, Tags... > b )
constexpr

Divide the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 480 of file strong_type.h.

480 {
481 return Strong<T2, Tags...>(a / b.get());
482}

References Botan::detail::Strong_Base< T >::get().

◆ operator/=() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator/= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Divide in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 777 of file strong_type.h.

777 {
778 a.get() /= b.get();
779 return a;
780}

References Botan::detail::Strong_Base< T >::get().

◆ operator/=() [2/2]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator/= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Divide in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 765 of file strong_type.h.

765 {
766 a.get() /= b;
767 return a;
768}

References Botan::detail::Strong_Base< T >::get().

◆ operator<() [1/5]

bool Botan::operator< ( const ASN1_Time & x,
const ASN1_Time & y )

Compare two times

Returns
true if x is earlier than y

Definition at line 319 of file asn1_time.cpp.

319 {
320 return (t1.cmp(t2) < 0);
321}

References Botan::ASN1_Time::cmp().

◆ operator<() [2/5]

bool Botan::operator< ( const BigInt & a,
const BigInt & b )
inline

Compare two integers

Parameters
athe first operand
bthe second operand
Returns
true if a is less than b

Definition at line 1350 of file bigint.h.

1350 {
1351 return a.is_less_than(b);
1352}
bool is_less_than(const BigInt &n) const
Definition bigint.cpp:165

References Botan::BigInt::is_less_than().

◆ operator<() [3/5]

bool Botan::operator< ( const BigInt & a,
word b )
inline

Compare an integer with a word

Parameters
athe first operand
bthe second operand
Returns
true if a is less than b

Definition at line 1410 of file bigint.h.

1410 {
1411 return (a.cmp_word(b) < 0);
1412}

References Botan::BigInt::cmp_word().

◆ operator<() [4/5]

bool Botan::operator< ( const OID & a,
const OID & b )

Compare two OIDs.

Parameters
athe first OID
bthe second OID
Returns
true if a is lexicographically smaller than b

Definition at line 175 of file asn1_oid.cpp.

175 {
176 const std::vector<uint32_t>& oid1 = a.get_components();
177 const std::vector<uint32_t>& oid2 = b.get_components();
178
179 return std::lexicographical_compare(oid1.begin(), oid1.end(), oid2.begin(), oid2.end());
180}

References Botan::OID::get_components().

Referenced by Botan::Cert_Extension::TNAuthList::encompasses().

◆ operator<() [5/5]

bool Botan::operator< ( const X509_DN & dn1,
const X509_DN & dn2 )

Definition at line 355 of file x509_dn.cpp.

355 {
356 return dn1._canonical_bytes() < dn2._canonical_bytes();
357}
const std::vector< uint8_t > & _canonical_bytes() const
Definition pkix_types.h:274

References Botan::X509_DN::_canonical_bytes().

◆ operator<<() [1/12]

BigInt Botan::operator<< ( const BigInt & x,
size_t n )

Shift an integer left

Parameters
xthe value to shift
nthe number of bits to shift by
Returns
(x << n)

Definition at line 184 of file big_ops3.cpp.

184 {
185 if(shift >= 65536) {
186 throw Invalid_Argument("BigInt left shift count too large");
187 }
188
189 if(x.is_zero()) {
190 return BigInt::zero();
191 }
192
193 const size_t x_sw = x.sig_words();
194
195 const size_t new_size = x_sw + shift / WordInfo<word>::bits + 1;
196 BigInt y = BigInt::with_capacity(new_size);
197 bigint_shl2(y.mutable_data(), new_size, x._data(), x_sw, shift);
198 y.set_sign(x.sign());
199 return y;
200}
constexpr void bigint_shl2(W y[], size_t y_size, const W x[], size_t x_size, size_t shift)
Definition mp_core.h:359

References Botan::BigInt::_data(), bigint_shl2(), Botan::BigInt::is_zero(), Botan::BigInt::mutable_data(), Botan::BigInt::set_sign(), Botan::BigInt::sig_words(), Botan::BigInt::sign(), Botan::BigInt::with_capacity(), and Botan::BigInt::zero().

◆ operator<<() [2/12]

int Botan::operator<< ( int out,
Pipe & pipe )

Stream output operator; dumps the results from pipe's default message to the output stream.

Parameters
outfile descriptor for an open output stream
pipethe pipe

Definition at line 19 of file fd_unix.cpp.

19 {
21 while(pipe.remaining() > 0) {
22 size_t got = pipe.read(buffer.data(), buffer.size());
23 size_t position = 0;
24 while(got > 0) {
25 const ssize_t ret = ::write(fd, &buffer[position], got);
26 if(ret < 0) {
27 if(errno == EINTR) {
28 continue;
29 }
30 throw Stream_IO_Error("Pipe output operator (unixfd) has failed");
31 }
32
33 position += static_cast<size_t>(ret);
34 got -= static_cast<size_t>(ret);
35 }
36 }
37 return fd;
38}
size_t read(uint8_t output[], size_t length) override
Definition pipe_rw.cpp:84
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
Definition pipe_rw.cpp:129
constexpr size_t DefaultBufferSize
Definition types.h:150

References DefaultBufferSize, Botan::Pipe::read(), and Botan::Pipe::remaining().

◆ operator<<() [3/12]

std::ostream & Botan::operator<< ( std::ostream & os,
const GeneralName & gn )

Definition at line 785 of file name_constraint.cpp.

785 {
786 os << gn.type() << ":" << gn.name();
787 return os;
788}
std::string type() const
std::string name() const

References Botan::GeneralName::name(), and Botan::GeneralName::type().

◆ operator<<() [4/12]

std::ostream & Botan::operator<< ( std::ostream & os,
const GeneralSubtree & gs )

Definition at line 826 of file name_constraint.cpp.

826 {
827 os << gs.base();
828 return os;
829}
const GeneralName & base() const
Definition pkix_types.h:735

References Botan::GeneralSubtree::base().

◆ operator<<() [5/12]

template<typename T, typename... Tags>
decltype(auto) Botan::operator<< ( std::ostream & os,
const Strong< T, Tags... > & v )

Write the wrapped value to an output stream

Parameters
osthe output stream
vthe strong type to write
Returns
reference to the output stream

Definition at line 295 of file strong_type.h.

295 {
296 return os << v.get();
297}

References Botan::detail::Strong_Base< T >::get().

◆ operator<<() [6/12]

std::ostream & Botan::operator<< ( std::ostream & out,
const OID & oid )

Write an OID to a stream, in the format produced by OID::to_string

Parameters
outthe stream to write to
oidthe OID to write
Returns
the stream

Definition at line 308 of file asn1_oid.cpp.

308 {
309 out << oid.to_string();
310 return out;
311}

References Botan::OID::to_string().

◆ operator<<() [7/12]

std::ostream & Botan::operator<< ( std::ostream & out,
const X509_DN & dn )

Definition at line 488 of file x509_dn.cpp.

488 {
489 const auto& rdns = dn.rdns();
490
491 // Escape characters as a backslash plus two hex digits per byte
492 // See RFC 4514 Sections 2.4 and 4
493 const auto hex_escape = [](std::ostream& s, char c) {
494 const auto b = static_cast<uint8_t>(c);
495 s << '\\' << nibble_to_hex(b >> 4) << nibble_to_hex(b);
496 };
497
498 // AVAs within the same RDN are joined with '+' (per RFC 4514), so a
499 // multi-valued RDN remains distinguishable from multiple single-valued
500 // RDNs separated by ','.
501 bool first_rdn = true;
502 for(const auto& rdn : rdns) {
503 if(!first_rdn) {
504 out << ",";
505 }
506 first_rdn = false;
507
508 bool first_ava = true;
509 for(const auto& ava : rdn) {
510 if(!first_ava) {
511 out << "+";
512 }
513 first_ava = false;
514 out << to_short_form(ava.first) << "=\"";
515 const std::string_view value = ava.second.value();
516 size_t pos = 0;
517 while(pos < value.size()) {
518 const size_t start = pos;
519
520 uint32_t cp = 0;
521 try {
522 cp = next_utf8_codepoint(value, pos);
523 } catch(const Decoding_Error&) {
524 // value() should always be valid UTF-8, but escape defensively otherwise
525 hex_escape(out, value[start]);
526 pos = start + 1;
527 continue;
528 }
529
530 if(cp == '\\' || cp == '"') {
531 out << '\\' << static_cast<char>(cp);
532 } else if(is_unicode_control_char(cp)) {
533 for(size_t i = start; i < pos; ++i) {
534 hex_escape(out, value[i]);
535 }
536 } else {
537 out << value.substr(start, pos - start);
538 }
539 }
540 out << "\"";
541 }
542 }
543 return out;
544}
const std::vector< std::vector< std::pair< OID, ASN1_String > > > & rdns() const
Definition pkix_types.h:229

References is_unicode_control_char(), next_utf8_codepoint(), nibble_to_hex(), and Botan::X509_DN::rdns().

◆ operator<<() [8/12]

std::ostream & Botan::operator<< ( std::ostream & out,
Pipe & pipe )

Stream output operator; dumps the results from pipe's default message to the output stream.

Parameters
outan output stream
pipethe pipe

Definition at line 19 of file pipe_io.cpp.

19 {
21 while(stream.good() && pipe.remaining() > 0) {
22 const size_t got = pipe.read(buffer.data(), buffer.size());
23 stream.write(cast_uint8_ptr_to_char(buffer.data()), static_cast<std::streamsize>(got));
24 }
25 if(!stream.good()) {
26 throw Stream_IO_Error("Pipe output operator (iostream) has failed");
27 }
28 return stream;
29}

References cast_uint8_ptr_to_char(), DefaultBufferSize, Botan::Pipe::read(), and Botan::Pipe::remaining().

◆ operator<<() [9/12]

std::ostream & Botan::operator<< ( std::ostream & stream,
const BigInt & n )

Write an integer to an output stream

Parameters
Stream Ciphersthe stream to write to
nthe integer to write
Returns
reference to the stream

Definition at line 19 of file big_io.cpp.

19 {
20 const auto stream_flags = stream.flags();
21 if((stream_flags & std::ios::oct) != 0) {
22 throw Invalid_Argument("Octal output of BigInt not supported");
23 }
24
25 const size_t base = (stream_flags & std::ios::hex) != 0 ? 16 : 10;
26
27 if(base == 10) {
28 stream << n.to_dec_string();
29 } else {
30 stream << n.to_hex_string();
31 }
32
33 if(!stream.good()) {
34 throw Stream_IO_Error("BigInt output operator has failed");
35 }
36 return stream;
37}
std::string to_dec_string() const
Definition big_code.cpp:40
std::string to_hex_string() const
Definition big_code.cpp:108

References Botan::BigInt::to_dec_string(), and Botan::BigInt::to_hex_string().

◆ operator<<() [10/12]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator<< ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Left shift the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 678 of file strong_type.h.

678 {
679 return Strong<T, Tags...>(a.get() << b.get());
680}

References Botan::detail::Strong_Base< T >::get().

◆ operator<<() [11/12]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator<< ( Strong< T1, Tags... > a,
T2 b )
constexpr

Left shift the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 667 of file strong_type.h.

667 {
668 return Strong<T1, Tags...>(a.get() << b);
669}

References Botan::detail::Strong_Base< T >::get().

◆ operator<<() [12/12]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator<< ( T1 a,
Strong< T2, Tags... > b )
constexpr

Left shift the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 655 of file strong_type.h.

655 {
656 return Strong<T2, Tags...>(a << b.get());
657}

References Botan::detail::Strong_Base< T >::get().

◆ operator<<=() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator<<= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Left shift in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 902 of file strong_type.h.

902 {
903 a.get() <<= b.get();
904 return a;
905}

References Botan::detail::Strong_Base< T >::get().

◆ operator<<=() [2/2]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator<<= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Left shift in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 890 of file strong_type.h.

890 {
891 a.get() <<= b;
892 return a;
893}

References Botan::detail::Strong_Base< T >::get().

◆ operator<=() [1/3]

bool Botan::operator<= ( const ASN1_Time & x,
const ASN1_Time & y )

Compare two times

Returns
true if x is not later than y

Definition at line 311 of file asn1_time.cpp.

311 {
312 return (t1.cmp(t2) <= 0);
313}

References Botan::ASN1_Time::cmp().

◆ operator<=() [2/3]

bool Botan::operator<= ( const BigInt & a,
const BigInt & b )
inline

Compare two integers

Parameters
athe first operand
bthe second operand
Returns
true if a is less than or equal to b

Definition at line 1330 of file bigint.h.

1330 {
1331 return (a.cmp(b) <= 0);
1332}
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition bigint.cpp:139

References Botan::BigInt::cmp().

◆ operator<=() [3/3]

bool Botan::operator<= ( const BigInt & a,
word b )
inline

Compare an integer with a word

Parameters
athe first operand
bthe second operand
Returns
true if a is less than or equal to b

Definition at line 1390 of file bigint.h.

1390 {
1391 return (a.cmp_word(b) <= 0);
1392}

References Botan::BigInt::cmp_word().

◆ operator<=>() [1/3]

template<typename T, typename... Tags>
auto Botan::operator<=> ( const Strong< T, Tags... > & lhs,
const Strong< T, Tags... > & rhs )

Three-way comparison

Parameters
lhsthe first operand (strong type)
rhsthe second operand (strong type)
Returns
the ordering of lhs relative to rhs

Definition at line 319 of file strong_type.h.

319 =>(const Strong<T, Tags...>& lhs, const Strong<T, Tags...>& rhs) {
320 return lhs.get() <=> rhs.get();
321}

References Botan::detail::Strong_Base< T >::get(), and operator<=>().

Referenced by operator<=>().

◆ operator<=>() [2/3]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator<=> ( Strong< T1, Tags... > a,
T2 b )

Three-way comparison

Parameters
athe first operand (strong type)
bthe second operand (plain number)
Returns
the ordering of a relative to b

Definition at line 341 of file strong_type.h.

341 =>(Strong<T1, Tags...> a, T2 b) {
342 return a.get() <=> b;
343}

References Botan::detail::Strong_Base< T >::get().

◆ operator<=>() [3/3]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator<=> ( T1 a,
Strong< T2, Tags... > b )

Three-way comparison

Parameters
athe first operand (plain number)
bthe second operand (strong type)
Returns
the ordering of a relative to b

Definition at line 330 of file strong_type.h.

330 =>(T1 a, Strong<T2, Tags...> b) {
331 return a <=> b.get();
332}

References Botan::detail::Strong_Base< T >::get().

◆ operator==() [1/13]

bool Botan::operator== ( const AlgorithmIdentifier & x,
const AlgorithmIdentifier & y )

Compare two AlgorithmIdentifiers

Parameters
xthe first AlgorithmIdentifier
ythe second AlgorithmIdentifier
Returns
true if x is equal to y

Definition at line 54 of file alg_id.cpp.

54 {
55 return (x.oid() == y.oid() && x.parameters() == y.parameters());
56}
const std::vector< uint8_t > & parameters() const
Definition asn1_obj.h:693

References Botan::AlgorithmIdentifier::oid(), and Botan::AlgorithmIdentifier::parameters().

◆ operator==() [2/13]

bool Botan::operator== ( const ASN1_Time & x,
const ASN1_Time & y )

Compare two times

Returns
true if x is equal to y

Definition at line 303 of file asn1_time.cpp.

303 {
304 return (t1.cmp(t2) == 0);
305}

References Botan::ASN1_Time::cmp().

◆ operator==() [3/13]

bool Botan::operator== ( const BigInt & a,
const BigInt & b )
inline

Compare two integers

Parameters
athe first operand
bthe second operand
Returns
true if a is equal to b

Definition at line 1310 of file bigint.h.

1310 {
1311 return a.is_equal(b);
1312}

◆ operator==() [4/13]

bool Botan::operator== ( const BigInt & a,
word b )
inline

Compare an integer with a word

Parameters
athe first operand
bthe second operand
Returns
true if a is equal to b

Definition at line 1370 of file bigint.h.

1370 {
1371 return (a.cmp_word(b) == 0);
1372}

References Botan::BigInt::cmp_word().

◆ operator==() [5/13]

◆ operator==() [6/13]

bool Botan::operator== ( const CRL_Entry & lhs,
const CRL_Entry & rhs )

Test two CRL entries for equality in all fields.

Definition at line 52 of file crl_ent.cpp.

52 {
53 if(a1.serial() != a2.serial()) {
54 return false;
55 }
56 if(a1.expire_time() != a2.expire_time()) {
57 return false;
58 }
59 if(a1.reason_code() != a2.reason_code()) {
60 return false;
61 }
62 return true;
63}

References Botan::CRL_Entry::expire_time(), Botan::CRL_Entry::reason_code(), and Botan::CRL_Entry::serial().

◆ operator==() [7/13]

bool Botan::operator== ( const OctetString & x,
const OctetString & y )

Compare two strings

Parameters
xan octet string
yan octet string
Returns
if x is equal to y

Definition at line 85 of file symkey.cpp.

85 {
86 return (s1.bits_of() == s2.bits_of());
87}

References Botan::OctetString::bits_of().

◆ operator==() [8/13]

template<typename T, typename U>
bool Botan::operator== ( const secure_allocator< T > & ,
const secure_allocator< U > &  )
inline

Compare two secure allocators

All instances are interchangeable, so this is always true.

Returns
always true

Definition at line 112 of file secmem.h.

112 {
113 return true;
114}

◆ operator==() [9/13]

template<typename T, typename... Tags>
bool Botan::operator== ( const Strong< T, Tags... > & lhs,
const Strong< T, Tags... > & rhs )

Compare for equality

Parameters
lhsthe first operand (strong type)
rhsthe second operand (strong type)
Returns
true if lhs and rhs are equal

Definition at line 307 of file strong_type.h.

307 {
308 return lhs.get() == rhs.get();
309}

References Botan::detail::Strong_Base< T >::get().

◆ operator==() [10/13]

template<bitvectorish T1, bitvectorish T2>
bool Botan::operator== ( const T1 & lhs,
const T2 & rhs )

Definition at line 1463 of file bitvector.h.

1463 {
1464 return lhs.equals_vartime(rhs);
1465}

◆ operator==() [11/13]

bool Botan::operator== ( const X509_DN & dn1,
const X509_DN & dn2 )

Definition at line 340 of file x509_dn.cpp.

340 {
341 return dn1._canonical_bytes() == dn2._canonical_bytes();
342}

References Botan::X509_DN::_canonical_bytes().

◆ operator==() [12/13]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator== ( Strong< T1, Tags... > a,
T2 b )

Compare for equality

Parameters
athe first operand (strong type)
bthe second operand (plain number)
Returns
true if a and b are equal

Definition at line 363 of file strong_type.h.

363 {
364 return a.get() == b;
365}

References Botan::detail::Strong_Base< T >::get().

◆ operator==() [13/13]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator== ( T1 a,
Strong< T2, Tags... > b )

Compare for equality

Parameters
athe first operand (plain number)
bthe second operand (strong type)
Returns
true if a and b are equal

Definition at line 352 of file strong_type.h.

352 {
353 return a == b.get();
354}

References Botan::detail::Strong_Base< T >::get().

◆ operator>() [1/3]

bool Botan::operator> ( const ASN1_Time & x,
const ASN1_Time & y )

Compare two times

Returns
true if x is later than y

Definition at line 323 of file asn1_time.cpp.

323 {
324 return (t1.cmp(t2) > 0);
325}

References Botan::ASN1_Time::cmp().

◆ operator>() [2/3]

bool Botan::operator> ( const BigInt & a,
const BigInt & b )
inline

Compare two integers

Parameters
athe first operand
bthe second operand
Returns
true if a is greater than b

Definition at line 1360 of file bigint.h.

1360 {
1361 return b.is_less_than(a);
1362}

References Botan::BigInt::is_less_than().

◆ operator>() [3/3]

bool Botan::operator> ( const BigInt & a,
word b )
inline

Compare an integer with a word

Parameters
athe first operand
bthe second operand
Returns
true if a is greater than b

Definition at line 1420 of file bigint.h.

1420 {
1421 return (a.cmp_word(b) > 0);
1422}

References Botan::BigInt::cmp_word().

◆ operator>=() [1/3]

bool Botan::operator>= ( const ASN1_Time & x,
const ASN1_Time & y )

Compare two times

Returns
true if x is not earlier than y

Definition at line 315 of file asn1_time.cpp.

315 {
316 return (t1.cmp(t2) >= 0);
317}

References Botan::ASN1_Time::cmp().

◆ operator>=() [2/3]

bool Botan::operator>= ( const BigInt & a,
const BigInt & b )
inline

Compare two integers

Parameters
athe first operand
bthe second operand
Returns
true if a is greater than or equal to b

Definition at line 1340 of file bigint.h.

1340 {
1341 return (a.cmp(b) >= 0);
1342}

References Botan::BigInt::cmp().

◆ operator>=() [3/3]

bool Botan::operator>= ( const BigInt & a,
word b )
inline

Compare an integer with a word

Parameters
athe first operand
bthe second operand
Returns
true if a is greater than or equal to b

Definition at line 1400 of file bigint.h.

1400 {
1401 return (a.cmp_word(b) >= 0);
1402}

References Botan::BigInt::cmp_word().

◆ operator>>() [1/8]

BigInt Botan::operator>> ( const BigInt & x,
size_t n )

Shift an integer right

Parameters
xthe value to shift
nthe number of bits to shift by
Returns
(x >> n)

Definition at line 205 of file big_ops3.cpp.

205 {
206 const size_t shift_words = shift / WordInfo<word>::bits;
207 const size_t x_sw = x.sig_words();
208
209 if(shift_words >= x_sw) {
210 return BigInt::zero();
211 }
212
213 const size_t new_size = x_sw - shift_words;
214 BigInt y = BigInt::with_capacity(new_size);
215 bigint_shr2(y.mutable_data(), new_size, x._data(), x_sw, shift);
216
217 if(x.signum() < 0 && y.is_zero()) {
218 y.set_sign(BigInt::Positive);
219 } else {
220 y.set_sign(x.sign());
221 }
222
223 return y;
224}

References Botan::BigInt::_data(), bigint_shr2(), Botan::BigInt::is_zero(), Botan::BigInt::mutable_data(), Botan::BigInt::Positive, Botan::BigInt::set_sign(), Botan::BigInt::sig_words(), Botan::BigInt::sign(), Botan::BigInt::signum(), Botan::BigInt::with_capacity(), and Botan::BigInt::zero().

◆ operator>>() [2/8]

int Botan::operator>> ( int in,
Pipe & pipe )

File descriptor input operator; dumps the remaining bytes of input to the (assumed open) pipe message.

Parameters
infile descriptor for an open input stream
pipethe pipe

Definition at line 43 of file fd_unix.cpp.

43 {
45 while(true) {
46 const ssize_t ret = ::read(fd, buffer.data(), buffer.size());
47 if(ret < 0) {
48 if(errno == EINTR) {
49 continue;
50 }
51 throw Stream_IO_Error("Pipe input operator (unixfd) has failed");
52 } else if(ret == 0) {
53 break;
54 }
55 pipe.write(buffer.data(), static_cast<size_t>(ret));
56 }
57 return fd;
58}
void write(const uint8_t in[], size_t length)
Definition pipe_rw.cpp:42

References DefaultBufferSize, and Botan::Pipe::write().

◆ operator>>() [3/8]

std::istream & Botan::operator>> ( std::istream & in,
Pipe & pipe )

Stream input operator; dumps the remaining bytes of input to the (assumed open) pipe message.

Parameters
inthe input stream
pipethe pipe

Definition at line 34 of file pipe_io.cpp.

34 {
36 while(stream.good()) {
37 stream.read(cast_uint8_ptr_to_char(buffer.data()), static_cast<std::streamsize>(buffer.size()));
38 const size_t got = static_cast<size_t>(stream.gcount());
39 pipe.write(buffer.data(), got);
40 }
41 if(stream.bad() || (stream.fail() && !stream.eof())) {
42 throw Stream_IO_Error("Pipe input operator (iostream) has failed");
43 }
44 return stream;
45}

References cast_uint8_ptr_to_char(), DefaultBufferSize, and Botan::Pipe::write().

◆ operator>>() [4/8]

std::istream & Botan::operator>> ( std::istream & in,
X509_DN & dn )

Parse the input stream as a DN Prefer X509_DN::parse

Definition at line 689 of file x509_dn.cpp.

689 {
690 const std::istreambuf_iterator<char> begin(in);
691 const std::istreambuf_iterator<char> end;
692 const std::string contents(begin, end);
693
694 if(auto parsed = X509_DN::parse(contents)) {
695 dn = std::move(*parsed);
696 } else {
697 in.setstate(std::ios::failbit);
698 }
699 return in;
700}
static std::optional< X509_DN > parse(std::string_view str)
Definition x509_dn.cpp:551

References Botan::X509_DN::parse().

◆ operator>>() [5/8]

std::istream & Botan::operator>> ( std::istream & stream,
BigInt & n )

Read an integer from an input stream

Parameters
Stream Ciphersthe stream to read from
nset to the integer which was read
Returns
reference to the stream

Definition at line 42 of file big_io.cpp.

42 {
43 std::string str;
44 std::getline(stream, str);
45 if(stream.bad() || (stream.fail() && !stream.eof())) {
46 throw Stream_IO_Error("BigInt input operator has failed");
47 }
48 n = BigInt(str);
49 return stream;
50}

◆ operator>>() [6/8]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator>> ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Right shift the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 643 of file strong_type.h.

643 {
644 return Strong<T, Tags...>(a.get() >> b.get());
645}

References Botan::detail::Strong_Base< T >::get().

◆ operator>>() [7/8]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator>> ( Strong< T1, Tags... > a,
T2 b )
constexpr

Right shift the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 632 of file strong_type.h.

632 {
633 return Strong<T1, Tags...>(a.get() >> b);
634}

References Botan::detail::Strong_Base< T >::get().

◆ operator>>() [8/8]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator>> ( T1 a,
Strong< T2, Tags... > b )
constexpr

Right shift the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 620 of file strong_type.h.

620 {
621 return Strong<T2, Tags...>(a >> b.get());
622}

References Botan::detail::Strong_Base< T >::get().

◆ operator>>=() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator>>= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Right shift in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 877 of file strong_type.h.

877 {
878 a.get() >>= b.get();
879 return a;
880}

References Botan::detail::Strong_Base< T >::get().

◆ operator>>=() [2/2]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator>>= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Right shift in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 865 of file strong_type.h.

865 {
866 a.get() >>= b;
867 return a;
868}

References Botan::detail::Strong_Base< T >::get().

◆ operator^() [1/5]

OctetString Botan::operator^ ( const OctetString & x,
const OctetString & y )

XOR two strings

Parameters
xan octet string
yan octet string
Returns
x XORed with y

Definition at line 109 of file symkey.cpp.

109 {
110 secure_vector<uint8_t> out(std::max(k1.length(), k2.length()));
111
112 copy_mem(out.data(), k1.begin(), k1.length());
113 xor_buf(out.data(), k2.begin(), k2.length());
114 return OctetString(out);
115}

References Botan::OctetString::begin(), copy_mem(), Botan::OctetString::length(), OctetString, and xor_buf().

◆ operator^() [2/5]

template<bitvectorish T1, bitvectorish T2>
auto Botan::operator^ ( const T1 & lhs,
const T2 & rhs )

Definition at line 1456 of file bitvector.h.

1456 {
1457 auto res = detail::copy_lhs_allocator_aware(lhs, rhs);
1458 res ^= rhs;
1459 return res;
1460}

References Botan::detail::copy_lhs_allocator_aware().

◆ operator^() [3/5]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator^ ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Bitwise XOR of the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 538 of file strong_type.h.

538 {
539 return Strong<T, Tags...>(a.get() ^ b.get());
540}

References Botan::detail::Strong_Base< T >::get().

◆ operator^() [4/5]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator^ ( Strong< T1, Tags... > a,
T2 b )
constexpr

Bitwise XOR of the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 527 of file strong_type.h.

527 {
528 return Strong<T1, Tags...>(a.get() ^ b);
529}

References Botan::detail::Strong_Base< T >::get().

◆ operator^() [5/5]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator^ ( T1 a,
Strong< T2, Tags... > b )
constexpr

Bitwise XOR of the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 515 of file strong_type.h.

515 {
516 return Strong<T2, Tags...>(a ^ b.get());
517}

References Botan::detail::Strong_Base< T >::get().

◆ operator^=() [1/3]

template<typename Alloc, typename Alloc2>
std::vector< uint8_t, Alloc > & Botan::operator^= ( std::vector< uint8_t, Alloc > & out,
const std::vector< uint8_t, Alloc2 > & in )

XOR a vector into another, growing the destination if it is shorter

Parameters
outthe vector to XOR into
inthe vector to read from
Returns
reference to out

Definition at line 532 of file mem_ops.h.

532 {
533 if(out.size() < in.size()) {
534 out.resize(in.size());
535 }
536
537 xor_buf(std::span{out}.first(in.size()), in);
538 return out;
539}

References xor_buf().

◆ operator^=() [2/3]

template<std::integral T, typename... Tags>
auto Botan::operator^= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Bitwise XOR in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 802 of file strong_type.h.

802 {
803 a.get() ^= b.get();
804 return a;
805}

References Botan::detail::Strong_Base< T >::get().

◆ operator^=() [3/3]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator^= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Bitwise XOR in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 790 of file strong_type.h.

790 {
791 a.get() ^= b;
792 return a;
793}

References Botan::detail::Strong_Base< T >::get().

◆ operator|() [1/12]

ASN1_Class Botan::operator| ( ASN1_Class x,
ASN1_Class y )
inline

Return the bitwise combination of two class tags

Definition at line 91 of file asn1_obj.h.

91 {
92 return static_cast<ASN1_Class>(static_cast<uint32_t>(x) | static_cast<uint32_t>(y));
93}
ASN1_Class
Definition asn1_obj.h:32

◆ operator|() [2/12]

uint32_t Botan::operator| ( ASN1_Class x,
ASN1_Type y )
inline

Combine a class tag and a type tag into a single tagging value

Definition at line 105 of file asn1_obj.h.

105 {
106 return static_cast<uint32_t>(x) | static_cast<uint32_t>(y);
107}

◆ operator|() [3/12]

uint32_t Botan::operator| ( ASN1_Type x,
ASN1_Class y )
inline

Combine a type tag and a class tag into a single tagging value

Definition at line 98 of file asn1_obj.h.

98 {
99 return static_cast<uint32_t>(x) | static_cast<uint32_t>(y);
100}

◆ operator|() [4/12]

ASN1_Type Botan::operator| ( ASN1_Type x,
ASN1_Type y )
inline

Return the bitwise combination of two type tags

Definition at line 84 of file asn1_obj.h.

84 {
85 return static_cast<ASN1_Type>(static_cast<uint32_t>(x) | static_cast<uint32_t>(y));
86}

◆ operator|() [5/12]

donna128 Botan::operator| ( const donna128 & x,
const donna128 & y )
inlineconstexpr

Definition at line 121 of file donna128.h.

121 {
122 return donna128(x.lo() | y.lo(), x.hi() | y.hi());
123}

References Botan::donna128::hi(), and Botan::donna128::lo().

◆ operator|() [6/12]

donna128 Botan::operator| ( const donna128 & x,
uint64_t y )
inlineconstexpr

Definition at line 125 of file donna128.h.

125 {
126 return donna128(x.lo() | y, x.hi());
127}

References Botan::donna128::hi(), and Botan::donna128::lo().

◆ operator|() [7/12]

template<bitvectorish T1, bitvectorish T2>
auto Botan::operator| ( const T1 & lhs,
const T2 & rhs )

Definition at line 1442 of file bitvector.h.

1442 {
1443 auto res = detail::copy_lhs_allocator_aware(lhs, rhs);
1444 res |= rhs;
1445 return res;
1446}

References Botan::detail::copy_lhs_allocator_aware().

◆ operator|() [8/12]

ECIES_Flags Botan::operator| ( ECIES_Flags a,
ECIES_Flags b )
inline

Definition at line 65 of file ecies.h.

65 {
66 // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
67 return static_cast<ECIES_Flags>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
68}

◆ operator|() [9/12]

ReasonFlags Botan::operator| ( ReasonFlags::Bits a,
ReasonFlags::Bits b )
inline

Definition at line 269 of file pkix_enums.h.

269 {
270 return ReasonFlags(static_cast<uint16_t>(static_cast<uint16_t>(a) | static_cast<uint16_t>(b)));
271}

◆ operator|() [10/12]

template<std::integral T, typename... Tags>
decltype(auto) Botan::operator| ( Strong< T, Tags... > a,
Strong< T, Tags... > b )
constexpr

Bitwise OR of the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 608 of file strong_type.h.

608 {
609 return Strong<T, Tags...>(a.get() | b.get());
610}

References Botan::detail::Strong_Base< T >::get().

◆ operator|() [11/12]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator| ( Strong< T1, Tags... > a,
T2 b )
constexpr

Bitwise OR of the wrapped values

Parameters
athe left hand operand (strong type)
bthe right hand operand (plain number)
Returns
the result, wrapped in the strong type

Definition at line 597 of file strong_type.h.

597 {
598 return Strong<T1, Tags...>(a.get() | b);
599}

References Botan::detail::Strong_Base< T >::get().

◆ operator|() [12/12]

template<std::integral T1, std::integral T2, typename... Tags>
decltype(auto) Botan::operator| ( T1 a,
Strong< T2, Tags... > b )
constexpr

Bitwise OR of the wrapped values

Parameters
athe left hand operand (plain number)
bthe right hand operand (strong type)
Returns
the result, wrapped in the strong type

Definition at line 585 of file strong_type.h.

585 {
586 return Strong<T2, Tags...>(a | b.get());
587}

References Botan::detail::Strong_Base< T >::get().

◆ operator|=() [1/2]

template<std::integral T, typename... Tags>
auto Botan::operator|= ( Strong< T, Tags... > & a,
Strong< T, Tags... > b )
constexpr

Bitwise OR in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (strong type)
Returns
reference to a

Definition at line 852 of file strong_type.h.

852 {
853 a.get() |= b.get();
854 return a;
855}

References Botan::detail::Strong_Base< T >::get().

◆ operator|=() [2/2]

template<std::integral T1, std::integral T2, typename... Tags>
auto Botan::operator|= ( Strong< T1, Tags... > & a,
T2 b )
constexpr

Bitwise OR in place the wrapped value

Parameters
athe strong type to modify
bthe right hand operand (plain number)
Returns
reference to a

Definition at line 840 of file strong_type.h.

840 {
841 a.get() |= b;
842 return a;
843}

References Botan::detail::Strong_Base< T >::get().

◆ OS2ECP() [1/3]

EC_Point Botan::OS2ECP ( const uint8_t data[],
size_t data_len,
const CurveGFp & curve )

Perform point decoding Use EC_Group::OS2ECP instead

Definition at line 870 of file ec_point.cpp.

870 {
871 if(data_len == 1 && data[0] == 0) {
872 // SEC1 standard representation of the point at infinity
873 return EC_Point(curve);
874 }
875
876 const auto [g_x, g_y] = OS2ECP(data, data_len, curve.get_p(), curve.get_a(), curve.get_b());
877
878 EC_Point point(curve, g_x, g_y);
879
880 if(!point.on_the_curve()) {
881 throw Decoding_Error("OS2ECP: Decoded point was not on the curve");
882 }
883
884 return point;
885}
const BigInt & get_a() const
Definition ec_point.cpp:37
const BigInt & get_p() const
Definition ec_point.cpp:45
const BigInt & get_b() const
Definition ec_point.cpp:41
EC_Point OS2ECP(std::span< const uint8_t > data, const CurveGFp &curve)
Definition ec_point.cpp:866

References Botan::CurveGFp::get_a(), Botan::CurveGFp::get_b(), Botan::CurveGFp::get_p(), Botan::EC_Point::on_the_curve(), and OS2ECP().

◆ OS2ECP() [2/3]

std::pair< BigInt, BigInt > BOTAN_UNSTABLE_API Botan::OS2ECP ( const uint8_t data[],
size_t data_len,
const BigInt & curve_p,
const BigInt & curve_a,
const BigInt & curve_b )

Perform point decoding

This is an internal function which was accidentally made public. Do not use it; it will be removed in Botan4.

Parameters
datathe encoded point
data_lenlength of data in bytes
curve_pthe curve equation prime
curve_athe curve equation a parameter
curve_bthe curve equation b parameter

Definition at line 887 of file ec_point.cpp.

887 {
888 if(pt_len <= 1) {
889 throw Decoding_Error("OS2ECP invalid point encoding");
890 }
891
892 const uint8_t pc = pt[0];
893 const size_t p_bytes = p.bytes();
894
895 BigInt x;
896 BigInt y;
897
898 if(pc == 2 || pc == 3) {
899 if(pt_len != 1 + p_bytes) {
900 throw Decoding_Error("OS2ECP invalid point encoding");
901 }
902 x = BigInt::decode(&pt[1], pt_len - 1);
903
904 const bool y_mod_2 = ((pc & 0x01) == 1);
905 y = decompress_point(y_mod_2, x, p, a, b);
906 } else if(pc == 4) {
907 if(pt_len != 1 + 2 * p_bytes) {
908 throw Decoding_Error("OS2ECP invalid point encoding");
909 }
910
911 x = BigInt::decode(&pt[1], p_bytes);
912 y = BigInt::decode(&pt[p_bytes + 1], p_bytes);
913 } else if(pc == 6 || pc == 7) {
914 if(pt_len != 1 + 2 * p_bytes) {
915 throw Decoding_Error("OS2ECP invalid point encoding");
916 }
917
918 x = BigInt::decode(&pt[1], p_bytes);
919 y = BigInt::decode(&pt[p_bytes + 1], p_bytes);
920
921 const bool y_mod_2 = ((pc & 0x01) == 1);
922
923 if(decompress_point(y_mod_2, x, p, a, b) != y) {
924 throw Decoding_Error("OS2ECP: Decoding error in hybrid format");
925 }
926 } else {
927 throw Decoding_Error("OS2ECP: Unknown format type " + std::to_string(static_cast<int>(pc)));
928 }
929
930 if(x >= p || y >= p) {
931 throw Decoding_Error("OS2ECP invalid point encoding");
932 }
933
934 return std::make_pair(x, y);
935}
static BigInt decode(const uint8_t buf[], size_t length)
Definition bigint.h:943

References Botan::BigInt::bytes(), and Botan::BigInt::decode().

◆ OS2ECP() [3/3]

EC_Point BOTAN_UNSTABLE_API Botan::OS2ECP ( std::span< const uint8_t > data,
const CurveGFp & curve )

Perform point decoding

Parameters
datathe encoded point
curvethe curve the point is on
Returns
the decoded point

Definition at line 866 of file ec_point.cpp.

866 {
867 return OS2ECP(data.data(), data.size(), curve);
868}

References OS2ECP().

Referenced by OS2ECP(), OS2ECP(), Botan::EC_Group_Data::point_deserialize_compressed(), and Botan::EC_Group_Data::point_deserialize_uncompressed().

◆ out_ptr()

template<typename T>
auto Botan::out_ptr ( T & outptr)
nodiscardconstexprnoexcept

Definition at line 164 of file stl_util.h.

164 {
165 class out_ptr_t {
166 public:
167 constexpr ~out_ptr_t() noexcept {
168 m_ptr.reset(m_rawptr);
169 m_rawptr = nullptr;
170 }
171
172 constexpr explicit out_ptr_t(T& outptr) noexcept : m_ptr(outptr), m_rawptr(nullptr) {}
173
174 out_ptr_t(const out_ptr_t&) = delete;
175 out_ptr_t(out_ptr_t&&) = delete;
176 out_ptr_t& operator=(const out_ptr_t&) = delete;
177 out_ptr_t& operator=(out_ptr_t&&) = delete;
178
179 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor) - Implicit by design for C API interop
180 [[nodiscard]] constexpr operator typename T::element_type **() && noexcept { return &m_rawptr; }
181
182 private:
183 T& m_ptr;
184 typename T::element_type* m_rawptr;
185 };
186
187 return out_ptr_t{outptr};
188}

Referenced by Botan::TPM2::Object::_public_info(), base_decode(), Botan::TPM2::PrivateKey::create_transient_from_template(), Botan::TPM2::HashFunction::final_with_ticket(), hex_decode(), Botan::TPM2::Signature_Operation::sign(), and Botan::TPM2::Session::tpm_nonce().

◆ overloaded()

template<class... Ts>
Botan::overloaded ( Ts... ) -> overloaded< Ts... >

◆ P0()

uint32_t Botan::P0 ( uint32_t X)
inline

Definition at line 17 of file sm3_fn.h.

17 {
18 return X ^ rotl<9>(X) ^ rotl<17>(X);
19}

References rotl().

Referenced by R1(), R2(), and redc_crandall().

◆ P1()

uint32_t Botan::P1 ( uint32_t X)
inline

Definition at line 65 of file sm3_fn.h.

65 {
66 return X ^ rotl<15>(X) ^ rotl<23>(X);
67}

References rotl().

Referenced by SM3_E().

◆ p_div_2_plus_1()

template<WordType W, size_t N>
std::array< W, N > Botan::p_div_2_plus_1 ( const std::array< W, N > & p)
inlineconsteval

Definition at line 206 of file pcurves_util.h.

206 {
207 const W one = 1;
208 std::array<W, N> r = p;
210 bigint_add2(r.data(), N, &one, 1);
211 return r;
212}
constexpr auto bigint_add2(W x[], size_t x_size, const W y[], size_t y_size) -> W
Definition mp_core.h:98
constexpr W shift_right(std::array< W, N > &x)
Definition mp_core.h:904

References bigint_add2(), and shift_right().

Referenced by Botan::IntMod< MontgomeryRep< ScalarParams > >::_invert_vartime_div2_helper(), and Botan::IntMod< MontgomeryRep< ScalarParams > >::div2().

◆ p_minus()

template<uint8_t X, WordType W, size_t N>
std::array< W, N > Botan::p_minus ( const std::array< W, N > & p)
inlineconsteval

Definition at line 175 of file pcurves_util.h.

175 {
176 // TODO combine into p_plus_x_over_y<-1, 1>
177 static_assert(X > 0);
178 std::array<W, N> r{};
179 W x = X;
180 bigint_sub3(r.data(), p.data(), N, &x, 1);
181 std::reverse(r.begin(), r.end());
182 return r;
183}

References bigint_sub3().

◆ p_minus_1_over_2()

template<WordType W, size_t N>
std::array< W, N > Botan::p_minus_1_over_2 ( const std::array< W, N > & p)
inlineconsteval

Definition at line 196 of file pcurves_util.h.

196 {
197 const W one = 1;
198 std::array<W, N> r{};
199 bigint_sub3(r.data(), p.data(), N, &one, 1);
201 std::reverse(r.begin(), r.end());
202 return r;
203}

References bigint_sub3(), and shift_right().

Referenced by shanks_tonelli_c4(), and Botan::IntMod< MontgomeryRep< ScalarParams > >::sqrt().

◆ p_plus_1_over_4()

template<WordType W, size_t N>
std::array< W, N > Botan::p_plus_1_over_4 ( const std::array< W, N > & p)
inlineconsteval

Definition at line 186 of file pcurves_util.h.

186 {
187 const W one = 1;
188 std::array<W, N> r{};
189 bigint_add3(r.data(), p.data(), N, &one, 1);
191 std::reverse(r.begin(), r.end());
192 return r;
193}

References bigint_add3(), and shift_right().

Referenced by Botan::IntMod< MontgomeryRep< ScalarParams > >::sqrt().

◆ parse_legacy_enc_options()

PK_Encryption_Options Botan::parse_legacy_enc_options ( const Public_Key & key,
std::string_view params )

Definition at line 248 of file pk_options_impl.cpp.

248 {
249 /*
250 * As with parse_legacy_sig_options, this handles the padding strings accepted
251 * prior to the introduction of PK_Encryption_Options.
252 */
253
254 if(key.algo_name() == "SM2") {
255 // The only parameter is the hash function, which defaults to SM3
256 return PK_Encryption_Options().with_hash(params);
257 }
258
259 /*
260 * Everything else (RSA, ElGamal, and the RSA implementations of the hardware
261 * providers) takes an EME specification:
262 *
263 * Raw
264 * PKCS1v15 (or the alias EME-PKCS1-v1_5)
265 * OAEP(hash), OAEP(hash,MGF1), OAEP(hash,MGF1,label), OAEP(hash,MGF1(mgf_hash)),
266 * OAEP(hash,MGF1(mgf_hash),label) (or the aliases EME-OAEP and EME1)
267 */
268
269 // TODO(Botan4) Remove all but "PKCS1v15"
270 if(params == "PKCS1v15" || params == "EME-PKCS1-v1_5") {
271 return PK_Encryption_Options().with_padding("PKCS1v15");
272 }
273
274 // Schemes which require a padding reject this when the operation is created
275 if(params.empty()) {
276 return PK_Encryption_Options();
277 }
278
279 // TODO(Botan4) Remove all but "OAEP" here
280 if(params.starts_with("OAEP") || params.starts_with("EME-OAEP") || params.starts_with("EME1")) {
281 const AlgorithmSpec req(params);
282
283 auto oaep_opt = PK_Encryption_Options().with_padding("OAEP");
284
285 if(auto m = req.match("OAEP|EME-OAEP|EME1({hash})")) {
286 return oaep_opt.with_hash(m->str("hash"));
287 }
288
289 if(auto m = req.match("OAEP|EME-OAEP|EME1({hash},MGF1,{label:str=})")) {
290 return oaep_opt.with_hash(m->str("hash")).with_context(m->str("label"));
291 }
292
293 if(auto m = req.match("OAEP|EME-OAEP|EME1({hash},MGF1({mgf_hash}),{label:str=})")) {
294 return oaep_opt.with_hash(m->str("hash")).with_mgf1_hash(m->str("mgf_hash")).with_context(m->str("label"));
295 }
296 }
297
298 // Anything else, including "Raw", is treated as the name of a padding scheme
299 return PK_Encryption_Options().with_padding(params);
300}
virtual std::string algo_name() const =0
PK_Encryption_Options with_padding(std::string_view padding)
PK_Encryption_Options with_hash(std::string_view hash)

References Botan::Asymmetric_Key::algo_name(), Botan::AlgorithmSpec::match(), Botan::PK_Encryption_Options::with_hash(), and Botan::PK_Encryption_Options::with_padding().

Referenced by Botan::Private_Key::create_decryption_op(), Botan::Public_Key::create_encryption_op(), Botan::PK_Decryptor_EME::PK_Decryptor_EME(), and Botan::PK_Encryptor_EME::PK_Encryptor_EME().

◆ parse_legacy_ka_options()

PK_Key_Agreement_Options Botan::parse_legacy_ka_options ( std::string_view params)

Definition at line 313 of file pk_options_impl.cpp.

313 {
314 // The string interface has always required naming a KDF (or "Raw")
315 if(params.empty()) {
316 throw Invalid_Argument("Key agreement requires specifying a KDF, or Raw to use the agreed value directly");
317 } else if(params == "Raw") {
318 return PK_Key_Agreement_Options().with_raw_shared_key();
319 } else {
320 return PK_Key_Agreement_Options().with_kdf(params);
321 }
322}
PK_Key_Agreement_Options with_kdf(std::string_view kdf)

References Botan::PK_Key_Agreement_Options::with_kdf(), and Botan::PK_Key_Agreement_Options::with_raw_shared_key().

Referenced by Botan::Private_Key::create_key_agreement_op(), and Botan::PK_Key_Agreement::PK_Key_Agreement().

◆ parse_legacy_kem_options()

PK_KEM_Options Botan::parse_legacy_kem_options ( std::string_view params)

Definition at line 302 of file pk_options_impl.cpp.

302 {
303 // The string interface has always required naming a KDF (or "Raw")
304 if(params.empty()) {
305 throw Invalid_Argument("KEM requires specifying a KDF, or Raw to use the shared key directly");
306 } else if(params == "Raw") {
307 return PK_KEM_Options().with_raw_shared_key();
308 } else {
309 return PK_KEM_Options().with_kdf(params);
310 }
311}
PK_KEM_Options with_kdf(std::string_view kdf)

References Botan::PK_KEM_Options::with_kdf(), and Botan::PK_KEM_Options::with_raw_shared_key().

Referenced by Botan::Private_Key::create_kem_decryption_op(), Botan::Public_Key::create_kem_encryption_op(), Botan::PK_KEM_Decryptor::PK_KEM_Decryptor(), and Botan::PK_KEM_Encryptor::PK_KEM_Encryptor().

◆ parse_legacy_sig_options()

PK_Signature_Options Botan::parse_legacy_sig_options ( const Public_Key & key,
std::string_view params )

Definition at line 16 of file pk_options_impl.cpp.

16 {
17 /*
18 * This is a convoluted mess because we must handle dispatch for every algorithm
19 * specific detail of how padding strings were formatted in versions prior to the
20 * introduction of PK_Signature_Options.
21 *
22 * This will all go away once the deprecated constructors of PK_Signer and PK_Verifier
23 * are removed in Botan4.
24 */
25
26 const std::string algo = key.algo_name();
27
28 if(algo.starts_with("Dilithium") || algo.starts_with("ML-DSA") || algo == "SLH-DSA" || algo == "SPHINCS+") {
29 if(!params.empty() && params != "Randomized" && params != "Deterministic" && params != "Pure") {
30 throw Invalid_Argument(fmt("Unexpected parameters '{}' for signing with {}", params, algo));
31 }
32
33 if(params == "Deterministic" || params == "Pure") {
34 return PK_Signature_Options().with_deterministic_signature();
35 } else {
36 return PK_Signature_Options();
37 }
38 }
39
40 if(algo == "SM2") {
41 /*
42 * SM2 parameters have the following possible formats:
43 * Ident [since 2.2.0]
44 * Ident,Hash [since 2.3.0]
45 *
46 * Historically a completely empty parameter string was treated as
47 * if the identity was empty. This probably should have instead been
48 * treated as if it was the "default userid" ("1234567812345678") but
49 * there was a bug and it wasn't.
50 *
51 * TODO(Botan4) evaluate if this should be changed
52 */
53 std::string userid;
54 std::string hash = "SM3";
55 const auto comma = params.find(',');
56 if(comma == std::string::npos) {
57 userid = params;
58 } else {
59 userid = params.substr(0, comma);
60 hash = params.substr(comma + 1, std::string::npos);
61 }
62
63 // With a "Raw" hash there is no ZA computation, and the identity was always ignored
64 if(hash == "Raw") {
66 }
67
68 return PK_Signature_Options().with_hash(hash).with_context(userid);
69 }
70
71 if(algo == "Ed25519") {
72 if(params.empty() || params == "Identity" || params == "Pure") {
73 return PK_Signature_Options();
74 } else if(params == "Ed25519ph") {
76 } else {
77 return PK_Signature_Options().with_prehash(std::string(params));
78 }
79 }
80
81 if(algo == "Ed448") {
82 if(params.empty() || params == "Identity" || params == "Pure" || params == "Ed448") {
83 return PK_Signature_Options();
84 } else if(params == "Ed448ph") {
86 } else {
87 return PK_Signature_Options().with_prehash(std::string(params));
88 }
89 }
90
91 if(algo == "RSA") {
92 // handling various deprecated aliases that have accumulated over the years ...
93 const auto canonical_padding = [](std::string_view alg) -> std::string_view {
94 // TODO(Botan4) Remove all but "PKCSv15"
95 if(alg == "EMSA_PKCS1" || alg == "EMSA-PKCS1-v1_5" || alg == "EMSA3") {
96 return "PKCS1v15";
97 }
98
99 // TODO(Botan4) Remove this alias
100 if(alg == "PSSR_Raw") {
101 return "PSS_Raw";
102 }
103
104 // TODO(Botan4) Remove all but "PSS"
105 if(alg == "PSSR" || alg == "EMSA-PSS" || alg == "PSS-MGF1" || alg == "EMSA4") {
106 return "PSS";
107 }
108
109 // TODO(Botan4) Remove all but "X9.31"
110 if(alg == "EMSA_X931" || alg == "EMSA2" || alg == "X9.31") {
111 return "X9.31";
112 }
113
114 return alg;
115 };
116
117 const AlgorithmSpec given(params);
118 const AlgorithmSpec req = given.with_head(canonical_padding(given.head()));
119
120 if(auto m = req.match("Raw({hash?})")) {
121 if(m->has("hash")) {
123 std::string(m->str("hash")));
124 }
125 return PK_Signature_Options().with_padding("Raw");
126 }
127
128 if(auto m = req.match("PKCS1v15(Raw,{hash?})")) {
129 if(m->has("hash")) {
130 return PK_Signature_Options()
131 .with_padding("PKCS1v15")
132 .with_externally_computed_prehash(std::string(m->str("hash")));
133 }
135 }
136
137 if(auto m = req.match("PKCS1v15({hash})")) {
138 return PK_Signature_Options().with_padding("PKCS1v15").with_hash(m->str("hash"));
139 }
140
141 // Only supported by PKCS#11 (CKM_RSA_9796)
142 if(req.matches("ISO9796")) {
143 return PK_Signature_Options().with_padding("ISO9796");
144 }
145
146 if(req.matches("PSS(Raw)")) {
148 }
149
150 if(auto m = req.match("PSS|PSS_Raw({hash})")) {
151 return PK_Signature_Options().with_padding(m->head()).with_hash(m->str("hash"));
152 }
153
154 if(auto m = req.match("PSS|PSS_Raw({hash},MGF1,{salt_len:int?})")) {
155 auto pss_opt = PK_Signature_Options().with_padding(m->head()).with_hash(m->str("hash"));
156
157 if(m->has("salt_len")) {
158 return std::move(pss_opt).with_salt_size(m->integer("salt_len"));
159 }
160 return pss_opt;
161 }
162
163 if(auto m = req.match("ISO_9796_DS2({hash},{trailer:str=exp},{salt_len:int?})")) {
164 const auto trailer = m->str("trailer");
165 if(trailer != "imp" && trailer != "exp") {
166 throw Invalid_Argument(fmt("Unexpected parameters '{}' for signing with {}", params, algo));
167 }
168
169 auto opt = PK_Signature_Options()
170 .with_padding("ISO_9796_DS2")
171 .with_hash(m->str("hash"))
172 .with_explicit_trailer_field(trailer == "exp");
173
174 if(m->has("salt_len")) {
175 return std::move(opt).with_salt_size(m->integer("salt_len"));
176 }
177 return opt;
178 }
179
180 //ISO-9796-2 DS 3 is deterministic and DS2 without a salt
181 if(auto m = req.match("ISO_9796_DS3({hash},{trailer:str=exp})")) {
182 const auto trailer = m->str("trailer");
183 if(trailer != "imp" && trailer != "exp") {
184 throw Invalid_Argument(fmt("Unexpected parameters '{}' for signing with {}", params, algo));
185 }
186
187 return PK_Signature_Options()
188 .with_padding("ISO_9796_DS3")
189 .with_hash(m->str("hash"))
190 .with_explicit_trailer_field(trailer == "exp");
191 }
192
193 if(req.matches("X9.31(Raw)")) {
195 }
196
197 if(auto m = req.match("X9.31({hash})")) {
198 return PK_Signature_Options().with_padding("X9.31").with_hash(m->str("hash"));
199 }
200 } // RSA block
201
202 if(params.empty()) {
203 return PK_Signature_Options();
204 }
205
206 // ECDSA/DSA/ECKCDSA/etc
207
208 /*
209 * Stopgap until PK_Signature_Options is exposed through the FFI: a
210 * trailing ",Deterministic" (eg "SHA-256,Deterministic") requests a
211 * deterministic signature, so that RFC 6979 ECDSA remains reachable
212 * through the string based interfaces.
213 */
214 const std::string_view det_suffix = ",Deterministic";
215 const bool deterministic = params.ends_with(det_suffix);
216 const std::string_view hash_params = deterministic ? params.substr(0, params.size() - det_suffix.size()) : params;
217
218 // "Raw" or "Raw(hash)" means the caller provides the digest
219 if(hash_params.starts_with("Raw")) {
220 const AlgorithmSpec req(hash_params);
221 const auto m = req.match("Raw({hash?})");
222 if(!m) {
223 throw Invalid_Argument(fmt("Unexpected parameters '{}' for signing with {}", params, algo));
224 }
225 auto raw_opt = PK_Signature_Options().with_deterministic_signature(deterministic);
226 if(m->has("hash")) {
227 return std::move(raw_opt).with_externally_computed_prehash(std::string(m->str("hash")));
228 }
229 return std::move(raw_opt).with_externally_computed_prehash();
230 }
231
232 const auto hash = [&]() -> std::string {
233 if(hash_params.starts_with("EMSA1")) {
234 const AlgorithmSpec req(hash_params);
235 const auto m = req.match("EMSA1({hash})");
236 if(!m) {
237 throw Invalid_Argument(fmt("Unexpected parameters '{}' for signing with {}", params, algo));
238 }
239 return std::string(m->str("hash"));
240 } else {
241 return std::string(hash_params);
242 }
243 }();
244
245 return PK_Signature_Options().with_hash(hash).with_deterministic_signature(deterministic);
246}
AlgorithmSpec with_head(std::string_view head) const
PK_Signature_Options with_explicit_trailer_field(bool trailer=true)
PK_Signature_Options with_deterministic_signature(bool deterministic=true)
PK_Signature_Options with_padding(std::string_view padding)
PK_Signature_Options with_hash(std::string_view hash)
PK_Signature_Options with_prehash(std::optional< std::string > prehash=std::nullopt)
PK_Signature_Options with_context(std::span< const uint8_t > context)
PK_Signature_Options with_externally_computed_prehash(std::optional< std::string > hash=std::nullopt)

References Botan::Asymmetric_Key::algo_name(), fmt(), Botan::AlgorithmSpec::head(), Botan::AlgorithmSpec::match(), Botan::AlgorithmSpec::matches(), Botan::PK_Signature_Options::with_context(), Botan::PK_Signature_Options::with_deterministic_signature(), Botan::PK_Signature_Options::with_explicit_trailer_field(), Botan::PK_Signature_Options::with_externally_computed_prehash(), Botan::PK_Signature_Options::with_hash(), Botan::AlgorithmSpec::with_head(), Botan::PK_Signature_Options::with_padding(), and Botan::PK_Signature_Options::with_prehash().

Referenced by Botan::Private_Key::create_signature_op(), Botan::Public_Key::create_verification_op(), Botan::PK_Signer::PK_Signer(), and Botan::PK_Verifier::PK_Verifier().

◆ parse_sz()

BOTAN_TEST_API std::optional< size_t > Botan::parse_sz ( std::string_view input,
bool require_canonical = false )

Attempt to parse a string as a size_t-sized decimal integer

Parameters
inputthe string to convert
require_canonicalif set, reject leading zeros ("007"); "0" is still accepted
Returns
integer value, or nullopt if invalid

Definition at line 71 of file parsing.cpp.

71 {
72 return parse_decimal_integer<size_t>(input, require_canonical);
73}

Referenced by Botan::IPv4Subnet::from_string(), Botan::IPv6Subnet::from_string(), and Botan::OS::read_env_variable_sz().

◆ parse_u16()

std::optional< uint16_t > Botan::parse_u16 ( std::string_view input,
bool require_canonical = false )

Attempt to parse a string as a 16-bit decimal integer

Parameters
inputthe string to convert
require_canonicalif set, reject leading zeros ("007"); "0" is still accepted
Returns
integer value, or nullopt if invalid

Definition at line 59 of file parsing.cpp.

59 {
60 return parse_decimal_integer<uint16_t>(input, require_canonical);
61}

Referenced by check_bcrypt(), and Botan::TLS::Text_Policy::srtp_profiles().

◆ parse_u32()

BOTAN_TEST_API std::optional< uint32_t > Botan::parse_u32 ( std::string_view input,
bool require_canonical = false )

Attempt to parse a string as a 32-bit decimal integer

Parameters
inputthe string to convert
require_canonicalif set, reject leading zeros ("007"); "0" is still accepted
Returns
integer value, or nullopt if invalid

Definition at line 63 of file parsing.cpp.

63 {
64 return parse_decimal_integer<uint32_t>(input, require_canonical);
65}

Referenced by to_u32bit().

◆ parse_u64()

BOTAN_TEST_API std::optional< uint64_t > Botan::parse_u64 ( std::string_view input,
bool require_canonical = false )

Attempt to parse a string as a 64-bit decimal integer

Parameters
inputthe string to convert
require_canonicalif set, reject leading zeros ("007"); "0" is still accepted
Returns
integer value, or nullopt if invalid

Definition at line 67 of file parsing.cpp.

67 {
68 return parse_decimal_integer<uint64_t>(input, require_canonical);
69}

◆ pbes2_decrypt()

secure_vector< uint8_t > Botan::pbes2_decrypt ( std::span< const uint8_t > key_bits,
std::string_view passphrase,
const std::vector< uint8_t > & params )

Decrypt a PKCS #5 v2.0 encrypted stream

Parameters
key_bitsthe input
passphrasethe passphrase to use for decryption
paramsthe PBES2 parameters

Definition at line 423 of file pbes2.cpp.

425 {
426 AlgorithmIdentifier kdf_algo;
427 AlgorithmIdentifier enc_algo;
428
431 .decode(kdf_algo)
432 .decode(enc_algo)
433 .end_cons()
434 .verify_end();
435
436 const std::string cipher = [&]() -> std::string {
437 if(const auto name = enc_algo.oid().registered_name()) {
438 const auto cipher_spec = split_on(*name, '/');
439 if(cipher_spec.size() == 2 && known_pbes_cipher_mode(cipher_spec[1])) {
440 return *name;
441 }
442 }
443
444 throw Decoding_Error(fmt("PBES2: Unknown/invalid cipher OID {}", enc_algo.oid()));
445 }();
446
447 std::vector<uint8_t> iv;
449
451 if(!dec) {
452 throw Decoding_Error(fmt("PBES2 cannot decrypt due to unavailable cipher '{}'", cipher));
453 }
454
455 // The cipher parameters carry the IV (RFC 8018 B.2). Require the length be the
456 // expected value; any other length has undocumented semantics.
457 if(iv.size() != dec->default_nonce_length()) {
458 throw Decoding_Error("PBES2 cipher AlgorithmIdentifier has invalid IV length");
459 }
460
461 const size_t default_key_size = dec->key_spec().maximum_keylength();
462 auto pbkdf = Pbes2KdfParameters::decode(kdf_algo);
463 dec->set_key(pbkdf->derive_key(passphrase, default_key_size));
464
465 dec->start(iv);
466
467 secure_vector<uint8_t> buf(key_bits.begin(), key_bits.end());
468 dec->finish(buf);
469
470 return buf;
471}
BER_Decoder & decode(bool &out)
Definition ber_dec.h:361
BER_Decoder & verify_end()
Definition ber_dec.cpp:471
BER_Decoder & end_cons()
Definition ber_dec.cpp:635
BER_Decoder start_sequence()
Definition ber_dec.h:279

References Botan::Cipher_Mode::create(), Botan::BER_Decoder::decode(), Decryption, Botan::BER_Decoder::Limits::DER(), Botan::BER_Decoder::end_cons(), fmt(), name, OctetString, Botan::AlgorithmIdentifier::oid(), Botan::AlgorithmIdentifier::parameters(), Botan::OID::registered_name(), split_on(), Botan::BER_Decoder::start_sequence(), and Botan::BER_Decoder::verify_end().

Referenced by pkcs12_pbe_decrypt().

◆ pbes2_encrypt()

std::pair< AlgorithmIdentifier, std::vector< uint8_t > > Botan::pbes2_encrypt ( std::span< const uint8_t > key_bits,
std::string_view passphrase,
std::chrono::milliseconds msec,
std::string_view cipher,
std::string_view digest,
RandomNumberGenerator & rng )

Encrypt with PBES2 from PKCS #5 v2.0

Parameters
key_bitsthe input
passphrasethe passphrase to use for encryption
msechow many milliseconds to run PBKDF2
cipherspecifies the block cipher to use to encrypt
digestspecifies the PRF to use with PBKDF2 (eg "HMAC(SHA-1)")
Random Number Generatorsa random number generator

Definition at line 385 of file pbes2.cpp.

390 {
391 size_t msec_in_iterations_out = static_cast<size_t>(msec.count());
392 return pbes2_encrypt_shared(key_bits, passphrase, &msec_in_iterations_out, 0, cipher, digest, rng);
393 // return value msec_in_iterations_out discarded
394}

◆ pbes2_encrypt_iter()

std::pair< AlgorithmIdentifier, std::vector< uint8_t > > Botan::pbes2_encrypt_iter ( std::span< const uint8_t > key_bits,
std::string_view passphrase,
size_t iterations,
std::string_view cipher,
std::string_view digest,
RandomNumberGenerator & rng )

Encrypt with PBES2 from PKCS #5 v2.0

Parameters
key_bitsthe input
passphrasethe passphrase to use for encryption
iterationshow many iterations to run PBKDF2
cipherspecifies the block cipher to use to encrypt
digestspecifies the PRF to use with PBKDF2 (eg "HMAC(SHA-1)")
Random Number Generatorsa random number generator

Definition at line 414 of file pbes2.cpp.

419 {
420 return pbes2_encrypt_shared(key_bits, passphrase, nullptr, pbkdf_iter, cipher, digest, rng);
421}

Referenced by Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(), and pkcs12_pbe_encrypt().

◆ pbes2_encrypt_msec()

std::pair< AlgorithmIdentifier, std::vector< uint8_t > > Botan::pbes2_encrypt_msec ( std::span< const uint8_t > key_bits,
std::string_view passphrase,
std::chrono::milliseconds msec,
size_t * out_iterations_if_nonnull,
std::string_view cipher,
std::string_view digest,
RandomNumberGenerator & rng )

Encrypt with PBES2 from PKCS #5 v2.0

Parameters
key_bitsthe input
passphrasethe passphrase to use for encryption
msechow many milliseconds to run PBKDF2
out_iterations_if_nonnullif not null, set to the number of PBKDF iterations used
cipherspecifies the block cipher to use to encrypt
digestspecifies the PRF to use with PBKDF2 (eg "HMAC(SHA-1)")
Random Number Generatorsa random number generator

Definition at line 396 of file pbes2.cpp.

402 {
403 size_t msec_in_iterations_out = static_cast<size_t>(msec.count());
404
405 auto ret = pbes2_encrypt_shared(key_bits, passphrase, &msec_in_iterations_out, 0, cipher, digest, rng);
406
407 if(out_iterations_if_nonnull != nullptr) {
408 *out_iterations_if_nonnull = msec_in_iterations_out;
409 }
410
411 return ret;
412}

Referenced by Botan::PKCS8::BER_encode(), and Botan::PKCS8::BER_encode_encrypted_pbkdf_msec().

◆ pbkdf2() [1/2]

void Botan::pbkdf2 ( MessageAuthenticationCode & prf,
uint8_t out[],
size_t out_len,
const uint8_t salt[],
size_t salt_len,
size_t iterations )

Perform PBKDF2. The prf is assumed to be keyed already.

Definition at line 92 of file pbkdf2.cpp.

97 {
98 if(iterations == 0) {
99 throw Invalid_Argument("PBKDF2: Invalid iteration count");
100 }
101
102 clear_mem(out, out_len);
103
104 if(out_len == 0) {
105 return;
106 }
107
108 const size_t prf_sz = prf.output_length();
109 BOTAN_ASSERT_NOMSG(prf_sz > 0);
110
111 // RFC 2898 Section 5.2: derived key length limited to (2^32 - 1) * hLen
112 const auto blocks_required = ceil_division<uint64_t>(out_len, prf_sz);
113 BOTAN_ARG_CHECK(blocks_required <= 0xFFFFFFFE, "PBKDF2 maximum output length exceeded");
114
115 secure_vector<uint8_t> U(prf_sz);
116
117 uint32_t counter = 1;
118 while(out_len > 0) {
119 const size_t prf_output = std::min<size_t>(prf_sz, out_len);
120
121 prf.update(salt, salt_len);
122 prf.update_be(counter++);
123 prf.final(U.data());
124
125 xor_buf(out, U.data(), prf_output);
126
127 for(size_t i = 1; i != iterations; ++i) {
128 prf.update(U);
129 prf.final(U.data());
130 xor_buf(out, U.data(), prf_output);
131 }
132
133 out_len -= prf_output;
134 out += prf_output;
135 }
136}

References BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, ceil_division(), clear_mem(), Botan::Buffered_Computation::final(), Botan::Buffered_Computation::output_length(), Botan::Buffered_Computation::update(), Botan::Buffered_Computation::update_be(), and xor_buf().

◆ pbkdf2() [2/2]

size_t Botan::pbkdf2 ( MessageAuthenticationCode & prf,
uint8_t out[],
size_t out_len,
std::string_view password,
const uint8_t salt[],
size_t salt_len,
size_t iterations,
std::chrono::milliseconds msec )

Definition at line 73 of file pbkdf2.cpp.

80 {
81 if(iterations == 0) {
82 iterations = tune_pbkdf2(prf, out_len, msec.count());
83 }
84
85 const PBKDF2 pbkdf2(prf, iterations);
86
87 pbkdf2.derive_key(out, out_len, password.data(), password.size(), salt, salt_len);
88
89 return iterations;
90}
size_t pbkdf2(MessageAuthenticationCode &prf, uint8_t out[], size_t out_len, std::string_view password, const uint8_t salt[], size_t salt_len, size_t iterations, std::chrono::milliseconds msec)
Definition pbkdf2.cpp:73

References pbkdf2().

Referenced by Botan::PBKDF2::derive_key(), Botan::Scrypt::derive_key(), Botan::PKCS5_PBKDF2::pbkdf(), and pbkdf2().

◆ pkcs12_kdf()

BOTAN_TEST_API void Botan::pkcs12_kdf ( std::span< uint8_t > out,
std::span< const uint8_t > pwd_bytes,
std::span< const uint8_t > salt,
size_t iterations,
uint8_t id,
HashFunction & hash )

Low-level PKCS#12 KDF (RFC 7292 Appendix B).

Runs the KDF on a caller-supplied pwd_bytes buffer without applying pkcs12_encode_password. Intended for the very rare case (e.g. OpenSSL empty-password interop) where the RFC 7292 UCS-2 BE encoding + null terminator is not the desired input. Normal callers should use the PKCS12_KDF class.

Definition at line 153 of file pkcs12_kdf.cpp.

158 {
159 pkcs12_kdf_with_hash(out, pwd_bytes, salt, iterations, id, hash);
160}

◆ pkcs12_pbe_decrypt()

secure_vector< uint8_t > Botan::pkcs12_pbe_decrypt ( std::span< const uint8_t > ciphertext,
std::string_view password,
const AlgorithmIdentifier & pbe_algo,
bool openssl_empty_pwd_compat = false )

Decrypt data protected by PKCS#12 PBE (RFC 7292 Appendix B) or PBES2.

Parameters
ciphertextthe encrypted data
passwordthe decryption password
pbe_algothe AlgorithmIdentifier from the EncryptedData structure
openssl_empty_pwd_compatif true and password is empty, the password is fed to the PKCS#12 KDF as an empty byte string (matching OpenSSL's non-conforming behavior) instead of the RFC 7292 form (a two-byte {0x00,0x00} terminator). Has no effect on PBES2 or when the password is non-empty.

Definition at line 92 of file pkcs12_pbe.cpp.

95 {
96 const OID& oid = pbe_algo.oid();
97
98 if(oid == OID::from_string("PBE-PKCS5v20")) {
99 // PBES2 (RFC 8018) uses PBKDF2, which is unambiguous for empty
100 // passwords, so the OpenSSL empty-password quirk does not apply.
101 return pbes2_decrypt(ciphertext, password, pbe_algo.parameters());
102 }
103
104 std::vector<uint8_t> salt;
105 size_t iterations = 0;
106 BER_Decoder(pbe_algo.parameters())
107 .start_sequence()
108 .decode(salt, ASN1_Type::OctetString)
109 .decode(iterations)
110 .verify_end()
111 .end_cons();
112
113 if(iterations == 0 || iterations > PKCS12_MAX_ITERATIONS) {
114 throw Decoding_Error(fmt("PKCS#12 PBE has invalid iteration count: {}", iterations));
115 }
116
117 const auto params = pkcs12_pbe_params_for_oid(oid);
118 auto [key, iv] = pkcs12_derive_key_iv(password, salt, iterations, params, openssl_empty_pwd_compat);
119
120 auto cipher = Cipher_Mode::create_or_throw(params.cipher_name, Cipher_Dir::Decryption);
121 cipher->set_key(key);
122 cipher->start(iv);
123
124 secure_vector<uint8_t> plaintext(ciphertext.begin(), ciphertext.end());
125 cipher->finish(plaintext);
126
127 return plaintext;
128}
static OID from_string(std::string_view str)
Definition asn1_oid.cpp:80
secure_vector< uint8_t > pbes2_decrypt(std::span< const uint8_t > key_bits, std::string_view passphrase, const std::vector< uint8_t > &params)
Definition pbes2.cpp:423
constexpr size_t PKCS12_MAX_ITERATIONS
Definition pkcs12_pbe.h:25

References Botan::Cipher_Mode::create_or_throw(), Botan::BER_Decoder::decode(), Decryption, Botan::BER_Decoder::end_cons(), fmt(), Botan::OID::from_string(), OctetString, Botan::AlgorithmIdentifier::oid(), Botan::AlgorithmIdentifier::parameters(), pbes2_decrypt(), PKCS12_MAX_ITERATIONS, Botan::BER_Decoder::start_sequence(), and Botan::BER_Decoder::verify_end().

◆ pkcs12_pbe_encrypt()

std::pair< AlgorithmIdentifier, std::vector< uint8_t > > Botan::pkcs12_pbe_encrypt ( std::span< const uint8_t > plaintext,
std::string_view password,
std::string_view algo,
size_t iterations,
RandomNumberGenerator & rng )

Encrypt data using PKCS#12 PBE (RFC 7292 Appendix B) or PBES2.

Parameters
plaintextthe data to encrypt
passwordthe encryption password
algoalgorithm name: "PBES2-SHA256-AES256", "PBES2-SHA256-AES128", "PBE-SHA1-3DES" (legacy), "PBE-SHA1-2DES" (legacy). Higher-level APIs default to "PBES2-SHA256-AES256" via PKCS12_Options.
iterationsPBKDF iteration count
Random Number Generatorsa random number generator
Returns
the AlgorithmIdentifier and encrypted data

Definition at line 130 of file pkcs12_pbe.cpp.

134 {
135 if(iterations == 0 || iterations > PKCS12_MAX_ITERATIONS) {
136 throw Invalid_Argument(fmt("PKCS#12 PBE: iteration count must be between 1 and {}", PKCS12_MAX_ITERATIONS));
137 }
138
139 if(algo == "PBES2-SHA256-AES256") {
140 auto [aid, ct] = pbes2_encrypt_iter(plaintext, password, iterations, "AES-256/CBC", "SHA-256", rng);
141 return {std::move(aid), std::move(ct)};
142 }
143 if(algo == "PBES2-SHA256-AES128") {
144 auto [aid, ct] = pbes2_encrypt_iter(plaintext, password, iterations, "AES-128/CBC", "SHA-256", rng);
145 return {std::move(aid), std::move(ct)};
146 }
147
148 const auto params = pkcs12_pbe_params_for_algo(algo);
149
150 std::vector<uint8_t> salt(8);
151 rng.randomize(salt.data(), salt.size());
152
153 auto [key, iv] = pkcs12_derive_key_iv(password, salt, iterations, params, false);
154
155 auto cipher = Cipher_Mode::create_or_throw(params.cipher_name, Cipher_Dir::Encryption);
156 cipher->set_key(key);
157 cipher->start(iv);
158
159 std::vector<uint8_t> ciphertext(plaintext.begin(), plaintext.end());
160 cipher->finish(ciphertext);
161
162 std::vector<uint8_t> enc_params;
163 DER_Encoder(enc_params).start_sequence().encode(salt, ASN1_Type::OctetString).encode(iterations).end_cons();
164
165 return {AlgorithmIdentifier(params.oid, enc_params), std::move(ciphertext)};
166}
DER_Encoder & start_sequence()
Definition der_enc.h:86
DER_Encoder & end_cons()
Definition der_enc.cpp:208
DER_Encoder & encode(bool b)
Definition der_enc.cpp:313
std::pair< AlgorithmIdentifier, std::vector< uint8_t > > pbes2_encrypt_iter(std::span< const uint8_t > key_bits, std::string_view passphrase, size_t pbkdf_iter, std::string_view cipher, std::string_view digest, RandomNumberGenerator &rng)
Definition pbes2.cpp:414

References Botan::Cipher_Mode::create_or_throw(), Botan::DER_Encoder::encode(), Encryption, Botan::DER_Encoder::end_cons(), fmt(), OctetString, pbes2_encrypt_iter(), PKCS12_MAX_ITERATIONS, Botan::RandomNumberGenerator::randomize(), and Botan::DER_Encoder::start_sequence().

Referenced by Botan::PKCS12::export_to().

◆ pkcs_hash_id()

std::vector< uint8_t > BOTAN_TEST_API Botan::pkcs_hash_id ( std::string_view hash_name)

Return the PKCS #1 hash identifier

See also
RFC 3447 section 9.2
Parameters
hash_namethe name of the hash function
Returns
uint8_t sequence identifying the hash
Exceptions
Invalid_Argumentif the hash has no known PKCS #1 hash id

Definition at line 78 of file hash_id.cpp.

78 {
79 // Special case for SSL/TLS RSA signatures
80 if(name == "Parallel(MD5,SHA-1)") {
81 return std::vector<uint8_t>();
82 }
83
84 // If you add a value to this function, also update test_hash_id.cpp
85
86 if(name == "MD5") {
87 return std::vector<uint8_t>(MD5_PKCS_ID, MD5_PKCS_ID + sizeof(MD5_PKCS_ID));
88 }
89
90 if(name == "RIPEMD-160") {
91 return std::vector<uint8_t>(RIPEMD_160_PKCS_ID, RIPEMD_160_PKCS_ID + sizeof(RIPEMD_160_PKCS_ID));
92 }
93
94 if(name == "SHA-1") {
95 return std::vector<uint8_t>(SHA_1_PKCS_ID, SHA_1_PKCS_ID + sizeof(SHA_1_PKCS_ID));
96 }
97
98 if(name == "SHA-224") {
99 return std::vector<uint8_t>(SHA_224_PKCS_ID, SHA_224_PKCS_ID + sizeof(SHA_224_PKCS_ID));
100 }
101
102 if(name == "SHA-256") {
103 return std::vector<uint8_t>(SHA_256_PKCS_ID, SHA_256_PKCS_ID + sizeof(SHA_256_PKCS_ID));
104 }
105
106 if(name == "SHA-384") {
107 return std::vector<uint8_t>(SHA_384_PKCS_ID, SHA_384_PKCS_ID + sizeof(SHA_384_PKCS_ID));
108 }
109
110 if(name == "SHA-512") {
111 return std::vector<uint8_t>(SHA_512_PKCS_ID, SHA_512_PKCS_ID + sizeof(SHA_512_PKCS_ID));
112 }
113
114 if(name == "SHA-512-256") {
115 return std::vector<uint8_t>(SHA_512_256_PKCS_ID, SHA_512_256_PKCS_ID + sizeof(SHA_512_256_PKCS_ID));
116 }
117
118 if(name == "SHA-3(224)") {
119 return std::vector<uint8_t>(SHA3_224_PKCS_ID, SHA3_224_PKCS_ID + sizeof(SHA3_224_PKCS_ID));
120 }
121
122 if(name == "SHA-3(256)") {
123 return std::vector<uint8_t>(SHA3_256_PKCS_ID, SHA3_256_PKCS_ID + sizeof(SHA3_256_PKCS_ID));
124 }
125
126 if(name == "SHA-3(384)") {
127 return std::vector<uint8_t>(SHA3_384_PKCS_ID, SHA3_384_PKCS_ID + sizeof(SHA3_384_PKCS_ID));
128 }
129
130 if(name == "SHA-3(512)") {
131 return std::vector<uint8_t>(SHA3_512_PKCS_ID, SHA3_512_PKCS_ID + sizeof(SHA3_512_PKCS_ID));
132 }
133
134 if(name == "SM3") {
135 return std::vector<uint8_t>(SM3_PKCS_ID, SM3_PKCS_ID + sizeof(SM3_PKCS_ID));
136 }
137
138 throw Invalid_Argument("No PKCS #1 identifier for " + std::string(name));
139}

References name.

Referenced by botan_pkcs_hash_id(), Botan::PKCS1v15_Raw_SignaturePaddingScheme::PKCS1v15_Raw_SignaturePaddingScheme(), and Botan::PKCS1v15_SignaturePaddingScheme::PKCS1v15_SignaturePaddingScheme().

◆ point_add()

template<typename ProjectivePoint, typename FieldElement>
ProjectivePoint Botan::point_add ( const ProjectivePoint & a,
const ProjectivePoint & b )
inlineconstexpr

Definition at line 188 of file pcurves_algos.h.

188 {
189 const auto a_is_identity = a.is_identity();
190 const auto b_is_identity = b.is_identity();
191
192 const auto Z1Z1 = a.z().square();
193 const auto Z2Z2 = b.z().square();
194 const auto U1 = a.x() * Z2Z2;
195 const auto U2 = b.x() * Z1Z1;
196 const auto S1 = a.y() * b.z() * Z2Z2;
197 const auto S2 = b.y() * a.z() * Z1Z1;
198 const auto H = U2 - U1;
199 const auto r = S2 - S1;
200
201 /* Risky conditional
202 *
203 * This implementation uses projective coordinates, which do not have an efficient complete
204 * addition formula. We rely on the design of the multiplication algorithms to avoid doublings.
205 *
206 * This conditional only comes into play for the actual doubling case, not x + (-x) which
207 * is another exceptional case in some circumstances. Here if a == -b then H == 0 && r != 0,
208 * in which case at the end we'll set z to a.z * b.z * H = 0, resulting in the correct
209 * output (the identity element)
210 */
211 if((r.is_zero() && H.is_zero() && !(a_is_identity && b_is_identity)).as_bool()) {
212 return a.dbl();
213 }
214
215 const auto HH = H.square();
216 const auto HHH = H * HH;
217 const auto V = U1 * HH;
218 const auto t2 = r.square();
219 const auto t3 = V + V;
220 const auto t4 = t2 - HHH;
221 auto X3 = t4 - t3;
222 const auto t5 = V - X3;
223 const auto t6 = S1 * HHH;
224 const auto t7 = r * t5;
225 auto Y3 = t7 - t6;
226 const auto t8 = b.z() * H;
227 auto Z3 = a.z() * t8;
228
229 // if a is identity then return b
230 FieldElement::conditional_assign(X3, Y3, Z3, a_is_identity, b.x(), b.y(), b.z());
231
232 // if b is identity then return a
233 FieldElement::conditional_assign(X3, Y3, Z3, b_is_identity, a.x(), a.y(), a.z());
234
235 return ProjectivePoint(X3, Y3, Z3);
236}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::add().

◆ point_add_mixed()

template<typename ProjectivePoint, typename AffinePoint, typename FieldElement>
ProjectivePoint Botan::point_add_mixed ( const ProjectivePoint & a,
const AffinePoint & b,
const FieldElement & one,
const FieldElement & curve_a )
inlineconstexpr

Definition at line 303 of file pcurves_algos.h.

306 {
308}
constexpr std::pair< ProjectivePoint, FieldElement > point_add_mixed_h(const ProjectivePoint &a, const AffinePoint &b, const FieldElement &one, const FieldElement &curve_a)

References point_add_mixed_h().

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::add_mixed(), and Botan::ProjectiveCurvePoint< FieldElement, Params >::add_mixed_iso().

◆ point_add_mixed_h()

template<typename ProjectivePoint, typename AffinePoint, typename FieldElement>
std::pair< ProjectivePoint, FieldElement > Botan::point_add_mixed_h ( const ProjectivePoint & a,
const AffinePoint & b,
const FieldElement & one,
const FieldElement & curve_a )
inlineconstexpr

Definition at line 247 of file pcurves_algos.h.

250 {
251 const auto a_is_identity = a.is_identity();
252 const auto b_is_identity = b.is_identity();
253
254 /*
255 https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-add-1998-cmo-2
256
257 Cost: 8M + 3S + 6add + 1*2
258 */
259
260 const auto Z1Z1 = a.z().square();
261 const auto U2 = b.x() * Z1Z1;
262 const auto S2 = b.y() * a.z() * Z1Z1;
263 const auto H = U2 - a.x();
264 const auto r = S2 - a.y();
265
266 /* Risky conditional
267 *
268 * This implementation uses projective coordinates, which do not have an efficient complete
269 * addition formula. We rely on the design of the multiplication algorithms to avoid doublings.
270 *
271 * This conditional only comes into play for the actual doubling case, not x + (-x) which
272 * is another exceptional case in some circumstances. Here if a == -b then H == 0 && r != 0,
273 * in which case at the end we'll set z to a.z * H = 0, resulting in the correct output
274 * (the identity element)
275 */
276 if((r.is_zero() && H.is_zero() && !(a_is_identity && b_is_identity)).as_bool()) {
277 return {a.dbl_iso(curve_a), H};
278 }
279
280 const auto HH = H.square();
281 const auto HHH = H * HH;
282 const auto V = a.x() * HH;
283 const auto t2 = r.square();
284 const auto t3 = V + V;
285 const auto t4 = t2 - HHH;
286 auto X3 = t4 - t3;
287 const auto t5 = V - X3;
288 const auto t6 = a.y() * HHH;
289 const auto t7 = r * t5;
290 auto Y3 = t7 - t6;
291 auto Z3 = a.z() * H;
292
293 // if a is identity then return b
294 FieldElement::conditional_assign(X3, Y3, Z3, a_is_identity, b.x(), b.y(), one);
295
296 // if b is identity then return a
297 FieldElement::conditional_assign(X3, Y3, Z3, b_is_identity, a.x(), a.y(), a.z());
298
299 return {ProjectivePoint(X3, Y3, Z3), H};
300}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::add_mixed_h(), and point_add_mixed().

◆ point_add_or_sub_mixed()

template<typename ProjectivePoint, typename AffinePoint, typename FieldElement>
ProjectivePoint Botan::point_add_or_sub_mixed ( const ProjectivePoint & a,
const AffinePoint & b,
CT::Choice sub,
const FieldElement & one,
const FieldElement & curve_a )
inlineconstexpr

Definition at line 314 of file pcurves_algos.h.

318 {
319 const auto a_is_identity = a.is_identity();
320 const auto b_is_identity = b.is_identity();
321
322 /*
323 https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-add-1998-cmo-2
324
325 Cost: 8M + 3S + 6add + 1*2
326 */
327
328 auto by = b.y();
329 by.conditional_assign(sub, by.negate());
330
331 const auto Z1Z1 = a.z().square();
332 const auto U2 = b.x() * Z1Z1;
333 const auto S2 = by * a.z() * Z1Z1;
334 const auto H = U2 - a.x();
335 const auto r = S2 - a.y();
336
337 /* Risky conditional
338 *
339 * This implementation uses projective coordinates, which do not have an efficient complete
340 * addition formula. We rely on the design of the multiplication algorithms to avoid doublings.
341 *
342 * This conditional only comes into play for the actual doubling case, not x + (-x) which
343 * is another exceptional case in some circumstances. Here if a == -b then H == 0 && r != 0,
344 * in which case at the end we'll set z to a.z * H = 0, resulting in the correct output
345 * (the identity element)
346 */
347 if((r.is_zero() && H.is_zero() && !(a_is_identity && b_is_identity)).as_bool()) {
348 return a.dbl_iso(curve_a);
349 }
350
351 const auto HH = H.square();
352 const auto HHH = H * HH;
353 const auto V = a.x() * HH;
354 const auto t2 = r.square();
355 const auto t3 = V + V;
356 const auto t4 = t2 - HHH;
357 auto X3 = t4 - t3;
358 const auto t5 = V - X3;
359 const auto t6 = a.y() * HHH;
360 const auto t7 = r * t5;
361 auto Y3 = t7 - t6;
362 auto Z3 = a.z() * H;
363
364 // if a is identity then return b
365 FieldElement::conditional_assign(X3, Y3, Z3, a_is_identity, b.x(), by, one);
366
367 // if b is identity then return a
368 FieldElement::conditional_assign(X3, Y3, Z3, b_is_identity, a.x(), a.y(), a.z());
369
370 return ProjectivePoint(X3, Y3, Z3);
371}

Referenced by Botan::ProjectiveCurvePoint< FieldElement, Params >::add_or_sub(), and Botan::ProjectiveCurvePoint< FieldElement, Params >::add_or_sub_iso().

◆ poly_double_n() [1/2]

void Botan::poly_double_n ( uint8_t buf[],
size_t n )
inline

Definition at line 26 of file poly_dbl.h.

26 {
27 return poly_double_n(buf, buf, n);
28}
void poly_double_n(uint8_t out[], const uint8_t in[], size_t n)
Definition poly_dbl.cpp:81

References poly_double_n().

◆ poly_double_n() [2/2]

void BOTAN_TEST_API Botan::poly_double_n ( uint8_t out[],
const uint8_t in[],
size_t n )

Polynomial doubling in GF(2^n)

Definition at line 81 of file poly_dbl.cpp.

81 {
82 switch(n) {
83 case 8:
84 return poly_double<1, MinWeightPolynomial::P64>(out, in);
85 case 16:
86 return poly_double<2, MinWeightPolynomial::P128>(out, in);
87 case 24:
88 return poly_double<3, MinWeightPolynomial::P192>(out, in);
89 case 32:
90 return poly_double<4, MinWeightPolynomial::P256>(out, in);
91 case 64:
92 return poly_double<8, MinWeightPolynomial::P512>(out, in);
93 case 128:
94 return poly_double<16, MinWeightPolynomial::P1024>(out, in);
95 default:
96 throw Invalid_Argument("Unsupported size for poly_double_n");
97 }
98}

Referenced by poly_double_n(), and Botan::SIV_Mode::S2V().

◆ poly_double_n_le()

void BOTAN_TEST_API Botan::poly_double_n_le ( uint8_t out[],
const uint8_t in[],
size_t n )

Definition at line 100 of file poly_dbl.cpp.

100 {
101 switch(n) {
102 case 8:
103 return poly_double_le<1, MinWeightPolynomial::P64>(out, in);
104 case 16:
105 return poly_double_le<2, MinWeightPolynomial::P128>(out, in);
106 case 24:
107 return poly_double_le<3, MinWeightPolynomial::P192>(out, in);
108 case 32:
109 return poly_double_le<4, MinWeightPolynomial::P256>(out, in);
110 case 64:
111 return poly_double_le<8, MinWeightPolynomial::P512>(out, in);
112 case 128:
113 return poly_double_le<16, MinWeightPolynomial::P1024>(out, in);
114 default:
115 throw Invalid_Argument("Unsupported size for poly_double_n_le");
116 }
117}

Referenced by xts_compute_tweak_block().

◆ poly_double_supported_size()

bool Botan::poly_double_supported_size ( size_t n)
inline

Returns true iff poly_double_n is implemented for this size.

Definition at line 22 of file poly_dbl.h.

22 {
23 return (n == 8 || n == 16 || n == 24 || n == 32 || n == 64 || n == 128);
24}

Referenced by Botan::CMAC::CMAC(), and Botan::XTS_Mode::XTS_Mode().

◆ poly_mul()

template<uint8_t POLY, std::unsigned_integral T>
T Botan::poly_mul ( T x,
uint8_t y )
constexpr

Compile-time polynomial multiplication in GF(2^8) modulo an irreducible polynomial POLY

When T is larger than a byte, the function computes the product of each byte of T and returns the packed result.

This function is intended only for use at compile-time, and in particular should not be used with secret inputs.

TODO(Botan4) this function should be consteval, but that hits bugs in older versions of GCC and Clang.

Definition at line 307 of file bit_ops.h.

307 {
308 // The constant 0x010101... as a T
309 constexpr T lo_bit = (static_cast<T>(-1) / 255);
310
311 // The constant 0x7F7F7F... as a T
312 constexpr T mask = static_cast<T>(~(lo_bit << 7));
313
314 constexpr T poly = POLY;
315
316 T r = 0;
317 while(x > 0 && y > 0) {
318 if((y & 1) != 0) {
319 r ^= x;
320 }
321 const T carry = ((x >> 7) & lo_bit) * poly;
322 x = ((x & mask) << 1) ^ carry;
323 y >>= 1;
324 }
325 return r;
326}

◆ polyval_multiply()

BOTAN_FORCE_INLINE SIMD_4x32 BOTAN_FN_ISA_CLMUL Botan::polyval_multiply ( const SIMD_4x32 & H,
const SIMD_4x32 & x )

Definition at line 140 of file polyval_fn.h.

140 {
141 SIMD_4x32 hi = clmul<0x11>(H, x);
142 const SIMD_4x32 mid = clmul<0x10>(H, x) ^ clmul<0x01>(H, x);
143 SIMD_4x32 lo = clmul<0x00>(H, x);
144
145 hi ^= mid.shift_elems_right<2>();
146 lo ^= mid.shift_elems_left<2>();
147
148 return polyval_reduce(hi, lo);
149}
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 shift_elems_right() const noexcept
Definition simd_4x32.h:599
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 shift_elems_left() const noexcept
Definition simd_4x32.h:562
BOTAN_FORCE_INLINE SIMD_4x32 BOTAN_FN_ISA_CLMUL polyval_reduce(const SIMD_4x32 &hi, const SIMD_4x32 &lo)
Definition polyval_fn.h:119
BOTAN_FORCE_INLINE BOTAN_FN_ISA_CLMUL SIMD_4x32 clmul(const SIMD_4x32 &H, const SIMD_4x32 &x)
Definition polyval_fn.h:21

References BOTAN_FORCE_INLINE, clmul(), polyval_reduce(), Botan::SIMD_4x32::shift_elems_left(), and Botan::SIMD_4x32::shift_elems_right().

◆ polyval_reduce()

BOTAN_FORCE_INLINE SIMD_4x32 BOTAN_FN_ISA_CLMUL Botan::polyval_reduce ( const SIMD_4x32 & hi,
const SIMD_4x32 & lo )

Definition at line 119 of file polyval_fn.h.

119 {
120 const SIMD_4x32 V(0, 0xC2000000, 0, 0);
121
122 /*
123 Montgomery reduction
124 Input: 256-bit operand [X3 : X2 : X1 : X0]
125 [A1 : A0] = X0 * 0xc200000000000000
126 [B1 : B0] = [X0 + A1 : X1 + A0]
127 [C1 : C0] = B0 * 0xc200000000000000
128 [D1 : D0] = [B0 + C1 : B1 + C0]
129 Output: [D1 + X3 : D0 + X2]
130 */
131
132 const auto A = clmul<0x00>(lo, V);
133 const auto B = A ^ lo.swap_halves();
134 const auto C = clmul<0x00>(B, V);
135 const auto D = C ^ B.swap_halves();
136
137 return D ^ hi;
138}
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 swap_halves() const
Definition simd_4x32.h:930

References BOTAN_FORCE_INLINE, clmul(), and Botan::SIMD_4x32::swap_halves().

Referenced by polyval_multiply().

◆ power_mod()

BigInt Botan::power_mod ( const BigInt & b,
const BigInt & x,
const BigInt & m )

Modular exponentiation

Parameters
ban integer base
xa positive exponent
ma positive modulus
Returns
(b^x) % m

Definition at line 310 of file numthry.cpp.

310 {
311 if(mod.signum() < 0 || mod == 1) {
312 return BigInt::zero();
313 }
314
315 if(base.is_zero() || mod.is_zero()) {
316 if(exp.is_zero()) {
317 return BigInt::one();
318 }
319 return BigInt::zero();
320 }
321
323
324 const size_t exp_bits = exp.bits();
325
326 if(mod.is_odd()) {
327 const Montgomery_Params monty_params(mod, reduce_mod);
328 return monty_exp(monty_params, ct_modulo(base, mod), exp, exp_bits).value();
329 }
330
331 /*
332 Support for even modulus is just a convenience and not considered
333 cryptographically important, so this implementation is slow ...
334 */
335 BigInt accum = BigInt::one();
336 BigInt g = ct_modulo(base, mod);
337 BigInt t;
338
339 for(size_t i = 0; i != exp_bits; ++i) {
340 t = reduce_mod.multiply(g, accum);
341 g = reduce_mod.square(g);
342 accum.ct_cond_assign(exp.get_bit(i), t);
343 }
344 return accum;
345}
static Barrett_Reduction for_secret_modulus(const BigInt &m)
Definition barrett.cpp:23
static BigInt one()
Definition bigint.h:55
BigInt value() const
Definition monty.cpp:279
Montgomery_Int monty_exp(const Montgomery_Params &params_p, const BigInt &g, const BigInt &k, size_t max_k_bits)
Definition monty_exp.h:70

References Botan::BigInt::bits(), Botan::BigInt::ct_cond_assign(), ct_modulo(), Botan::Barrett_Reduction::for_secret_modulus(), Botan::BigInt::get_bit(), Botan::BigInt::is_odd(), Botan::BigInt::is_zero(), monty_exp(), Botan::BigInt::one(), reduce_mod(), Botan::BigInt::signum(), Botan::Montgomery_Int::value(), and Botan::BigInt::zero().

Referenced by botan_mp_powmod().

◆ prefetch_array_raw()

uint64_t Botan::prefetch_array_raw ( size_t bytes,
const void * array )
noexcept

Prefetch an array

This function returns a uint64_t which is accumulated from values read from the array. This may help confuse the compiler sufficiently to not elide otherwise "useless" reads. The return value will always be zero.

Definition at line 14 of file prefetch.cpp.

14 {
15#if defined(__cpp_lib_hardware_interference_size)
16 constexpr size_t cache_line_size = std::hardware_destructive_interference_size;
17#else
18 // We arbitrarily use a 64 byte cache line, which is by far the most
19 // common size.
20 //
21 // Runtime detection adds too much overhead to this function.
22 constexpr size_t cache_line_size = 64;
23#endif
24
25 const uint8_t* array = static_cast<const uint8_t*>(arrayv);
26
27 volatile uint64_t combiner = 1;
28
29 for(size_t idx = 0; idx < bytes; idx += cache_line_size) {
30#if BOTAN_COMPILER_HAS_BUILTIN(__builtin_prefetch)
31 // we have no way of knowing if the compiler will emit anything here
32 __builtin_prefetch(&array[idx]);
33#endif
34
35 combiner = combiner | array[idx];
36 }
37
38 /*
39 * The combiner variable is initialized with 1, and we accumulate using OR, so
40 * now combiner must be a value other than zero. This being the case we will
41 * always return zero here. Hopefully the compiler will not figure this out.
42 */
43 return ct_is_zero(combiner);
44}
BOTAN_FORCE_INLINE constexpr T ct_is_zero(T x)
Definition bit_ops.h:37

References ct_is_zero().

Referenced by prefetch_arrays().

◆ prefetch_arrays()

template<std::unsigned_integral T, size_t... Ns>
T Botan::prefetch_arrays ( T(&... arr) [Ns])
noexcept

Prefetch several arrays

This function returns a uint64_t which is accumulated from values read from the array. This may help confuse the compiler sufficiently to not elide otherwise "useless" reads. The return value will always be zero.

Definition at line 34 of file prefetch.h.

34 {
35 return (static_cast<T>(prefetch_array_raw(sizeof(T) * Ns, arr)) & ...);
36}
uint64_t prefetch_array_raw(size_t bytes, const void *arrayv) noexcept
Definition prefetch.cpp:14

References prefetch_array_raw().

Referenced by Botan::SEED::decrypt_n(), and Botan::SEED::encrypt_n().

◆ probe_provider_private_key()

std::vector< std::string > Botan::probe_provider_private_key ( std::string_view alg_name,
const std::vector< std::string > & possible )

Definition at line 752 of file pk_algs.cpp.

753 {
754 std::vector<std::string> providers;
755
756 for(auto&& prov : possible) {
757 if(prov == "base") {
758 providers.push_back(prov);
759 }
760 }
761
762 BOTAN_UNUSED(alg_name);
763
764 return providers;
765}

References BOTAN_UNUSED.

◆ probe_providers_of()

template<typename T>
std::vector< std::string > Botan::probe_providers_of ( std::string_view algo_spec,
const std::vector< std::string > & possible = {"base"} )

Return those of the possible providers for which T::create succeeds

Definition at line 20 of file probe_providers.h.

21 {"base"}) {
22 std::vector<std::string> providers;
23 for(auto&& prov : possible) {
24 const auto o = T::create(algo_spec, prov);
25 if(o) {
26 providers.push_back(prov); // available
27 }
28 }
29 return providers;
30}

Referenced by Botan::BlockCipher::providers(), Botan::HashFunction::providers(), Botan::KDF::providers(), Botan::MessageAuthenticationCode::providers(), Botan::PasswordHashFamily::providers(), Botan::PBKDF::providers(), Botan::StreamCipher::providers(), and Botan::XOF::providers().

◆ process_bytes_in_sponge() [1/2]

template<detail::SpongeLikeWithTrivialPermute SpongeT>
void Botan::process_bytes_in_sponge ( SpongeT & sponge,
size_t bytes_to_process,
const detail::ModifierFn< SpongeT > auto & modifier_fn )
inline

Definition at line 205 of file sponge_processing.h.

207 {
209 sponge, bytes_to_process, [&sponge] { sponge.permute(); }, modifier_fn);
210}

References process_bytes_in_sponge().

◆ process_bytes_in_sponge() [2/2]

template<detail::SpongeLike SpongeT>
BOTAN_FORCE_INLINE void Botan::process_bytes_in_sponge ( SpongeT & sponge,
size_t bytes_to_process,
const detail::PermutationFn auto & permutation_fn,
const detail::ModifierFn< SpongeT > auto & modifier_fn )

Performs the core processing loop for ingesting or extracting data into/from the sponge state in a byte-oriented manner for the given number of bytes_to_process. The provided word_modifier_fn is called for each (partial) word of the sponge state that needs to be modified or read.

The processing loop ensures efficient handling of unaligned input and output data. For that, it calls the provided permutation function either with an instance of PartialWordBounds or FullWordBounds. Hence word_modifier_fn must be able to handle both types of bounds and should use their respective methods to read from or write into input or output buffers.

Parameters
Sponge Helperthe sponge instance to process data into or from
bytes_to_processthe number of sponge state bytes to traverse
permutation_fna function that performs the sponge's permutation
modifier_fna function that modifies the sponge state words

Definition at line 135 of file sponge_processing.h.

138 {
139 if(bytes_to_process == 0) {
140 return;
141 }
142
143 constexpr auto word_bytes = SpongeT::word_bytes;
144 const auto byte_rate = sponge.byte_rate();
145 auto& S = sponge.state();
146 auto& cursor = sponge._cursor();
147
148 // If necessary, try to get aligned with the sponge state's words array
149 const auto bytes_out_of_word_alignment = static_cast<size_t>(cursor % word_bytes);
150 if(bytes_out_of_word_alignment > 0) {
151 const auto bytes_until_word_alignment = word_bytes - bytes_out_of_word_alignment;
152 const auto bytes_from_input = std::min(bytes_to_process, bytes_until_word_alignment);
153 BOTAN_DEBUG_ASSERT(bytes_from_input < word_bytes);
154
155 S[cursor / word_bytes] = modifier_fn(S[cursor / word_bytes],
156 detail::PartialWordBounds<SpongeT>{
157 .offset = bytes_out_of_word_alignment,
158 .length = bytes_from_input,
159 });
160 cursor += bytes_from_input;
161 bytes_to_process -= bytes_from_input;
162
163 if(cursor == byte_rate) {
164 permutation_fn();
165 cursor = 0;
166 }
167 }
168
169 // If we didn't exhaust the bytes to process for this invocation, we should
170 // be word-aligned with the sponge state now
171 BOTAN_DEBUG_ASSERT(bytes_to_process == 0 || cursor % word_bytes == 0);
172
173 // Block-wise incorporation of the input data into the sponge state until
174 // all input bytes are processed
175 while(bytes_to_process >= word_bytes) {
176 // Process full words until we either run out of data or reach the
177 // end of the current sponge state block
178 while(bytes_to_process >= word_bytes && cursor < byte_rate) {
179 S[cursor / word_bytes] = modifier_fn(S[cursor / word_bytes], detail::FullWordBounds<SpongeT>{});
180 cursor += word_bytes;
181 bytes_to_process -= word_bytes;
182 }
183
184 if(cursor == byte_rate) {
185 permutation_fn();
186 cursor = 0;
187 }
188 }
189
190 // Process the remaining bytes that don't fill an entire word.
191 // Therefore, leaving the sponge state in an unaligned state that won't
192 // need another permutation until the next call to process().
193 BOTAN_DEBUG_ASSERT(bytes_to_process < word_bytes && cursor < byte_rate);
194 if(bytes_to_process > 0) {
195 S[cursor / word_bytes] = modifier_fn(S[cursor / word_bytes],
197 .offset = 0,
198 .length = bytes_to_process,
199 });
200 cursor += bytes_to_process;
201 }
202}

References BOTAN_DEBUG_ASSERT, and BOTAN_FORCE_INLINE.

Referenced by absorb_into_sponge(), Botan::Ascon_p::percolate_in(), Botan::Ascon_p::percolate_out(), process_bytes_in_sponge(), and squeeze_from_sponge().

◆ R1()

void Botan::R1 ( uint32_t A,
uint32_t & B,
uint32_t C,
uint32_t & D,
uint32_t E,
uint32_t & F,
uint32_t G,
uint32_t & H,
uint32_t TJ,
uint32_t Wi,
uint32_t Wj )
inline

Definition at line 21 of file sm3_fn.h.

31 {
32 const uint32_t A12 = rotl<12>(A);
33 const uint32_t SS1 = rotl<7>(A12 + E + TJ);
34 const uint32_t TT1 = (A ^ B ^ C) + D + (SS1 ^ A12) + (Wi ^ Wj);
35 const uint32_t TT2 = (E ^ F ^ G) + H + SS1 + Wi;
36
37 B = rotl<9>(B);
38 D = TT1;
39 F = rotl<19>(F);
40 H = P0(TT2);
41}
uint32_t P0(uint32_t X)
Definition sm3_fn.h:17

References P0(), and rotl().

Referenced by Botan::SM3::compress_n(), Botan::Blowfish::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::EC_Point::EC_Point(), Botan::EC_Point::EC_Point(), Botan::Blowfish::encrypt_n(), and Botan::CAST_128::encrypt_n().

◆ R2()

void Botan::R2 ( uint32_t A,
uint32_t & B,
uint32_t C,
uint32_t & D,
uint32_t E,
uint32_t & F,
uint32_t G,
uint32_t & H,
uint32_t TJ,
uint32_t Wi,
uint32_t Wj )
inline

Definition at line 43 of file sm3_fn.h.

53 {
54 const uint32_t A12 = rotl<12>(A);
55 const uint32_t SS1 = rotl<7>(A12 + E + TJ);
56 const uint32_t TT1 = majority(A, B, C) + D + (SS1 ^ A12) + (Wi ^ Wj);
57 const uint32_t TT2 = choose(E, F, G) + H + SS1 + Wi;
58
59 B = rotl<9>(B);
60 D = TT1;
61 F = rotl<19>(F);
62 H = P0(TT2);
63}
BOTAN_FORCE_INLINE constexpr T majority(T a, T b, T c)
Definition bit_ops.h:223

References choose(), majority(), P0(), and rotl().

Referenced by Botan::SM3::compress_n(), Botan::Blowfish::decrypt_n(), and Botan::Blowfish::encrypt_n().

◆ random_code_element()

gf2m Botan::random_code_element ( uint16_t code_length,
RandomNumberGenerator & rng )

Definition at line 81 of file polyn_gf2m.cpp.

81 {
82 if(code_length == 0) {
83 throw Invalid_Argument("random_code_element() was supplied a code length of zero");
84 }
85 const unsigned nlz = nlz_16bit(code_length - 1);
86 const gf2m mask = (1 << (16 - nlz)) - 1;
87
88 gf2m result = random_gf2m(rng) & mask;
89
90 while(result >= code_length) {
91 // rejection sampling
92 result = random_gf2m(rng) & mask;
93 }
94
95 return result;
96}
gf2m random_gf2m(RandomNumberGenerator &rng)

References random_gf2m().

Referenced by Botan::polyn_gf2m::polyn_gf2m().

◆ random_gf2m()

gf2m Botan::random_gf2m ( RandomNumberGenerator & rng)

Definition at line 75 of file polyn_gf2m.cpp.

75 {
76 uint8_t b[2];
77 rng.randomize(b, sizeof(b));
78 return make_uint16(b[1], b[0]);
79}
constexpr uint16_t make_uint16(uint8_t i0, uint8_t i1)
Definition loadstor.h:92

References make_uint16(), and Botan::RandomNumberGenerator::randomize().

Referenced by random_code_element().

◆ random_prime()

BigInt Botan::random_prime ( RandomNumberGenerator & rng,
size_t bits,
const BigInt & coprime = BigInt::from_u64(0),
size_t equiv = 1,
size_t equiv_mod = 2,
size_t prob = 128 )

Randomly generate a prime suitable for discrete logarithm parameters

Parameters
Random Number Generatorsa random number generator
bitshow large the resulting prime should be in bits
coprimea positive integer that (prime - 1) should be coprime to
equiva non-negative number that the result should be equivalent to modulo equiv_mod
equiv_modthe modulus equiv should be checked against
probuse test so false positive is bounded by 1/2**prob
Returns
random prime with the specified criteria

Definition at line 198 of file make_prm.cpp.

199 {
200 if(bits <= 1) {
201 throw Invalid_Argument("random_prime: Can't make a prime of " + std::to_string(bits) + " bits");
202 }
203 if(coprime.signum() < 0 || (coprime.signum() != 0 && coprime.is_even()) || coprime.bits() >= bits) {
204 throw Invalid_Argument("random_prime: invalid coprime");
205 }
206 // TODO(Botan4) reduce this to ~1000
207 if(modulo == 0 || modulo >= 100000) {
208 throw Invalid_Argument("random_prime: Invalid modulo value");
209 }
210
211 // TODO(Botan4) reject equiv > modulo instead of reducing here
212 equiv %= modulo;
213
214 if(equiv == 0) {
215 throw Invalid_Argument("random_prime Invalid value for equiv/modulo");
216 }
217
218 // Handle small values:
219
220 if(bits <= 16) {
221 if(equiv != 1 || modulo != 2 || coprime != 0) {
222 throw Not_Implemented("random_prime equiv/modulo/coprime options not usable for small primes");
223 }
224
225 if(bits == 2) {
226 return BigInt::from_word(((rng.next_byte() % 2) == 0 ? 2 : 3));
227 } else if(bits == 3) {
228 return BigInt::from_word(((rng.next_byte() % 2) == 0 ? 5 : 7));
229 } else if(bits == 4) {
230 return BigInt::from_word(((rng.next_byte() % 2) == 0 ? 11 : 13));
231 } else {
232 for(;;) {
233 // This is slightly biased, but for small primes it does not seem to matter
234 uint8_t b[4] = {0};
235 rng.randomize(b, 4);
236 const size_t idx = load_le<uint32_t>(b, 0) % PRIME_TABLE_SIZE;
237 const uint16_t small_prime = PRIMES[idx];
238
239 if(high_bit(small_prime) == bits) {
240 return BigInt::from_word(small_prime);
241 }
242 }
243 }
244 }
245
246 // The check_2p1 sieve filter is only appropriate when generating q for a
247 // safe prime; for arbitrary equiv/modulo it can pre-reject every candidate
248 // (eg equiv=1, modulo=3 makes the residue mod 3 always equal (3-1)/2).
249 return random_prime_with_sieve(rng, bits, coprime, equiv, modulo, prob, false);
250}
const uint16_t PRIMES[]
Definition primes.cpp:17

References Botan::BigInt::bits(), Botan::BigInt::from_word(), high_bit(), Botan::BigInt::is_even(), load_le(), Botan::RandomNumberGenerator::next_byte(), PRIME_TABLE_SIZE, PRIMES, Botan::RandomNumberGenerator::randomize(), and Botan::BigInt::signum().

Referenced by Botan::DL_Group::DL_Group().

◆ random_safe_prime()

BigInt Botan::random_safe_prime ( RandomNumberGenerator & rng,
size_t bits )

Return a 'safe' prime, of the form p=2*q+1 with q prime

Parameters
Random Number Generatorsa random number generator
bitsis how long the resulting prime should be
Returns
prime randomly chosen from safe primes of length bits

Definition at line 356 of file make_prm.cpp.

356 {
357 if(bits <= 64) {
358 throw Invalid_Argument("random_safe_prime: Can't make a prime of " + std::to_string(bits) + " bits");
359 }
360
361 const size_t error_bound = 128;
362
363 BigInt q;
364 BigInt p;
365 for(;;) {
366 /*
367 Generate q == 2 (mod 3), since otherwise [in the case of q == 1 (mod 3)],
368 2*q+1 == 3 (mod 3) and so certainly not prime.
369 */
370 q = random_prime_with_sieve(rng, bits - 1, BigInt::zero(), 2, 3, error_bound, true);
371 p = (q << 1) + 1;
372
373 if(is_prime(p, rng, error_bound, true)) {
374 return p;
375 }
376 }
377}
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition numthry.cpp:449

References is_prime(), and Botan::BigInt::zero().

Referenced by Botan::DL_Group::DL_Group().

◆ read_cfg()

std::map< std::string, std::string > Botan::read_cfg ( std::istream & is)

Definition at line 32 of file read_cfg.cpp.

32 {
33 std::map<std::string, std::string> kv;
34 size_t line = 0;
35
36 while(is.good()) {
37 std::string s;
38
39 std::getline(is, s);
40
41 ++line;
42
43 if(s.empty() || s[0] == '#') {
44 continue;
45 }
46
47 s = clean_ws(s.substr(0, s.find('#')));
48
49 if(s.empty()) {
50 continue;
51 }
52
53 const auto eq = s.find('=');
54
55 if(eq == std::string::npos || eq == 0 || eq == s.size() - 1) {
56 throw Decoding_Error("Bad read_cfg input '" + s + "' on line " + std::to_string(line));
57 }
58
59 const std::string key = clean_ws(s.substr(0, eq));
60 const std::string val = clean_ws(s.substr(eq + 1, std::string::npos));
61
62 kv[key] = val;
63 }
64
65 return kv;
66}

Referenced by Botan::TLS::Text_Policy::Text_Policy(), and Botan::TLS::Text_Policy::Text_Policy().

◆ read_kv()

std::map< std::string, std::string > Botan::read_kv ( std::string_view kv)

Accepts key value pairs delimited by commas:

"" (returns empty map) "K=V" (returns map {'K': 'V'}) "K1=V1,K2=V2" "K1=V1,K2=V2,K3=V3" "K1=V1,K2=V2,K3=a_value\,with\,commas_and_\=equals"

Values may be empty, keys must be non-empty and unique. Duplicate keys cause an exception.

Within both key and value, comma and equals can be escaped with backslash. Backslash can also be escaped.

Definition at line 13 of file read_kv.cpp.

13 {
14 std::map<std::string, std::string> m;
15 if(kv.empty()) {
16 return m;
17 }
18
19 try {
20 // Validate input format before manual parsing
21 [[maybe_unused]] const auto _ = split_on(kv, ',');
22 } catch(std::exception&) {
23 throw Invalid_Argument("Bad KV spec");
24 }
25
26 bool escaped = false;
27 bool reading_key = true;
28 std::string cur_key;
29 std::string cur_val;
30
31 for(const char c : kv) {
32 if(c == '\\' && !escaped) {
33 escaped = true;
34 } else if(c == ',' && !escaped) {
35 if(cur_key.empty()) {
36 throw Invalid_Argument("Bad KV spec empty key");
37 }
38
39 if(m.contains(cur_key)) {
40 throw Invalid_Argument("Bad KV spec duplicated key");
41 }
42 m[cur_key] = cur_val;
43 cur_key = "";
44 cur_val = "";
45 reading_key = true;
46 } else if(c == '=' && !escaped) {
47 if(!reading_key) {
48 throw Invalid_Argument("Bad KV spec unexpected equals sign");
49 }
50 reading_key = false;
51 } else {
52 if(reading_key) {
53 cur_key += c;
54 } else {
55 cur_val += c;
56 }
57 escaped = false;
58 }
59 }
60
61 if(!cur_key.empty()) {
62 if(!reading_key) {
63 if(m.contains(cur_key)) {
64 throw Invalid_Argument("Bad KV spec duplicated key");
65 }
66 m[cur_key] = cur_val;
67 } else {
68 throw Invalid_Argument("Bad KV spec incomplete string");
69 }
70 }
71
72 return m;
73}

References split_on().

◆ read_window_bits()

template<size_t WindowBits, typename W, size_t N>
size_t Botan::read_window_bits ( std::span< const W, N > words,
size_t offset )
constexpr

Definition at line 1284 of file mp_core.h.

1284 {
1285 static_assert(WindowBits >= 1 && WindowBits <= 7);
1286
1287 constexpr uint8_t WindowMask = static_cast<uint8_t>(1 << WindowBits) - 1;
1288
1289 constexpr size_t W_bits = sizeof(W) * 8;
1290 const auto bit_shift = offset % W_bits;
1291 const auto word_offset = words.size() - 1 - (offset / W_bits);
1292
1293 const bool single_byte_window = bit_shift <= (W_bits - WindowBits) || word_offset == 0;
1294
1295 const auto w0 = words[word_offset];
1296
1297 if(single_byte_window) {
1298 return (w0 >> bit_shift) & WindowMask;
1299 } else {
1300 // Otherwise we must join two words and extract the result
1301 const auto w1 = words[word_offset - 1];
1302 const auto combined = ((w0 >> bit_shift) | (w1 << (W_bits - bit_shift)));
1303 return combined & WindowMask;
1304 }
1305}

Referenced by Botan::BlindedScalarBits< C, WindowBits+1 >::get_window(), Botan::UnblindedScalarBits< C, WindowBits >::get_window(), and Botan::IntMod< MontgomeryRep< ScalarParams > >::pow_vartime().

◆ reciprocal_word()

template<WordType W>
W Botan::reciprocal_word ( W D)
constexpr

Compute the reciprocal floor((2^(2b) - 1) / D) - 2^b of a normalized divisor D (ie one with its top bit set)

This is the same value as computed by Algorithms 2 and 3 of Möller and Granlund "Improved Division by Invariant Integers". (https://gmplib.org/~tege/division-paper.pdf)

Uses compiler provided division instructions where available, and Algorithm 2 as the portable 64-bit fallback.

Definition at line 578 of file mp_core.h.

578 {
580
581 /*
582 * Subtracting 2^b*D from the numerator gives
583 * v = floor(((~D)*2^b + (2^b - 1)) / D). Since D is normalized, ~D < D
584 * and the quotient fits in a word. See the first part of Section III A
585 * in the paper.
586 */
587 if constexpr(sizeof(W) == 4) {
588 const auto nD = ~D; // Work around spurious MSVC warning
589 const typename WordInfo<W>::dword n =
590 (static_cast<typename WordInfo<W>::dword>(nD) << WordInfo<W>::bits) | WordInfo<W>::max;
591 return static_cast<W>(n / D);
592 } else {
593 if(!std::is_constant_evaluated()) {
594#if defined(BOTAN_MP_USE_X86_64_ASM)
595 W quotient = 0;
596 W remainder = 0;
597 // NOLINTNEXTLINE(*-no-assembler)
598 asm("divq %[d]"
599 : "=a"(quotient), "=d"(remainder)
600 : [d] "r"(D), "a"(WordInfo<W>::max), "d"(static_cast<W>(~D))
601 : "cc");
602 return quotient;
603#elif !defined(BOTAN_BUILD_COMPILER_IS_CLANGCL)
604 /* clang-cl has a bug where on encountering a 128/64 division it emits
605 * a call to __udivti3() but then fails to link the relevant builtin into
606 * the binary, causing a link failure. Work around this by simply omitting
607 * such code for clang-cl
608 *
609 * See https://github.com/llvm/llvm-project/issues/25679
610 */
611 if constexpr(WordInfo<W>::dword_is_native) {
612 typename WordInfo<W>::dword n =
613 (static_cast<typename WordInfo<W>::dword>(~D) << WordInfo<W>::bits) | WordInfo<W>::max;
614 return static_cast<W>(n / D);
615 }
616#endif
617 }
618
619 // Algorithm 2 of Möller and Granlund
620 const W d0 = D & 1;
621 const W d9 = D >> 55;
622 const W d40 = (D >> 24) + 1;
623 const W d63 = (D >> 1) + d0; // ceil(D/2)
624
625 // This division is done with a table lookup in the paper
626 const W v0 = ((W(1) << 19) - (W(3) << 8)) / d9;
627 const W v1 = (v0 << 11) - ((v0 * v0 * d40) >> 40) - 1;
628 const W v2 = (v1 << 13) + ((v1 * ((W(1) << 60) - v1 * d40)) >> 47);
629
630 const W e = W(0) - v2 * d63 + (v2 >> 1) * d0;
631
632 W product_hi = 0;
633 word_madd2(v2, e, &product_hi);
634 const W v3 = (v2 << 31) + (product_hi >> 1);
635
636 // Compute floor((v3 + 2^64 + 1) * D / 2^64) modulo 2^64
637 product_hi = D;
638 word_madd2(v3, D, &product_hi);
639 return v3 - D - product_hi;
640 }
641}

References BOTAN_DEBUG_ASSERT, and word_madd2().

Referenced by Botan::divide_precomp< W >::setup_vartime().

◆ reciprocal_word_ct()

template<WordType W>
W Botan::reciprocal_word_ct ( W D)
constexpr

Compute the same reciprocal as reciprocal_word, but running in constant time.

Requires that D is normalized (ie with its top bit set)

Definition at line 650 of file mp_core.h.

650 {
652
653 // Bit serial long division of ((~D) || (2^b - 1)) / D, with all of the
654 // conditional logic computed via masks
655 W remainder = static_cast<W>(~D);
656 W quotient = 0;
657
658 for(size_t i = 0; i != WordInfo<W>::bits; ++i) {
659 const auto carry = CT::Mask<W>::expand_top_bit(remainder);
660 remainder = static_cast<W>((remainder << 1) | 1);
661 quotient <<= 1;
662
663 const auto sub = carry | CT::Mask<W>::is_gte(remainder, D);
664 remainder -= sub.if_set_return(D);
665 quotient |= sub.if_set_return(1);
666 }
667
668 return quotient;
669}
static constexpr Mask< T > is_gte(T x, T y)
Definition ct_utils.h:473
static constexpr Mask< T > expand_top_bit(T v)
Definition ct_utils.h:420

References BOTAN_DEBUG_ASSERT, Botan::CT::Mask< T >::expand_top_bit(), and Botan::CT::Mask< T >::is_gte().

Referenced by Botan::divide_precomp< W >::setup().

◆ redc_crandall()

template<WordType W, size_t N, W C>
std::array< W, N > Botan::redc_crandall ( std::span< const W, 2 *N > z)
constexpr

Reduce z modulo p = 2**B - C where C is small

z is assumed to be at most (p-1)**2

For details on the algorithm see

  • Handbook of Applied Cryptography, Algorithm 14.47
  • Guide to Elliptic Curve Cryptography, Algorithm 2.54 and Note 2.55

Definition at line 1177 of file mp_core.h.

1177 {
1178 static_assert(N >= 2);
1179
1180 std::array<W, N> hi = {};
1181
1182 // hi = hi * c + lo
1183
1184 W carry = 0;
1185 for(size_t i = 0; i != N; ++i) {
1186 hi[i] = word_madd3(z[i + N], C, z[i], &carry);
1187 }
1188
1189 // hi += carry * C
1190 W carry_c[2] = {0};
1191 carry_c[0] = word_madd2(carry, C, &carry_c[1]);
1192
1193 carry = bigint_add2(hi.data(), N, carry_c, 2);
1194
1195 constexpr W P0 = WordInfo<W>::max - (C - 1);
1196
1197 std::array<W, N> r = {};
1198
1199 W borrow = 0;
1200
1201 /*
1202 * For undetermined reasons, on GCC (only) removing this asm block causes
1203 * massive (up to 20%) performance regressions in secp256k1.
1204 *
1205 * The generated code without the asm seems quite reasonable, and timing
1206 * repeated calls to redc_crandall with the cycle counter show that GCC
1207 * computes it in about the same number of cycles with or without the asm.
1208 *
1209 * So the cause of the regression is unclear. But it is reproducible across
1210 * machines and GCC versions.
1211 */
1212#if defined(BOTAN_MP_USE_X86_64_ASM) && defined(__GNUC__) && !defined(__clang__)
1213 if constexpr(N == 4 && std::same_as<W, uint64_t>) {
1214 if(!std::is_constant_evaluated()) {
1215 asm volatile(R"(
1216 movq 0(%[x]), %[borrow]
1217 subq %[p0], %[borrow]
1218 movq %[borrow], 0(%[r])
1219 movq 8(%[x]), %[borrow]
1220 sbbq $-1, %[borrow]
1221 movq %[borrow], 8(%[r])
1222 movq 16(%[x]), %[borrow]
1223 sbbq $-1, %[borrow]
1224 movq %[borrow], 16(%[r])
1225 movq 24(%[x]), %[borrow]
1226 sbbq $-1, %[borrow]
1227 movq %[borrow], 24(%[r])
1228 sbbq %[borrow],%[borrow]
1229 negq %[borrow]
1230 )"
1231 : [borrow] "=r"(borrow)
1232 : [x] "r"(hi.data()), [p0] "r"(P0), [r] "r"(r.data()), "0"(borrow)
1233 : "cc", "memory");
1234
1235 borrow = (carry - borrow) > carry;
1236 CT::conditional_assign_mem(borrow, r.data(), hi.data(), N);
1237 return r;
1238 }
1239 }
1240#endif
1241
1242 r[0] = word_sub(hi[0], P0, &borrow);
1243 for(size_t i = 1; i != N; ++i) {
1244 r[i] = word_sub(hi[i], WordInfo<W>::max, &borrow);
1245 }
1246
1247 borrow = (carry - borrow) > carry;
1248
1249 CT::conditional_assign_mem(borrow, r.data(), hi.data(), N);
1250
1251 return r;
1252}

References bigint_add2(), Botan::CT::conditional_assign_mem(), P0(), word_madd2(), word_madd3(), and word_sub().

◆ reduce()

template<typename RetT, typename KeyT, typename ReducerT>
requires std::invocable<ReducerT&, RetT, const KeyT&> && std::convertible_to<std::invoke_result_t<ReducerT&, RetT, const KeyT&>, RetT>
RetT Botan::reduce ( const std::vector< KeyT > & keys,
RetT acc,
ReducerT reducer )

Reduce the values of keys into an accumulator initialized with acc using the reducer function reducer.

The reducer is a function taking the accumulator and a single key to return the new accumulator. Keys are consecutively reduced into the accumulator.

Returns
the accumulator containing the reduction of keys

Definition at line 30 of file stl_util.h.

33{
34 for(const KeyT& key : keys) {
35 acc = reducer(std::move(acc), key);
36 }
37 return acc;
38}

Referenced by Botan::Hybrid_PrivateKey::check_key(), Botan::Hybrid_PublicKey::check_key(), Botan::Kyber_AVX2::inverse_ntt(), Botan::TLS::Hybrid_KEM_PublicKey::load_for_group(), Botan::Hybrid_PublicKey::raw_public_key_bits(), and Botan::TLS::Hybrid_KEM_PublicKey::raw_public_key_bits().

◆ reduce_mod()

template<WordType W, size_t N, size_t XN>
std::array< W, N > Botan::reduce_mod ( const std::array< W, XN > & x,
const std::array< W, N > & p )
inlineconsteval

Definition at line 16 of file pcurves_util.h.

16 {
17 std::array<W, N + 1> r = {0};
18 std::array<W, N + 1> t = {0};
19
20 const size_t x_bits = XN * WordInfo<W>::bits;
21
22 for(size_t i = 0; i != x_bits; ++i) {
23 const size_t b = x_bits - 1 - i;
24
25 const size_t b_word = b / WordInfo<W>::bits;
26 const size_t b_bit = b % WordInfo<W>::bits;
27 const bool x_b = (x[b_word] >> b_bit) & 1;
28
30 // Conditional ok: this function is consteval
31 if(x_b) {
32 r[0] += 1;
33 }
34
35 const W carry = bigint_sub3(t.data(), r.data(), N + 1, p.data(), N);
36
37 // Conditional ok: this function is consteval
38 if(carry == 0) {
39 std::swap(r, t);
40 }
41 }
42
43 std::array<W, N> rs = {};
44 copy_mem(rs, std::span{r}.template first<N>());
45 return rs;
46}

References bigint_sub3(), copy_mem(), and shift_left().

Referenced by montygomery_r(), mul_mod(), and power_mod().

◆ require_hardware_provider()

template<typename OptionsT>
void Botan::require_hardware_provider ( const OptionsT & options,
std::string_view algo_name,
std::string_view provider_name )

For keys held in hardware (PKCS #11, TPM)

Such keys have exactly one implementation, so the provider option must be unset or name that provider. In particular "base", which names the software implementation, is not available for them.

Exceptions
Provider_Not_Foundotherwise

Definition at line 103 of file pk_options_impl.h.

103 {
104 const auto& provider = options.provider();
105 if(provider.has_value() && *provider != provider_name) {
106 throw Provider_Not_Found(algo_name, *provider);
107 }
108}

Referenced by Botan::TPM2::RSA_PrivateKey::_create_decryption_op(), Botan::TPM2::RSA_PublicKey::_create_encryption_op(), Botan::TPM2::EC_PrivateKey::_create_signature_op(), Botan::TPM2::RSA_PrivateKey::_create_signature_op(), Botan::TPM_PrivateKey::_create_signature_op(), Botan::TPM2::EC_PublicKey::_create_verification_op(), and Botan::TPM2::RSA_PublicKey::_create_verification_op().

◆ require_software_provider()

template<typename OptionsT>
void Botan::require_software_provider ( const OptionsT & options,
std::string_view algo_name )

For keys implemented in software

Such keys have only the "base" provider, so any other provider request is rejected. Reading the option here also acknowledges it.

Exceptions
Provider_Not_Foundif a different provider was requested

Definition at line 87 of file pk_options_impl.h.

87 {
88 if(options.using_provider()) {
89 throw Provider_Not_Found(algo_name, options.provider().value());
90 }
91}

Referenced by Botan::ElGamal_PrivateKey::_create_decryption_op(), Botan::RSA_PrivateKey::_create_decryption_op(), Botan::SM2_PrivateKey::_create_decryption_op(), Botan::ElGamal_PublicKey::_create_encryption_op(), Botan::RSA_PublicKey::_create_encryption_op(), Botan::SM2_PublicKey::_create_encryption_op(), Botan::Classic_McEliece_PrivateKey::_create_kem_decryption_op(), Botan::FrodoKEM_PrivateKey::_create_kem_decryption_op(), Botan::Kyber_PrivateKey::_create_kem_decryption_op(), Botan::McEliece_PrivateKey::_create_kem_decryption_op(), Botan::RSA_PrivateKey::_create_kem_decryption_op(), Botan::Classic_McEliece_PublicKey::_create_kem_encryption_op(), Botan::FrodoKEM_PublicKey::_create_kem_encryption_op(), Botan::Kyber_PublicKey::_create_kem_encryption_op(), Botan::McEliece_PublicKey::_create_kem_encryption_op(), Botan::RSA_PublicKey::_create_kem_encryption_op(), Botan::DH_PrivateKey::_create_key_agreement_op(), Botan::ECDH_PrivateKey::_create_key_agreement_op(), Botan::X25519_PrivateKey::_create_key_agreement_op(), Botan::X448_PrivateKey::_create_key_agreement_op(), Botan::Dilithium_PrivateKey::_create_signature_op(), Botan::DSA_PrivateKey::_create_signature_op(), Botan::ECDSA_PrivateKey::_create_signature_op(), Botan::ECGDSA_PrivateKey::_create_signature_op(), Botan::ECKCDSA_PrivateKey::_create_signature_op(), Botan::Ed25519_PrivateKey::_create_signature_op(), Botan::Ed448_PrivateKey::_create_signature_op(), Botan::GOST_3410_PrivateKey::_create_signature_op(), Botan::HSS_LMS_PrivateKey::_create_signature_op(), Botan::RSA_PrivateKey::_create_signature_op(), Botan::SM2_PrivateKey::_create_signature_op(), Botan::SphincsPlus_PrivateKey::_create_signature_op(), Botan::XMSS_PrivateKey::_create_signature_op(), Botan::Dilithium_PublicKey::_create_verification_op(), Botan::DSA_PublicKey::_create_verification_op(), Botan::ECDSA_PublicKey::_create_verification_op(), Botan::ECGDSA_PublicKey::_create_verification_op(), Botan::ECKCDSA_PublicKey::_create_verification_op(), Botan::Ed25519_PublicKey::_create_verification_op(), Botan::Ed448_PublicKey::_create_verification_op(), Botan::GOST_3410_PublicKey::_create_verification_op(), Botan::HSS_LMS_PublicKey::_create_verification_op(), Botan::RSA_PublicKey::_create_verification_op(), Botan::SM2_PublicKey::_create_verification_op(), Botan::SphincsPlus_PublicKey::_create_verification_op(), and Botan::XMSS_PublicKey::_create_verification_op().

◆ reverse_bytes()

template<std::unsigned_integral T>
T Botan::reverse_bytes ( T x)
inlineconstexpr

Swap the byte order of an unsigned integer

Definition at line 25 of file bswap.h.

25 {
26 if constexpr(sizeof(T) == 1) {
27 return x;
28 } else if constexpr(sizeof(T) == 2) {
29#if BOTAN_COMPILER_HAS_BUILTIN(__builtin_bswap16)
30 return static_cast<T>(__builtin_bswap16(x));
31#else
32 return static_cast<T>((x << 8) | (x >> 8));
33#endif
34 } else if constexpr(sizeof(T) == 4) {
35#if BOTAN_COMPILER_HAS_BUILTIN(__builtin_bswap32)
36 return static_cast<T>(__builtin_bswap32(x));
37#else
38 // MSVC at least recognizes this as a bswap
39 return static_cast<T>(((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8) |
40 ((x & 0xFF000000) >> 24));
41#endif
42 } else if constexpr(sizeof(T) == 8) {
43#if BOTAN_COMPILER_HAS_BUILTIN(__builtin_bswap64)
44 return static_cast<T>(__builtin_bswap64(x));
45#else
46 uint32_t hi = static_cast<uint32_t>(x >> 32);
47 uint32_t lo = static_cast<uint32_t>(x);
48
49 hi = reverse_bytes(hi);
50 lo = reverse_bytes(lo);
51
52 return (static_cast<T>(lo) << 32) | hi;
53#endif
54 }
55}

References reverse_bytes().

Referenced by ct_reverse_bits(), Botan::detail::load_any(), reverse_bytes(), and Botan::detail::store_any().

◆ rfc3394_keyunwrap()

secure_vector< uint8_t > Botan::rfc3394_keyunwrap ( const secure_vector< uint8_t > & key,
const SymmetricKey & kek )

Decrypt a key under a key encryption key using the algorithm described in RFC 3394

Parameters
keythe encrypted key to decrypt
kekthe key encryption key
Returns
key decrypted under kek

Definition at line 27 of file rfc3394.cpp.

27 {
28 BOTAN_ARG_CHECK(kek.size() == 16 || kek.size() == 24 || kek.size() == 32, "Invalid KEK length for NIST key wrap");
29
30 BOTAN_ARG_CHECK(key.size() >= 16 && key.size() % 8 == 0, "Bad input key size for NIST key unwrap");
31
32 const std::string cipher_name = "AES-" + std::to_string(8 * kek.size());
33 auto aes = BlockCipher::create_or_throw(cipher_name);
34 aes->set_key(kek);
35
36 return nist_key_unwrap(key.data(), key.size(), *aes);
37}
static std::unique_ptr< BlockCipher > create_or_throw(std::string_view algo_spec, std::string_view provider="")
size_t size() const
Definition symkey.h:34

References BOTAN_ARG_CHECK, Botan::BlockCipher::create_or_throw(), nist_key_unwrap(), and Botan::OctetString::size().

◆ rfc3394_keywrap()

secure_vector< uint8_t > Botan::rfc3394_keywrap ( const secure_vector< uint8_t > & key,
const SymmetricKey & kek )

Encrypt a key under a key encryption key using the algorithm described in RFC 3394

Parameters
keythe plaintext key to encrypt
kekthe key encryption key
Returns
key encrypted under kek

Definition at line 16 of file rfc3394.cpp.

16 {
17 BOTAN_ARG_CHECK(kek.size() == 16 || kek.size() == 24 || kek.size() == 32, "Invalid KEK length for NIST key wrap");
18
19 const std::string cipher_name = "AES-" + std::to_string(8 * kek.size());
20 auto aes = BlockCipher::create_or_throw(cipher_name);
21 aes->set_key(kek);
22
23 std::vector<uint8_t> wrapped = nist_key_wrap(key.data(), key.size(), *aes);
24 return secure_vector<uint8_t>(wrapped.begin(), wrapped.end());
25}

References BOTAN_ARG_CHECK, Botan::BlockCipher::create_or_throw(), nist_key_wrap(), and Botan::OctetString::size().

◆ RFC4880_decode_count()

size_t Botan::RFC4880_decode_count ( uint8_t encoded_iter)

Decode the iteration count from RFC 4880 encoding

Definition at line 61 of file rfc4880.cpp.

61 {
62 return OPENPGP_S2K_ITERS[iter];
63}

Referenced by Botan::OpenPGP_S2K::decode_count(), and RFC4880_round_iterations().

◆ RFC4880_encode_count()

uint8_t Botan::RFC4880_encode_count ( size_t iterations)

RFC 4880 encodes the iteration count to a single-byte value

Definition at line 47 of file rfc4880.cpp.

47 {
48 if(desired_iterations <= OPENPGP_S2K_ITERS[0]) {
49 return 0;
50 }
51
52 if(desired_iterations >= OPENPGP_S2K_ITERS[255]) {
53 return 255;
54 }
55
56 const uint32_t* i = std::lower_bound(OPENPGP_S2K_ITERS, OPENPGP_S2K_ITERS + 256, desired_iterations);
57
58 return static_cast<uint8_t>(i - OPENPGP_S2K_ITERS);
59}

Referenced by Botan::OpenPGP_S2K::encode_count(), and RFC4880_round_iterations().

◆ RFC4880_round_iterations()

size_t Botan::RFC4880_round_iterations ( size_t iterations)
inline

Round an arbitrary iteration count to next largest iteration count supported by RFC4880 encoding.

Definition at line 32 of file rfc4880.h.

32 {
34}
uint8_t RFC4880_encode_count(size_t desired_iterations)
Definition rfc4880.cpp:47
size_t RFC4880_decode_count(uint8_t iter)
Definition rfc4880.cpp:61

References RFC4880_decode_count(), RFC4880_encode_count(), and RFC4880_round_iterations().

Referenced by RFC4880_round_iterations(), and Botan::RFC4880_S2K_Family::tune_params().

◆ rho()

◆ root()

Gf448Elem Botan::root ( const Gf448Elem & elem)

Compute the root of elem in the field.

The root of a in GF(p) is computed as r = a^((p+1)/4) mod p. Note that the root is not unique, i.e. r and p-r are both roots.

Returns
GfPElem The root of this element.

Definition at line 451 of file curve448_gf.cpp.

451 {
452 // Compute elem^((P-3)/4) using an optimized addition chain (cost 457).
453 // (P-3)/4 = 2^446 - 2^222 - 1
454 // return = x223 << 223 + x222
455 std::array<uint64_t, WORDS_448> x222; // NOLINT(*-member-init)
456 std::array<uint64_t, WORDS_448> x223; // NOLINT(*-member-init)
457 gf_pow_2_222m1(x222, x223, elem.words());
458
459 Gf448Elem res(0);
460 gf_sqr_n(res.words(), x223, 223);
461 gf_mul(res.words(), res.words(), x222);
462 return res;
463}

References Botan::Gf448Elem::words().

Referenced by Botan::SphincsPlus_PrivateKey::check_key(), Botan::Ed448Point::decode(), Botan::Sphincs_Hash_Functions::H_msg(), Botan::XMSS_Hash::h_msg(), Botan::Sphincs_Hash_Functions::H_msg_digest(), Botan::XMSS_Hash::h_msg_init(), Botan::SphincsPlus_PrivateKey::SphincsPlus_PrivateKey(), xmss_gen_root(), and Botan::Sphincs_Hash_Functions::~Sphincs_Hash_Functions().

◆ rotl() [1/4]

template<size_t R>
SIMD_16x32 BOTAN_FN_ISA_AVX512 Botan::rotl ( SIMD_16x32 input)
inline

Definition at line 341 of file simd_avx512.h.

341 {
342 return input.rotl<R>();
343}
BOTAN_FN_ISA_AVX512 SIMD_16x32 rotl() const
Definition simd_avx512.h:86

References Botan::SIMD_16x32::rotl().

◆ rotl() [2/4]

template<size_t R>
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 Botan::rotl ( SIMD_4x32 input)
inline

Definition at line 993 of file simd_4x32.h.

993 {
994 return input.rotl<R>();
995}
BOTAN_FN_ISA_SIMD_4X32 SIMD_4x32 rotl() const noexcept
Definition simd_4x32.h:297

References Botan::SIMD_4x32::rotl().

◆ rotl() [3/4]

template<size_t R>
SIMD_8x32 BOTAN_FN_ISA_SIMD_8X32 Botan::rotl ( SIMD_8x32 input)
inline

Definition at line 410 of file simd_8x32.h.

410 {
411 return input.rotl<R>();
412}
BOTAN_FN_ISA_SIMD_8X32 SIMD_8x32 rotl() const noexcept
Definition simd_8x32.h:126

References Botan::SIMD_8x32::rotl().

◆ rotl() [4/4]

template<size_t ROT, std::unsigned_integral T>
requires (ROT > 0 && ROT < 8 * sizeof(T))
BOTAN_FORCE_INLINE constexpr T Botan::rotl ( T input)
constexpr

Bit rotation left by a compile-time constant amount

Parameters
inputthe input word
Returns
input rotated left by ROT bits

Definition at line 23 of file rotate.h.

25{
26 return static_cast<T>((input << ROT) | (input >> (8 * sizeof(T) - ROT)));
27}

References BOTAN_FORCE_INLINE.

Referenced by Botan::SHA_1::compress_n(), Botan::Noekeon::decrypt_n(), Botan::Noekeon::encrypt_n(), Botan::SHA1_F::F1(), Botan::SHA1_F::F2(), Botan::SHA1_F::F3(), Botan::SHA1_F::F4(), Botan::GOST_28147_89::GOST_28147_89(), keccak_rotl(), P0(), P1(), R1(), R2(), SM3_E(), and Botan::Serpent_F::transform().

◆ rotl_var()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::rotl_var ( T input,
size_t rot )
constexpr

Bit rotation left, variable rotation amount

Parameters
inputthe input word
rotthe number of bits to rotate, must be between 0 and sizeof(T)*8-1
Returns
input rotated left by rot bits

Definition at line 64 of file rotate.h.

64 {
65 return rot ? static_cast<T>((input << rot) | (input >> (sizeof(T) * 8 - rot))) : input;
66}

References BOTAN_FORCE_INLINE.

◆ rotr() [1/4]

template<size_t R>
SIMD_16x32 BOTAN_FN_ISA_AVX512 Botan::rotr ( SIMD_16x32 input)
inline

Definition at line 346 of file simd_avx512.h.

346 {
347 return input.rotr<R>();
348}
BOTAN_FN_ISA_AVX512 SIMD_16x32 rotr() const
Definition simd_avx512.h:93

References Botan::SIMD_16x32::rotr().

◆ rotr() [2/4]

template<size_t R>
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 Botan::rotr ( SIMD_4x32 input)
inline

Definition at line 998 of file simd_4x32.h.

998 {
999 return input.rotr<R>();
1000}
SIMD_4x32 BOTAN_FN_ISA_SIMD_4X32 rotr() const noexcept
Definition simd_4x32.h:345

References Botan::SIMD_4x32::rotr().

◆ rotr() [3/4]

template<size_t R>
SIMD_8x32 BOTAN_FN_ISA_SIMD_8X32 Botan::rotr ( SIMD_8x32 input)
inline

Definition at line 415 of file simd_8x32.h.

415 {
416 return input.rotr<R>();
417}
BOTAN_FN_ISA_SIMD_8X32 SIMD_8x32 rotr() const noexcept
Definition simd_8x32.h:155

References Botan::SIMD_8x32::rotr().

◆ rotr() [4/4]

template<size_t ROT, std::unsigned_integral T>
requires (ROT > 0 && ROT < 8 * sizeof(T))
BOTAN_FORCE_INLINE constexpr T Botan::rotr ( T input)
constexpr

Bit rotation right by a compile-time constant amount

Parameters
inputthe input word
Returns
input rotated right by ROT bits

Definition at line 35 of file rotate.h.

37{
38 return static_cast<T>((input >> ROT) | (input << (8 * sizeof(T) - ROT)));
39}

References BOTAN_FORCE_INLINE.

Referenced by Botan::Noekeon::decrypt_n(), Botan::Noekeon::encrypt_n(), Botan::Serpent_F::i_transform(), rho(), and sigma().

◆ rotr_var()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::rotr_var ( T input,
size_t rot )
constexpr

Bit rotation right, variable rotation amount

Parameters
inputthe input word
rotthe number of bits to rotate, must be between 0 and sizeof(T)*8-1
Returns
input rotated right by rot bits

Definition at line 75 of file rotate.h.

75 {
76 return rot ? static_cast<T>((input >> rot) | (input << (sizeof(T) * 8 - rot))) : input;
77}

References BOTAN_FORCE_INLINE.

◆ runtime_version_check()

std::string Botan::runtime_version_check ( uint32_t major,
uint32_t minor,
uint32_t patch )

Usable for checking that the DLL version loaded at runtime exactly matches the compile-time version. Call using BOTAN_VERSION_* macro values, like so:

#define BOTAN_VERSION_PATCH
Definition build.h:34
#define BOTAN_VERSION_MINOR
Definition build.h:29
#define BOTAN_VERSION_MAJOR
Definition build.h:24
std::string runtime_version_check(uint32_t major, uint32_t minor, uint32_t patch)
Definition version.cpp:75

It will return an empty string if the versions match, or otherwise an error message indicating the discrepancy. This only is useful in dynamic libraries, where it is possible to compile and run against different versions.

Definition at line 75 of file version.cpp.

75 {
76 if(major != version_major() || minor != version_minor() || patch != version_patch()) {
77 return fmt("Warning: linked version ({}) does not match version built against ({}.{}.{})\n",
79 major,
80 minor,
81 patch);
82 }
83
84 return "";
85}
uint32_t version_minor()
Definition version.cpp:59
const char * short_version_cstr()
Definition version.cpp:16
uint32_t version_major()
Definition version.cpp:55
uint32_t version_patch()
Definition version.cpp:63

References fmt(), short_version_cstr(), version_major(), version_minor(), and version_patch().

◆ same_mem()

template<typename T>
bool Botan::same_mem ( const T * p1,
const T * p2,
size_t n )
inline

Memory comparison, input insensitive

Parameters
p1a pointer to an array
p2a pointer to another array
nthe number of Ts in p1 and p2
Returns
true iff p1[i] == p2[i] forall i in [0...n)

Definition at line 346 of file mem_ops.h.

346 {
347 volatile T difference = 0;
348
349 for(size_t i = 0; i != n; ++i) {
350 difference = difference | (p1[i] ^ p2[i]);
351 }
352
353 return difference == 0;
354}

References same_mem().

Referenced by same_mem().

◆ scalar_blinding_bits()

size_t Botan::scalar_blinding_bits ( size_t scalar_bits)
constexpr

Return number of blinding bits to use

This can return any value between 0 and the scalar bit length.

The field arithmetic and scalar multiplication algorithms are anyway written and tested to be constant time; blinding is just used as a safety net in the case that the compiler rewrites constant time code to include variable time behavior. If utmost performance is of concern and you are in a position to test that your specific compiler for your specific architecture is not inserting variable time behavior where not expected (for example by using the existing valgrind-based CT checking) it is safe to modify this function to just return 0, or some very small blinding factor of 1-4 bits.

Definition at line 42 of file pcurves_mul.h.

42 {
43 // For blinding use 1/8 the order length for most curves; for P-521 we round down a bit
44 // so the masked scalar fits exactly in 9 or 18 words.
45
46 if(scalar_bits == 521) {
47 return 55;
48 } else {
49 return scalar_bits / 8;
50 }
51}

◆ scrypt() [1/2]

void Botan::scrypt ( uint8_t output[],
size_t output_len,
const char * password,
size_t password_len,
const uint8_t salt[],
size_t salt_len,
size_t N,
size_t r,
size_t p )
inline

Scrypt key derivation function (RFC 7914)

Parameters
outputthe output will be placed here
output_lenlength of output
passwordthe user password
password_lenlength of password
saltthe salt
salt_lenlength of salt
Nthe CPU/Memory cost parameter, must be power of 2
rthe block size parameter
pthe parallelization parameter

Suitable parameters for most uses would be N = 32768, r = 8, p = 1

Scrypt uses approximately (p + N + 1) * 128 * r bytes of memory

Definition at line 83 of file scrypt.h.

91 {
92 auto pwdhash_fam = PasswordHashFamily::create_or_throw("Scrypt");
93 auto pwdhash = pwdhash_fam->from_params(N, r, p);
94 pwdhash->derive_key(output, output_len, password, password_len, salt, salt_len);
95}

References Botan::PasswordHashFamily::create_or_throw(), and scrypt().

Referenced by scrypt(), and scrypt().

◆ scrypt() [2/2]

void Botan::scrypt ( uint8_t output[],
size_t output_len,
std::string_view password,
const uint8_t salt[],
size_t salt_len,
size_t N,
size_t r,
size_t p )
inline

Scrypt key derivation function (RFC 7914) Before 2.8 this function was the primary interface for scrypt

Parameters
outputthe output will be placed here
output_lenlength of output
passwordthe user password
saltthe salt
salt_lenlength of salt
Nthe CPU/Memory cost parameter, must be power of 2
rthe block size parameter
pthe parallelization parameter

Suitable parameters for most uses would be N = 32768, r = 8, p = 1

Scrypt uses approximately (p + N + 1) * 128 * r bytes of memory

Definition at line 115 of file scrypt.h.

122 {
123 auto pwdhash_fam = PasswordHashFamily::create_or_throw("Scrypt");
124 auto pwdhash = pwdhash_fam->from_params(N, r, p);
125 pwdhash->derive_key(output, output_len, password.data(), password.size(), salt, salt_len);
126}

References Botan::PasswordHashFamily::create_or_throw(), and scrypt().

◆ secure_scrub_memory() [1/2]

void Botan::secure_scrub_memory ( ranges::contiguous_output_range auto && data)

Zero memory contents in a way that a compiler should not elide, using some system specific technique.

Parameters
datathe data region to be scrubbed

Definition at line 59 of file mem_ops.h.

59 {
60 secure_scrub_memory(std::ranges::data(data), ranges::size_bytes(data));
61}

References secure_scrub_memory(), and Botan::ranges::size_bytes().

◆ secure_scrub_memory() [2/2]

void Botan::secure_scrub_memory ( void * ptr,
size_t n )

Scrub memory contents in a way that a compiler should not elide, using some system specific technique. Note that this function might not zero the memory (for example, in some hypothetical implementation it might combine the memory contents with the output of a system PRNG), but if you can detect any difference in behavior at runtime then the clearing is side-effecting and you can just use clear_mem.

Use this function to scrub memory just before deallocating it, or on a stack buffer before returning from the function.

Parameters
ptra pointer to memory to scrub
nthe number of bytes pointed to by ptr

Definition at line 24 of file mem_utils.cpp.

24 {
25 return secure_zeroize_buffer(ptr, n);
26}
void secure_zeroize_buffer(void *ptr, size_t n)
Definition mem_utils.cpp:28

References secure_zeroize_buffer().

Referenced by botan_scrub_mem(), Botan::Ascon_AEAD128_Mode::clear(), Botan::Polyval::clear(), deallocate_memory(), Botan::GHASH::final(), Botan::Polyval::final(), Botan::OS::free_locked_pages(), Botan::BLS12_381::Scalar::hash(), Botan::BLS12_381::PointMul< Pt >::msm_vartime(), Botan::BLS12_381::PointMul< Pt >::mul(), Botan::BLS12_381::PointMul< Pt >::mul2(), Botan::BLS12_381::PointMul< Pt >::mul2_vartime(), Botan::BLS12_381::PointMul< Pt >::mul_vartime(), Botan::GCM_SIV_Mode::reset(), Botan::GHASH::reset_state(), secure_scrub_memory(), Botan::BLS12_381::Scalar::serialize_to(), Botan::Sodium::sodium_free(), Botan::Sodium::sodium_memzero(), x25519_basepoint(), x25519_scalarmult(), Botan::Ascon_AEAD128_Mode::~Ascon_AEAD128_Mode(), Botan::BER_Object::~BER_Object(), Botan::BLAKE2s::~BLAKE2s(), and Botan::Sponge< words, word >::~Sponge().

◆ secure_zeroize_buffer()

BOTAN_TEST_API void Botan::secure_zeroize_buffer ( void * ptr,
size_t n )

Zeroize memory contents in a way that a compiler should not elide, using some system specific technique.

Use this function to scrub memory just before deallocating it, or on a stack buffer before returning from the function.

Parameters
ptra pointer to memory to scrub
nthe number of bytes pointed to by ptr

Definition at line 28 of file mem_utils.cpp.

28 {
29 if(n == 0) {
30 return;
31 }
32
33#if defined(BOTAN_TARGET_OS_HAS_RTLSECUREZEROMEMORY)
34 ::RtlSecureZeroMemory(ptr, n);
35
36#elif defined(BOTAN_TARGET_OS_HAS_EXPLICIT_BZERO)
37 ::explicit_bzero(ptr, n);
38
39#elif defined(BOTAN_TARGET_OS_HAS_EXPLICIT_MEMSET)
40 (void)::explicit_memset(ptr, 0, n);
41
42#else
43 /*
44 * Call memset through a static volatile pointer, which the compiler should
45 * not elide. This construct should be safe in conforming compilers, but who
46 * knows. This has been checked to generate the expected code, which saves the
47 * memset address in the data segment and unconditionally loads and jumps to
48 * that address, with the following targets:
49 *
50 * x86-64: Clang 19, GCC 6, 11, 13, 14
51 * riscv64: GCC 14
52 * aarch64: GCC 14
53 * armv7: GCC 14
54 *
55 * Actually all of them generated the expected jump even without marking the
56 * function pointer as volatile. However this seems worth including as an
57 * additional precaution.
58 */
59 static void* (*const volatile memset_ptr)(void*, int, size_t) = std::memset;
60 (memset_ptr)(ptr, 0, n);
61#endif
62}

Referenced by Botan::PCurve::PrimeOrderCurve::Scalar::_zeroize(), secure_scrub_memory(), Botan::AlignmentBuffer< T, BLOCK_SIZE, FINAL_BLOCK_STRATEGY >::~AlignmentBuffer(), and Botan::BlindedScalarBits< C, WindowBits+1 >::~BlindedScalarBits().

◆ set_mem()

void Botan::set_mem ( uint8_t * ptr,
size_t n,
uint8_t val )
inlineconstexpr

Set memory to a fixed value

Parameters
ptra pointer to an array of bytes
nthe number of Ts pointed to by ptr
valthe value to set each byte to

Definition at line 291 of file mem_ops.h.

291 {
292 if(n > 0) {
293 std::memset(ptr, val, n);
294 }
295}

References set_mem().

Referenced by set_mem().

◆ SHA2_32_F() [1/2]

BOTAN_FORCE_INLINE void Botan::SHA2_32_F ( uint32_t A,
uint32_t B,
uint32_t C,
uint32_t & D,
uint32_t E,
uint32_t F,
uint32_t G,
uint32_t & H,
uint32_t & M1,
uint32_t M2,
uint32_t M3,
uint32_t M4,
uint32_t magic )

Definition at line 33 of file sha2_32_f.h.

45 {
46 H += magic + rho<6, 11, 25>(E) + choose(E, F, G) + M1;
47 D += H;
48 H += rho<2, 13, 22>(A) + majority(A, B, C);
49 M1 += sigma<17, 19, 10>(M2) + M3 + sigma<7, 18, 3>(M4);
50}
BOTAN_FORCE_INLINE constexpr T rho(T x)
Definition rotate.h:53
BOTAN_FORCE_INLINE constexpr T sigma(T x)
Definition rotate.h:45

References BOTAN_FORCE_INLINE, choose(), majority(), rho(), and sigma().

Referenced by Botan::SHA_256::compress_digest().

◆ SHA2_32_F() [2/2]

BOTAN_FORCE_INLINE void Botan::SHA2_32_F ( uint32_t A,
uint32_t B,
uint32_t C,
uint32_t & D,
uint32_t E,
uint32_t F,
uint32_t G,
uint32_t & H,
uint32_t M )

Definition at line 55 of file sha2_32_f.h.

56 {
57 H += rho<6, 11, 25>(E) + choose(E, F, G) + M;
58 D += H;
59 H += rho<2, 13, 22>(A) + majority(A, B, C);
60}

References BOTAN_FORCE_INLINE, choose(), majority(), and rho().

◆ sha2_32_mb_compress_x16()

BOTAN_FN_ISA_AVX512 void Botan::sha2_32_mb_compress_x16 ( uint8_t * states,
const uint8_t *const * blocks,
size_t nblocks )

Definition at line 55 of file hash_engine_sha2_32_avx512.cpp.

55 {
56 SIMD_16x32 S[8];
57 for(size_t j = 0; j != 8; ++j) {
58 S[j] = SIMD_16x32::load_le(states + 64 * j);
59 }
60
61 for(size_t n = 0; n != nblocks; ++n) {
62 // Initialized directly from the loads, since default construction
63 // would zero the whole array first
64 SIMD_16x32 W[16] = {SIMD_16x32::load_be<64>(blocks, 0, n),
65 SIMD_16x32::load_be<64>(blocks, 1, n),
66 SIMD_16x32::load_be<64>(blocks, 2, n),
67 SIMD_16x32::load_be<64>(blocks, 3, n),
68 SIMD_16x32::load_be<64>(blocks, 4, n),
69 SIMD_16x32::load_be<64>(blocks, 5, n),
70 SIMD_16x32::load_be<64>(blocks, 6, n),
71 SIMD_16x32::load_be<64>(blocks, 7, n),
72 SIMD_16x32::load_be<64>(blocks, 8, n),
73 SIMD_16x32::load_be<64>(blocks, 9, n),
74 SIMD_16x32::load_be<64>(blocks, 10, n),
75 SIMD_16x32::load_be<64>(blocks, 11, n),
76 SIMD_16x32::load_be<64>(blocks, 12, n),
77 SIMD_16x32::load_be<64>(blocks, 13, n),
78 SIMD_16x32::load_be<64>(blocks, 14, n),
79 SIMD_16x32::load_be<64>(blocks, 15, n)};
81 W[0], W[1], W[2], W[3], W[4], W[5], W[6], W[7], W[8], W[9], W[10], W[11], W[12], W[13], W[14], W[15]);
82
83 SIMD_16x32 A = S[0];
84 SIMD_16x32 B = S[1];
85 SIMD_16x32 C = S[2];
86 SIMD_16x32 D = S[3];
87 SIMD_16x32 E = S[4];
88 SIMD_16x32 F = S[5];
89 SIMD_16x32 G = S[6];
90 SIMD_16x32 H = S[7];
91
92 // Every index into W is a constant so that it can stay in registers
93 rnd(A, B, C, D, E, F, G, H, W[0], SHA256_K[0]);
94 rnd(H, A, B, C, D, E, F, G, W[1], SHA256_K[1]);
95 rnd(G, H, A, B, C, D, E, F, W[2], SHA256_K[2]);
96 rnd(F, G, H, A, B, C, D, E, W[3], SHA256_K[3]);
97 rnd(E, F, G, H, A, B, C, D, W[4], SHA256_K[4]);
98 rnd(D, E, F, G, H, A, B, C, W[5], SHA256_K[5]);
99 rnd(C, D, E, F, G, H, A, B, W[6], SHA256_K[6]);
100 rnd(B, C, D, E, F, G, H, A, W[7], SHA256_K[7]);
101 rnd(A, B, C, D, E, F, G, H, W[8], SHA256_K[8]);
102 rnd(H, A, B, C, D, E, F, G, W[9], SHA256_K[9]);
103 rnd(G, H, A, B, C, D, E, F, W[10], SHA256_K[10]);
104 rnd(F, G, H, A, B, C, D, E, W[11], SHA256_K[11]);
105 rnd(E, F, G, H, A, B, C, D, W[12], SHA256_K[12]);
106 rnd(D, E, F, G, H, A, B, C, W[13], SHA256_K[13]);
107 rnd(C, D, E, F, G, H, A, B, W[14], SHA256_K[14]);
108 rnd(B, C, D, E, F, G, H, A, W[15], SHA256_K[15]);
109
110 for(size_t t = 16; t != 64; t += 16) {
111 rnd(A, B, C, D, E, F, G, H, next_w<0>(W), SHA256_K[t + 0]);
112 rnd(H, A, B, C, D, E, F, G, next_w<1>(W), SHA256_K[t + 1]);
113 rnd(G, H, A, B, C, D, E, F, next_w<2>(W), SHA256_K[t + 2]);
114 rnd(F, G, H, A, B, C, D, E, next_w<3>(W), SHA256_K[t + 3]);
115 rnd(E, F, G, H, A, B, C, D, next_w<4>(W), SHA256_K[t + 4]);
116 rnd(D, E, F, G, H, A, B, C, next_w<5>(W), SHA256_K[t + 5]);
117 rnd(C, D, E, F, G, H, A, B, next_w<6>(W), SHA256_K[t + 6]);
118 rnd(B, C, D, E, F, G, H, A, next_w<7>(W), SHA256_K[t + 7]);
119 rnd(A, B, C, D, E, F, G, H, next_w<8>(W), SHA256_K[t + 8]);
120 rnd(H, A, B, C, D, E, F, G, next_w<9>(W), SHA256_K[t + 9]);
121 rnd(G, H, A, B, C, D, E, F, next_w<10>(W), SHA256_K[t + 10]);
122 rnd(F, G, H, A, B, C, D, E, next_w<11>(W), SHA256_K[t + 11]);
123 rnd(E, F, G, H, A, B, C, D, next_w<12>(W), SHA256_K[t + 12]);
124 rnd(D, E, F, G, H, A, B, C, next_w<13>(W), SHA256_K[t + 13]);
125 rnd(C, D, E, F, G, H, A, B, next_w<14>(W), SHA256_K[t + 14]);
126 rnd(B, C, D, E, F, G, H, A, next_w<15>(W), SHA256_K[t + 15]);
127 }
128
129 S[0] += A;
130 S[1] += B;
131 S[2] += C;
132 S[3] += D;
133 S[4] += E;
134 S[5] += F;
135 S[6] += G;
136 S[7] += H;
137 }
138
139 for(size_t j = 0; j != 8; ++j) {
140 S[j].store_le(states + 64 * j);
141 }
142}
static BOTAN_FN_ISA_AVX512 void transpose(SIMD_16x32 &B0, SIMD_16x32 &B1, SIMD_16x32 &B2, SIMD_16x32 &B3)
BOTAN_FN_ISA_AVX512 void store_le(uint8_t out[]) const
Definition simd_avx512.h:80
static BOTAN_FN_ISA_AVX512 SIMD_16x32 load_le(const uint8_t *in)
Definition simd_avx512.h:63
static BOTAN_FN_ISA_AVX512 SIMD_16x32 load_be(const uint8_t *in)
Definition simd_avx512.h:68
constexpr uint32_t SHA256_K[64]
Definition sha2_32_f.h:19

References Botan::SIMD_16x32::load_be(), Botan::SIMD_16x32::load_le(), SHA256_K, Botan::SIMD_16x32::store_le(), and Botan::SIMD_16x32::transpose().

Referenced by create_sha2_32_mb_engine().

◆ sha2_32_mb_compress_x8()

BOTAN_FN_ISA_AVX2 void Botan::sha2_32_mb_compress_x8 ( uint8_t * states,
const uint8_t *const * blocks,
size_t nblocks )

Definition at line 44 of file hash_engine_sha2_32_avx2.cpp.

44 {
45 SIMD_8x32 S[8];
46 for(size_t j = 0; j != 8; ++j) {
47 S[j] = SIMD_8x32::load_le(states + 32 * j);
48 }
49
50 for(size_t n = 0; n != nblocks; ++n) {
51 // Initialized directly from the loads, since default construction
52 // would zero the whole array first
53 SIMD_8x32 W[16] = {SIMD_8x32::load_be<64>(blocks, 0, n, 0),
54 SIMD_8x32::load_be<64>(blocks, 1, n, 0),
55 SIMD_8x32::load_be<64>(blocks, 2, n, 0),
56 SIMD_8x32::load_be<64>(blocks, 3, n, 0),
57 SIMD_8x32::load_be<64>(blocks, 4, n, 0),
58 SIMD_8x32::load_be<64>(blocks, 5, n, 0),
59 SIMD_8x32::load_be<64>(blocks, 6, n, 0),
60 SIMD_8x32::load_be<64>(blocks, 7, n, 0),
61 SIMD_8x32::load_be<64>(blocks, 0, n, 32),
62 SIMD_8x32::load_be<64>(blocks, 1, n, 32),
63 SIMD_8x32::load_be<64>(blocks, 2, n, 32),
64 SIMD_8x32::load_be<64>(blocks, 3, n, 32),
65 SIMD_8x32::load_be<64>(blocks, 4, n, 32),
66 SIMD_8x32::load_be<64>(blocks, 5, n, 32),
67 SIMD_8x32::load_be<64>(blocks, 6, n, 32),
68 SIMD_8x32::load_be<64>(blocks, 7, n, 32)};
69 SIMD_8x32::transpose(W[0], W[1], W[2], W[3], W[4], W[5], W[6], W[7]);
70 SIMD_8x32::transpose(W[8], W[9], W[10], W[11], W[12], W[13], W[14], W[15]);
71
72 SIMD_8x32 A = S[0];
73 SIMD_8x32 B = S[1];
74 SIMD_8x32 C = S[2];
75 SIMD_8x32 D = S[3];
76 SIMD_8x32 E = S[4];
77 SIMD_8x32 F = S[5];
78 SIMD_8x32 G = S[6];
79 SIMD_8x32 H = S[7];
80
81 for(size_t t = 0; t != 16; t += 8) {
82 rnd(A, B, C, D, E, F, G, H, W[t + 0], SHA256_K[t + 0]);
83 rnd(H, A, B, C, D, E, F, G, W[t + 1], SHA256_K[t + 1]);
84 rnd(G, H, A, B, C, D, E, F, W[t + 2], SHA256_K[t + 2]);
85 rnd(F, G, H, A, B, C, D, E, W[t + 3], SHA256_K[t + 3]);
86 rnd(E, F, G, H, A, B, C, D, W[t + 4], SHA256_K[t + 4]);
87 rnd(D, E, F, G, H, A, B, C, W[t + 5], SHA256_K[t + 5]);
88 rnd(C, D, E, F, G, H, A, B, W[t + 6], SHA256_K[t + 6]);
89 rnd(B, C, D, E, F, G, H, A, W[t + 7], SHA256_K[t + 7]);
90 }
91
92 for(size_t t = 16; t != 64; t += 8) {
93 rnd(A, B, C, D, E, F, G, H, next_w(W, (t + 0) % 16), SHA256_K[t + 0]);
94 rnd(H, A, B, C, D, E, F, G, next_w(W, (t + 1) % 16), SHA256_K[t + 1]);
95 rnd(G, H, A, B, C, D, E, F, next_w(W, (t + 2) % 16), SHA256_K[t + 2]);
96 rnd(F, G, H, A, B, C, D, E, next_w(W, (t + 3) % 16), SHA256_K[t + 3]);
97 rnd(E, F, G, H, A, B, C, D, next_w(W, (t + 4) % 16), SHA256_K[t + 4]);
98 rnd(D, E, F, G, H, A, B, C, next_w(W, (t + 5) % 16), SHA256_K[t + 5]);
99 rnd(C, D, E, F, G, H, A, B, next_w(W, (t + 6) % 16), SHA256_K[t + 6]);
100 rnd(B, C, D, E, F, G, H, A, next_w(W, (t + 7) % 16), SHA256_K[t + 7]);
101 }
102
103 S[0] += A;
104 S[1] += B;
105 S[2] += C;
106 S[3] += D;
107 S[4] += E;
108 S[5] += F;
109 S[6] += G;
110 S[7] += H;
111 }
112
113 for(size_t j = 0; j != 8; ++j) {
114 S[j].store_le(states + 32 * j);
115 }
116}
static BOTAN_FN_ISA_SIMD_8X32 void transpose(SIMD_8x32 &B0, SIMD_8x32 &B1, SIMD_8x32 &B2, SIMD_8x32 &B3) noexcept
Definition simd_8x32.h:274
static BOTAN_FN_ISA_SIMD_8X32 SIMD_8x32 load_le(const uint8_t *in) noexcept
Definition simd_8x32.h:61
static BOTAN_FN_ISA_SIMD_8X32 SIMD_8x32 load_be(const uint8_t *in) noexcept
Definition simd_8x32.h:81
BOTAN_FN_ISA_SIMD_8X32 void store_le(uint8_t out[]) const noexcept
Definition simd_8x32.h:94

References Botan::SIMD_8x32::load_be(), Botan::SIMD_8x32::load_le(), SHA256_K, Botan::SIMD_8x32::store_le(), and Botan::SIMD_8x32::transpose().

Referenced by create_sha2_32_mb_engine().

◆ sha2_32_mb_extract_x16()

BOTAN_FN_ISA_AVX512 void Botan::sha2_32_mb_extract_x16 ( const uint8_t * states,
uint8_t * digests )

Definition at line 144 of file hash_engine_sha2_32_avx512.cpp.

144 {
145 SIMD_16x32 S[8];
146 for(size_t j = 0; j != 8; ++j) {
147 S[j] = SIMD_16x32::load_le(states + 64 * j).bswap();
148 }
149
150 // Each S[j] holds word j of all 16 lanes. The 4-way transpose works
151 // within each 128-bit quarter, so afterwards quarter q of S[k] holds
152 // words 0..3 of lane 4*q+k, and quarter q of S[4+k] its words 4..7.
153 SIMD_16x32::transpose(S[0], S[1], S[2], S[3]);
154 SIMD_16x32::transpose(S[4], S[5], S[6], S[7]);
155
156 for(size_t k = 0; k != 4; ++k) {
157 store_quarters(S[k], digests + 32 * k, 128);
158 store_quarters(S[4 + k], digests + 32 * k + 16, 128);
159 }
160}
BOTAN_FN_ISA_AVX512 SIMD_16x32 bswap() const

References Botan::SIMD_16x32::bswap(), Botan::SIMD_16x32::load_le(), and Botan::SIMD_16x32::transpose().

Referenced by create_sha2_32_mb_engine().

◆ sha2_32_mb_extract_x8()

BOTAN_FN_ISA_AVX2 void Botan::sha2_32_mb_extract_x8 ( const uint8_t * states,
uint8_t * digests )

Definition at line 118 of file hash_engine_sha2_32_avx2.cpp.

118 {
119 SIMD_8x32 S[8];
120 for(size_t j = 0; j != 8; ++j) {
121 S[j] = SIMD_8x32::load_le(states + 32 * j);
122 }
123
124 // Each S[j] holds word j of all 8 lanes; the transpose turns that
125 // into the 8 words of each lane
126 SIMD_8x32::transpose(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7]);
127
128 for(size_t l = 0; l != 8; ++l) {
129 S[l].store_be(digests + 32 * l);
130 }
131}
BOTAN_FN_ISA_SIMD_8X32 void store_be(uint8_t out[]) const noexcept
Definition simd_8x32.h:123

References Botan::SIMD_8x32::load_le(), Botan::SIMD_8x32::store_be(), and Botan::SIMD_8x32::transpose().

Referenced by create_sha2_32_mb_engine().

◆ SHA2_64_F() [1/2]

BOTAN_FORCE_INLINE void Botan::SHA2_64_F ( uint64_t A,
uint64_t B,
uint64_t C,
uint64_t & D,
uint64_t E,
uint64_t F,
uint64_t G,
uint64_t & H,
uint64_t & M1,
uint64_t M2,
uint64_t M3,
uint64_t M4,
uint64_t magic )

Definition at line 41 of file sha2_64_f.h.

53 {
54 H += magic + rho<14, 18, 41>(E) + choose(E, F, G) + M1;
55 D += H;
56 H += rho<28, 34, 39>(A) + majority(A, B, C);
57 M1 += sigma<19, 61, 6>(M2) + M3 + sigma<1, 8, 7>(M4);
58}

References BOTAN_FORCE_INLINE, choose(), majority(), rho(), and sigma().

Referenced by Botan::SHA_512::compress_digest().

◆ SHA2_64_F() [2/2]

BOTAN_FORCE_INLINE void Botan::SHA2_64_F ( uint64_t A,
uint64_t B,
uint64_t C,
uint64_t & D,
uint64_t E,
uint64_t F,
uint64_t G,
uint64_t & H,
uint64_t M )

Definition at line 63 of file sha2_64_f.h.

64 {
65 H += rho<14, 18, 41>(E) + choose(E, F, G) + M;
66 D += H;
67 H += rho<28, 34, 39>(A) + majority(A, B, C);
68}

References BOTAN_FORCE_INLINE, choose(), majority(), and rho().

◆ sha2_64_mb_compress_x4()

BOTAN_FN_ISA_SIMD_4X64 void Botan::sha2_64_mb_compress_x4 ( uint8_t * states,
const uint8_t *const * blocks,
size_t nblocks )

Definition at line 44 of file hash_engine_sha2_64_avx2.cpp.

44 {
45 SIMD_4x64 S[8];
46 for(size_t j = 0; j != 8; ++j) {
47 S[j] = SIMD_4x64::load_le(states + 32 * j);
48 }
49
50 for(size_t n = 0; n != nblocks; ++n) {
51 // Initialized directly from the loads, since default construction
52 // would zero the whole array first
53 SIMD_4x64 W[16] = {SIMD_4x64::load_be<128>(blocks, 0, n, 0),
54 SIMD_4x64::load_be<128>(blocks, 1, n, 0),
55 SIMD_4x64::load_be<128>(blocks, 2, n, 0),
56 SIMD_4x64::load_be<128>(blocks, 3, n, 0),
57 SIMD_4x64::load_be<128>(blocks, 0, n, 32),
58 SIMD_4x64::load_be<128>(blocks, 1, n, 32),
59 SIMD_4x64::load_be<128>(blocks, 2, n, 32),
60 SIMD_4x64::load_be<128>(blocks, 3, n, 32),
61 SIMD_4x64::load_be<128>(blocks, 0, n, 64),
62 SIMD_4x64::load_be<128>(blocks, 1, n, 64),
63 SIMD_4x64::load_be<128>(blocks, 2, n, 64),
64 SIMD_4x64::load_be<128>(blocks, 3, n, 64),
65 SIMD_4x64::load_be<128>(blocks, 0, n, 96),
66 SIMD_4x64::load_be<128>(blocks, 1, n, 96),
67 SIMD_4x64::load_be<128>(blocks, 2, n, 96),
68 SIMD_4x64::load_be<128>(blocks, 3, n, 96)};
69 for(size_t j = 0; j != 4; ++j) {
70 SIMD_4x64::transpose(W[4 * j + 0], W[4 * j + 1], W[4 * j + 2], W[4 * j + 3]);
71 }
72
73 SIMD_4x64 A = S[0];
74 SIMD_4x64 B = S[1];
75 SIMD_4x64 C = S[2];
76 SIMD_4x64 D = S[3];
77 SIMD_4x64 E = S[4];
78 SIMD_4x64 F = S[5];
79 SIMD_4x64 G = S[6];
80 SIMD_4x64 H = S[7];
81
82 for(size_t t = 0; t != 16; t += 8) {
83 rnd(A, B, C, D, E, F, G, H, W[t + 0], SHA512_K[t + 0]);
84 rnd(H, A, B, C, D, E, F, G, W[t + 1], SHA512_K[t + 1]);
85 rnd(G, H, A, B, C, D, E, F, W[t + 2], SHA512_K[t + 2]);
86 rnd(F, G, H, A, B, C, D, E, W[t + 3], SHA512_K[t + 3]);
87 rnd(E, F, G, H, A, B, C, D, W[t + 4], SHA512_K[t + 4]);
88 rnd(D, E, F, G, H, A, B, C, W[t + 5], SHA512_K[t + 5]);
89 rnd(C, D, E, F, G, H, A, B, W[t + 6], SHA512_K[t + 6]);
90 rnd(B, C, D, E, F, G, H, A, W[t + 7], SHA512_K[t + 7]);
91 }
92
93 for(size_t t = 16; t != 80; t += 8) {
94 rnd(A, B, C, D, E, F, G, H, next_w(W, (t + 0) % 16), SHA512_K[t + 0]);
95 rnd(H, A, B, C, D, E, F, G, next_w(W, (t + 1) % 16), SHA512_K[t + 1]);
96 rnd(G, H, A, B, C, D, E, F, next_w(W, (t + 2) % 16), SHA512_K[t + 2]);
97 rnd(F, G, H, A, B, C, D, E, next_w(W, (t + 3) % 16), SHA512_K[t + 3]);
98 rnd(E, F, G, H, A, B, C, D, next_w(W, (t + 4) % 16), SHA512_K[t + 4]);
99 rnd(D, E, F, G, H, A, B, C, next_w(W, (t + 5) % 16), SHA512_K[t + 5]);
100 rnd(C, D, E, F, G, H, A, B, next_w(W, (t + 6) % 16), SHA512_K[t + 6]);
101 rnd(B, C, D, E, F, G, H, A, next_w(W, (t + 7) % 16), SHA512_K[t + 7]);
102 }
103
104 S[0] += A;
105 S[1] += B;
106 S[2] += C;
107 S[3] += D;
108 S[4] += E;
109 S[5] += F;
110 S[6] += G;
111 S[7] += H;
112 }
113
114 for(size_t j = 0; j != 8; ++j) {
115 S[j].store_le(states + 32 * j);
116 }
117}
static BOTAN_FN_ISA_SIMD_4X64 SIMD_4x64 load_be(const void *in)
Definition simd_4x64.h:49
static BOTAN_FN_ISA_SIMD_4X64 void transpose(SIMD_4x64 &B0, SIMD_4x64 &B1, SIMD_4x64 &B2, SIMD_4x64 &B3)
Definition simd_4x64.h:211
constexpr uint64_t SHA512_K[80]
Definition sha2_64_f.h:19

References Botan::SIMD_4x64::load_be(), Botan::SIMD_4x64::load_le(), SHA512_K, Botan::SIMD_4x64::store_le(), and Botan::SIMD_4x64::transpose().

Referenced by create_sha2_64_mb_engine().

◆ sha2_64_mb_compress_x8()

BOTAN_FN_ISA_SIMD_8X64 void Botan::sha2_64_mb_compress_x8 ( uint8_t * states,
const uint8_t *const * blocks,
size_t nblocks )

Definition at line 45 of file hash_engine_sha2_64_avx512.cpp.

45 {
46 SIMD_8x64 S[8];
47 for(size_t j = 0; j != 8; ++j) {
48 S[j] = SIMD_8x64::load_le(states + 64 * j);
49 }
50
51 for(size_t n = 0; n != nblocks; ++n) {
52 // Initialized directly from the loads, since default construction
53 // would zero the whole array first
54 SIMD_8x64 W[16] = {SIMD_8x64::load_be<128>(blocks, 0, n, 0),
55 SIMD_8x64::load_be<128>(blocks, 1, n, 0),
56 SIMD_8x64::load_be<128>(blocks, 2, n, 0),
57 SIMD_8x64::load_be<128>(blocks, 3, n, 0),
58 SIMD_8x64::load_be<128>(blocks, 4, n, 0),
59 SIMD_8x64::load_be<128>(blocks, 5, n, 0),
60 SIMD_8x64::load_be<128>(blocks, 6, n, 0),
61 SIMD_8x64::load_be<128>(blocks, 7, n, 0),
62 SIMD_8x64::load_be<128>(blocks, 0, n, 64),
63 SIMD_8x64::load_be<128>(blocks, 1, n, 64),
64 SIMD_8x64::load_be<128>(blocks, 2, n, 64),
65 SIMD_8x64::load_be<128>(blocks, 3, n, 64),
66 SIMD_8x64::load_be<128>(blocks, 4, n, 64),
67 SIMD_8x64::load_be<128>(blocks, 5, n, 64),
68 SIMD_8x64::load_be<128>(blocks, 6, n, 64),
69 SIMD_8x64::load_be<128>(blocks, 7, n, 64)};
70 SIMD_8x64::transpose(W[0], W[1], W[2], W[3], W[4], W[5], W[6], W[7]);
71 SIMD_8x64::transpose(W[8], W[9], W[10], W[11], W[12], W[13], W[14], W[15]);
72
73 SIMD_8x64 A = S[0];
74 SIMD_8x64 B = S[1];
75 SIMD_8x64 C = S[2];
76 SIMD_8x64 D = S[3];
77 SIMD_8x64 E = S[4];
78 SIMD_8x64 F = S[5];
79 SIMD_8x64 G = S[6];
80 SIMD_8x64 H = S[7];
81
82 // Every index into W is a constant so that it can stay in registers
83 rnd(A, B, C, D, E, F, G, H, W[0], SHA512_K[0]);
84 rnd(H, A, B, C, D, E, F, G, W[1], SHA512_K[1]);
85 rnd(G, H, A, B, C, D, E, F, W[2], SHA512_K[2]);
86 rnd(F, G, H, A, B, C, D, E, W[3], SHA512_K[3]);
87 rnd(E, F, G, H, A, B, C, D, W[4], SHA512_K[4]);
88 rnd(D, E, F, G, H, A, B, C, W[5], SHA512_K[5]);
89 rnd(C, D, E, F, G, H, A, B, W[6], SHA512_K[6]);
90 rnd(B, C, D, E, F, G, H, A, W[7], SHA512_K[7]);
91 rnd(A, B, C, D, E, F, G, H, W[8], SHA512_K[8]);
92 rnd(H, A, B, C, D, E, F, G, W[9], SHA512_K[9]);
93 rnd(G, H, A, B, C, D, E, F, W[10], SHA512_K[10]);
94 rnd(F, G, H, A, B, C, D, E, W[11], SHA512_K[11]);
95 rnd(E, F, G, H, A, B, C, D, W[12], SHA512_K[12]);
96 rnd(D, E, F, G, H, A, B, C, W[13], SHA512_K[13]);
97 rnd(C, D, E, F, G, H, A, B, W[14], SHA512_K[14]);
98 rnd(B, C, D, E, F, G, H, A, W[15], SHA512_K[15]);
99
100 for(size_t t = 16; t != 80; t += 16) {
101 rnd(A, B, C, D, E, F, G, H, next_w<0>(W), SHA512_K[t + 0]);
102 rnd(H, A, B, C, D, E, F, G, next_w<1>(W), SHA512_K[t + 1]);
103 rnd(G, H, A, B, C, D, E, F, next_w<2>(W), SHA512_K[t + 2]);
104 rnd(F, G, H, A, B, C, D, E, next_w<3>(W), SHA512_K[t + 3]);
105 rnd(E, F, G, H, A, B, C, D, next_w<4>(W), SHA512_K[t + 4]);
106 rnd(D, E, F, G, H, A, B, C, next_w<5>(W), SHA512_K[t + 5]);
107 rnd(C, D, E, F, G, H, A, B, next_w<6>(W), SHA512_K[t + 6]);
108 rnd(B, C, D, E, F, G, H, A, next_w<7>(W), SHA512_K[t + 7]);
109 rnd(A, B, C, D, E, F, G, H, next_w<8>(W), SHA512_K[t + 8]);
110 rnd(H, A, B, C, D, E, F, G, next_w<9>(W), SHA512_K[t + 9]);
111 rnd(G, H, A, B, C, D, E, F, next_w<10>(W), SHA512_K[t + 10]);
112 rnd(F, G, H, A, B, C, D, E, next_w<11>(W), SHA512_K[t + 11]);
113 rnd(E, F, G, H, A, B, C, D, next_w<12>(W), SHA512_K[t + 12]);
114 rnd(D, E, F, G, H, A, B, C, next_w<13>(W), SHA512_K[t + 13]);
115 rnd(C, D, E, F, G, H, A, B, next_w<14>(W), SHA512_K[t + 14]);
116 rnd(B, C, D, E, F, G, H, A, next_w<15>(W), SHA512_K[t + 15]);
117 }
118
119 S[0] += A;
120 S[1] += B;
121 S[2] += C;
122 S[3] += D;
123 S[4] += E;
124 S[5] += F;
125 S[6] += G;
126 S[7] += H;
127 }
128
129 for(size_t j = 0; j != 8; ++j) {
130 S[j].store_le(states + 64 * j);
131 }
132}
static BOTAN_FN_ISA_SIMD_8X64 SIMD_8x64 load_be(const void *in)
Definition simd_8x64.h:60
static BOTAN_FN_ISA_SIMD_8X64 void transpose(SIMD_8x64 &B0, SIMD_8x64 &B1, SIMD_8x64 &B2, SIMD_8x64 &B3, SIMD_8x64 &B4, SIMD_8x64 &B5, SIMD_8x64 &B6, SIMD_8x64 &B7)
Definition simd_8x64.h:185

References Botan::SIMD_8x64::load_be(), Botan::SIMD_8x64::load_le(), SHA512_K, Botan::SIMD_8x64::store_le(), and Botan::SIMD_8x64::transpose().

Referenced by create_sha2_64_mb_engine().

◆ sha2_64_mb_extract_x4()

BOTAN_FN_ISA_SIMD_4X64 void Botan::sha2_64_mb_extract_x4 ( const uint8_t * states,
uint8_t * digests )

Definition at line 119 of file hash_engine_sha2_64_avx2.cpp.

119 {
120 SIMD_4x64 S[8];
121 for(size_t j = 0; j != 8; ++j) {
122 S[j] = SIMD_4x64::load_le(states + 32 * j);
123 }
124
125 // Each S[j] holds word j of all 4 lanes. After the transposes S[k]
126 // holds words 0..3 of lane k and S[4+k] its words 4..7
127 SIMD_4x64::transpose(S[0], S[1], S[2], S[3]);
128 SIMD_4x64::transpose(S[4], S[5], S[6], S[7]);
129
130 for(size_t l = 0; l != 4; ++l) {
131 S[l].store_be(digests + 64 * l);
132 S[4 + l].store_be(digests + 64 * l + 32);
133 }
134}
BOTAN_FN_ISA_SIMD_4X64 void store_be(uint8_t out[]) const
Definition simd_4x64.h:82

References Botan::SIMD_4x64::load_le(), Botan::SIMD_4x64::store_be(), and Botan::SIMD_4x64::transpose().

Referenced by create_sha2_64_mb_engine().

◆ sha2_64_mb_extract_x8()

BOTAN_FN_ISA_SIMD_8X64 void Botan::sha2_64_mb_extract_x8 ( const uint8_t * states,
uint8_t * digests )

Definition at line 134 of file hash_engine_sha2_64_avx512.cpp.

134 {
135 SIMD_8x64 S[8];
136 for(size_t j = 0; j != 8; ++j) {
137 S[j] = SIMD_8x64::load_le(states + 64 * j);
138 }
139
140 // Each S[j] holds word j of all 8 lanes; the transpose turns that
141 // into the 8 words of each lane
142 SIMD_8x64::transpose(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7]);
143
144 for(size_t l = 0; l != 8; ++l) {
145 S[l].store_be(digests + 64 * l);
146 }
147}
BOTAN_FN_ISA_SIMD_8X64 void store_be(uint8_t out[]) const
Definition simd_8x64.h:88

References Botan::SIMD_8x64::load_le(), Botan::SIMD_8x64::store_be(), and Botan::SIMD_8x64::transpose().

Referenced by create_sha2_64_mb_engine().

◆ shanks_tonelli_c1c2()

template<WordType W, size_t N>
std::pair< size_t, std::array< W, N > > Botan::shanks_tonelli_c1c2 ( const std::array< W, N > & p)
inlineconsteval

Definition at line 215 of file pcurves_util.h.

215 {
216 size_t c1 = 0;
217 auto c2 = p;
218
219 // This assumes p % 2 == 1
220 shift_right<1>(c2);
221 c1++;
222
223 for(;;) {
224 // If we found another one bit past the first, stop
225 // Conditional ok: this function is consteval
226 if(c2[0] % 2 == 1) {
227 break;
228 }
229 shift_right<1>(c2);
230 c1++;
231 }
232
233 std::reverse(c2.begin(), c2.end());
234 return {c1, c2};
235}

References shift_right().

Referenced by Botan::IntMod< MontgomeryRep< ScalarParams > >::sqrt().

◆ shanks_tonelli_c3()

template<WordType W, size_t N>
std::array< W, N > Botan::shanks_tonelli_c3 ( const std::array< W, N > & c2)
inlineconsteval

Definition at line 238 of file pcurves_util.h.

238 {
239 auto c3 = c2;
240 std::reverse(c3.begin(), c3.end());
241 shift_right<1>(c3);
242 std::reverse(c3.begin(), c3.end());
243 return c3;
244}

References shift_right().

Referenced by Botan::IntMod< MontgomeryRep< ScalarParams > >::sqrt().

◆ shanks_tonelli_c4()

template<typename Z, WordType W, size_t N>
auto Botan::shanks_tonelli_c4 ( const std::array< W, N > & p_minus_1_over_2) -> Z
consteval

Definition at line 247 of file pcurves_util.h.

247 {
248 const auto one = Z::one();
249
250 // This is a silly performance hack; the first non-quadratic root in P-224
251 // is 11 so if we start the search there we save a little time.
252 auto z = Z::constant(11);
253
254 for(;;) {
255 const auto c = z.pow_vartime(p_minus_1_over_2);
256
257 const auto is_square = c.is_zero() || c.is_one();
258
259 // Conditional ok: this function is consteval
260 if(!is_square.as_bool()) {
261 return z;
262 }
263
264 z = z + one;
265 }
266}
consteval std::array< W, N > p_minus_1_over_2(const std::array< W, N > &p)

References p_minus_1_over_2().

Referenced by Botan::IntMod< MontgomeryRep< ScalarParams > >::sqrt().

◆ shift_left()

template<size_t S, WordType W, size_t N>
W Botan::shift_left ( std::array< W, N > & x)
inlineconstexpr

Definition at line 888 of file mp_core.h.

888 {
889 static_assert(N >= 1, "Invalid input size");
890 static_assert(S > 0, "Zero shift not supported");
891 static_assert(S < WordInfo<W>::bits, "Shift too large");
892
893 const W carry = x[N - 1] >> (WordInfo<W>::bits - S);
894
895 for(size_t i = N - 1; i != 0; --i) {
896 x[i] = (x[i] << S) | (x[i - 1] >> (WordInfo<W>::bits - S));
897 }
898 x[0] <<= S;
899
900 return carry;
901}

Referenced by bytes_to_words(), hex_to_words(), Botan::IntMod< MontgomeryRep< ScalarParams > >::mul2(), and reduce_mod().

◆ shift_right()

template<size_t S, WordType W, size_t N>
W Botan::shift_right ( std::array< W, N > & x)
inlineconstexpr

Definition at line 904 of file mp_core.h.

904 {
905 static_assert(N >= 1, "Invalid input size");
906 static_assert(S > 0, "Zero shift not supported");
907 static_assert(S < WordInfo<W>::bits, "Shift too large");
908
909 const W carry = x[0] << (WordInfo<W>::bits - S);
910
911 for(size_t i = 0; i != N - 1; ++i) {
912 x[i] = (x[i] >> S) | (x[i + 1] << (WordInfo<W>::bits - S));
913 }
914 x[N - 1] >>= S;
915
916 return carry;
917}

Referenced by Botan::IntMod< MontgomeryRep< ScalarParams > >::_invert_vartime_div2_helper(), Botan::IntMod< MontgomeryRep< ScalarParams > >::div2(), p_div_2_plus_1(), p_minus_1_over_2(), p_plus_1_over_4(), shanks_tonelli_c1c2(), shanks_tonelli_c3(), and Botan::BLS12_381::FieldElement2::sqrt().

◆ shl() [1/3]

template<size_t S>
SIMD_16x32 BOTAN_FN_ISA_AVX512 Botan::shl ( SIMD_16x32 input)
inline

Definition at line 352 of file simd_avx512.h.

352 {
353 return input.shl<S>();
354}
BOTAN_FN_ISA_AVX512 SIMD_16x32 shl() const

References Botan::SIMD_16x32::shl().

◆ shl() [2/3]

template<size_t S>
SIMD_4x32 Botan::shl ( SIMD_4x32 input)
inline

Definition at line 1004 of file simd_4x32.h.

1004 {
1005 return input.shl<S>();
1006}

References Botan::SIMD_4x32::shl().

◆ shl() [3/3]

template<size_t S>
SIMD_8x32 BOTAN_FN_ISA_SIMD_8X32 Botan::shl ( SIMD_8x32 input)
inline

Definition at line 421 of file simd_8x32.h.

421 {
422 return input.shl<S>();
423}
BOTAN_FN_ISA_SIMD_8X32 SIMD_8x32 shl() const noexcept
Definition simd_8x32.h:227

References Botan::SIMD_8x32::shl().

◆ short_version_cstr()

const char * Botan::short_version_cstr ( )

Same as version_short_string except returning a pointer to the string.

Definition at line 16 of file version.cpp.

16 {
17 return BOTAN_SHORT_VERSION_STRING;
18}

Referenced by runtime_version_check(), and short_version_string().

◆ short_version_string()

std::string Botan::short_version_string ( )

Return a version string of the form "MAJOR.MINOR.PATCH" where each of the values is an integer.

Definition at line 28 of file version.cpp.

28 {
29 return std::string(short_version_cstr());
30}

References short_version_cstr().

◆ sigma()

template<size_t R1, size_t R2, size_t S, std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr T Botan::sigma ( T x)
constexpr

SHA-2 Sigma style function

Definition at line 45 of file rotate.h.

45 {
46 return rotr<R1>(x) ^ rotr<R2>(x) ^ (x >> S);
47}

References BOTAN_FORCE_INLINE, and rotr().

Referenced by Botan::Kyber_Algos::expand_keypair(), SHA2_32_F(), and SHA2_64_F().

◆ sign_message()

std::array< uint8_t, 114 > Botan::sign_message ( std::span< const uint8_t, ED448_LEN > sk,
std::span< const uint8_t, ED448_LEN > pk,
bool f,
std::span< const uint8_t > context,
std::span< const uint8_t > msg )

Sign a message using a keypair (RFC 8032 5.2.6).

Parameters
skthe secret key
pkthe public key
fthe prehash flag (true iff using Ed448ph)
contextthe context string
msgthe message to sign
Returns
the signature

Definition at line 387 of file ed448_internal.cpp.

391 {
392 // 5.2.6. Signature Generation
393 // The inputs to the signing procedure is the private key, a 57-octet
394 // string, a flag F, which is 0 for Ed448, 1 for Ed448ph, context C of
395 // at most 255 octets, and a message M of arbitrary size.
396 // 1. Hash the private key, 57 octets, using SHAKE256(x, 114). Let h
397 // denote the resulting digest. Construct the secret scalar s from
398 // the first half of the digest, and the corresponding public key A,
399 // as described in the previous section. Let prefix denote the
400 // second half of the hash digest, h[57],...,h[113].
401 auto shake_xof = XOF::create_or_throw("SHAKE-256");
402 shake_xof->update(sk);
403 const Scalar448 s = scalar_from_xof(*shake_xof);
404 std::array<uint8_t, ED448_LEN> prefix{};
405 shake_xof->output(prefix);
406 // 2. Compute SHAKE256(dom4(F, C) || prefix || PH(M), 114), where M is
407 // the message to be signed, F is 1 for Ed448ph, 0 for Ed448, and C
408 // is the context to use. Interpret the 114-octet digest as a
409 // little-endian integer r.
410 const Scalar448 r(shake(pgflag, context, prefix, msg));
411 // 3. Compute the point [r]B. For efficiency, do this by first
412 // reducing r modulo L, the group order of B. Let the string R be
413 // the encoding of this point.
414 const auto big_r = Ed448Point::base_point_mul(r).encode();
415 // 4. Compute SHAKE256(dom4(F, C) || R || A || PH(M), 114), and
416 // interpret the 114-octet digest as a little-endian integer k.
417 const Scalar448 k(shake(pgflag, context, big_r, pk, msg));
418 // 5. Compute S = (r + k * s) mod L. For efficiency, again reduce k
419 // modulo L first.
420 const auto big_s = r + k * s; //r_plus_ks_mod_L(r, k, s);
421 // 6. Form the signature of the concatenation of R (57 octets) and the
422 // little-endian encoding of S (57 octets; the ten most significant
423 // bits of the final octets are always zero).
424 std::array<uint8_t, 2 * ED448_LEN> sig{};
425 BufferStuffer stuf(sig);
426 stuf.append(big_r);
427 stuf.append(big_s.to_bytes<ED448_LEN>());
428 BOTAN_ASSERT(stuf.full(), "Buffer is full");
429
430 return sig;
431}
constexpr size_t ED448_LEN

References Botan::BufferStuffer::append(), Botan::Ed448Point::base_point_mul(), BOTAN_ASSERT, Botan::XOF::create_or_throw(), ED448_LEN, Botan::Ed448Point::encode(), and Botan::BufferStuffer::full().

◆ significant_bytes()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr size_t Botan::significant_bytes ( T n)
constexpr

Return the number of significant bytes in n

Parameters
nan integer value
Returns
number of significant bytes in n

Definition at line 94 of file bit_ops.h.

94 {
95 size_t b = 0;
96
97 for(size_t s = 8 * sizeof(T) / 2; s >= 8; s /= 2) {
98 // Equivalent to: ((n >> s) == 0) ? 0 : s;
99 const size_t z = s - ct_if_is_zero_ret<T>(n >> s, s);
100 b += z / 8;
101 n >>= z;
102 }
103
104 b += (n != 0);
105
106 return b;
107}

References BOTAN_FORCE_INLINE, and ct_if_is_zero_ret().

◆ sm2_compute_za()

std::vector< uint8_t > Botan::sm2_compute_za ( HashFunction & hash,
std::string_view user_id,
const EC_Group & group,
const EC_AffinePoint & pubkey )

Definition at line 161 of file sm2.cpp.

164 {
165 return sm2_compute_za(hash, as_span_of_bytes(user_id), group, pubkey);
166}
std::vector< uint8_t > sm2_compute_za(HashFunction &hash, std::string_view user_id, const EC_Group &group, const EC_AffinePoint &pubkey)
Definition sm2.cpp:161

References as_span_of_bytes(), and sm2_compute_za().

Referenced by botan_pubkey_sm2_compute_za(), and sm2_compute_za().

◆ SM3_E()

uint32_t Botan::SM3_E ( uint32_t W0,
uint32_t W7,
uint32_t W13,
uint32_t W3,
uint32_t W10 )
inline

Definition at line 69 of file sm3_fn.h.

69 {
70 return P1(W0 ^ W7 ^ rotl<15>(W13)) ^ rotl<7>(W3) ^ W10;
71}
uint32_t P1(uint32_t X)
Definition sm3_fn.h:65

References P1(), and rotl().

Referenced by Botan::SM3::compress_n().

◆ solinas_correct_redc()

template<size_t N, WordType W>
void Botan::solinas_correct_redc ( std::array< W, N > & r,
const std::array< W, N > & P,
const std::array< W, N > & C )
inlineconstexpr

Set r to r - C. Then if r < 0, add P to r

Definition at line 84 of file pcurves_solinas.h.

84 {
85 W borrow = 0;
86 for(size_t i = 0; i != N; ++i) {
87 r[i] = word_sub(r[i], C[i], &borrow);
88 }
89
90 // borrow is either 0 or 1, perfect for setting up a mask without extra work
91 const W mask = CT::value_barrier<W>(0 - borrow);
92
93 W carry = 0;
94
95 for(size_t i = 0; i != N; ++i) {
96 r[i] = word_add(r[i], P[i] & mask, &carry);
97 }
98}

References Botan::CT::value_barrier(), word_add(), and word_sub().

◆ specialize_to()

template<typename SpecificVariantT, typename GeneralVariantT>
std::optional< SpecificVariantT > Botan::specialize_to ( GeneralVariantT && v)
constexpr

Converts a given variant into another variant whose type states are a subset of the given variant.

Returns
a variant of type SpecificVariantT if the given variant holds a type in SpecificVariantT, std::nullopt otherwise.

Definition at line 117 of file stl_util.h.

117 {
118 return std::visit(
119 // NOLINTNEXTLINE(*-missing-std-forward)
120 []<typename AlternativeT>(AlternativeT&& obj) -> std::optional<SpecificVariantT> {
121 if constexpr(std::is_constructible_v<SpecificVariantT, AlternativeT>) {
122 return std::forward<AlternativeT>(obj);
123 } else {
124 return std::nullopt;
125 }
126 },
127 std::forward<GeneralVariantT>(v));
128}

◆ split_on()

BOTAN_TEST_API std::vector< std::string > Botan::split_on ( std::string_view str,
char delim )

Split a string

Parameters
strthe input string
delimthe delimiter
Returns
string split by delim

Definition at line 83 of file parsing.cpp.

83 {
84 std::vector<std::string> elems;
85 if(str.empty()) {
86 return elems;
87 }
88
89 std::string substr;
90 for(const char c : str) {
91 if(c == delim) {
92 if(!substr.empty()) {
93 elems.push_back(substr);
94 }
95 substr.clear();
96 } else {
97 substr += c;
98 }
99 }
100
101 if(substr.empty()) {
102 throw Invalid_Argument(fmt("Unable to split string '{}", str));
103 }
104 elems.push_back(substr);
105
106 return elems;
107}

References fmt().

Referenced by argon2_check_pwhash(), Botan::PKCS11::MechanismWrapper::create_ecdh_mechanism(), create_private_key(), Botan::TLS::Text_Policy::get_list(), load_private_key(), load_public_key(), pbes2_decrypt(), Botan::TLS::Text_Policy::read_cert_type_list(), Botan::TLS::Text_Policy::read_group_list(), read_kv(), Botan::TLS::Text_Policy::read_sig_scheme_list(), Botan::PK_Ops::Verification_with_Hash::Verification_with_Hash(), and Botan::X509_Cert_Options::X509_Cert_Options().

◆ sqrt_field_element()

template<typename C>
CT::Option< typename C::FieldElement > Botan::sqrt_field_element ( const typename C::FieldElement & fe)
inlineconstexpr

Field square root

Uses the specialized fe_sqrt if available, or otherwise the standard square root

Definition at line 61 of file pcurves_algos.h.

61 {
62 if constexpr(curve_supports_fe_sqrt<C>) {
63 auto z = C::fe_sqrt(fe);
64 // Zero out the return value if it would otherwise be incorrect
65 const CT::Choice correct = (z.square() == fe);
66 z.conditional_assign(!correct, C::FieldElement::zero());
67 return CT::Option(z, correct);
68 } else {
69 return fe.sqrt();
70 }
71}

Referenced by Botan::PCurve::PrimeOrderCurveImpl< C >::deserialize_point_compressed(), and map_to_curve_sswu().

◆ sqrt_modulo_prime()

BigInt Botan::sqrt_modulo_prime ( const BigInt & x,
const BigInt & p )

Compute the square root of x modulo a prime using the Tonelli-Shanks algorithm. This algorithm is primarily used for EC point decompression which takes only public inputs, as a consequence it is not written to be constant-time and may leak side-channel information about its arguments.

Parameters
xthe input
pthe prime modulus
Returns
y such that (y*y)p == x, or -1 if no such integer

Definition at line 27 of file numthry.cpp.

27 {
28 BOTAN_ARG_CHECK(p > 1, "invalid prime");
29 BOTAN_ARG_CHECK(a < p, "value to solve for must be less than p");
30 BOTAN_ARG_CHECK(a >= 0, "value to solve for must not be negative");
31
32 // some very easy cases
33 if(p == 2 || a <= 1) {
34 return a;
35 }
36
37 BOTAN_ARG_CHECK(p.is_odd(), "invalid prime");
38
39 if(jacobi(a, p) != 1) { // not a quadratic residue
40 return BigInt::from_s32(-1);
41 }
42
43 const auto mod_p = Barrett_Reduction::for_public_modulus(p);
44 const Montgomery_Params monty_p(p, mod_p);
45
46 // If p == 3 (mod 4) there is a simple solution
47 if(p % 4 == 3) {
48 return monty_exp_vartime(monty_p, a, ((p + 1) >> 2)).value();
49 }
50
51 // Otherwise we have to use Shanks-Tonelli
52 size_t s = low_zero_bits(p - 1);
53 BigInt q = p >> s;
54
55 q -= 1;
56 q >>= 1;
57
58 BigInt r = monty_exp_vartime(monty_p, a, q).value();
59 BigInt n = mod_p.multiply(a, mod_p.square(r));
60 r = mod_p.multiply(r, a);
61
62 if(n == 1) {
63 return r;
64 }
65
66 // find random quadratic nonresidue z
67 word z = 2;
68 for(;;) {
69 if(jacobi(BigInt::from_word(z), p) == -1) { // found one
70 break;
71 }
72
73 z += 1; // try next z
74
75 /*
76 * The expected number of tests to find a non-residue modulo a
77 * prime is 2. If we have not found one after 256 then almost
78 * certainly we have been given a non-prime p.
79 */
80 if(z >= 256) {
81 return BigInt::from_s32(-1);
82 }
83 }
84
85 BigInt c = monty_exp_vartime(monty_p, BigInt::from_word(z), (q << 1) + 1).value();
86
87 while(n > 1) {
88 q = n;
89
90 size_t i = 0;
91 while(q != 1) {
92 q = mod_p.square(q);
93 ++i;
94
95 if(i >= s) {
96 return BigInt::from_s32(-1);
97 }
98 }
99
100 BOTAN_ASSERT_NOMSG(s >= (i + 1)); // No underflow!
101 c = monty_exp_vartime(monty_p, c, BigInt::power_of_2(s - i - 1)).value();
102 r = mod_p.multiply(r, c);
103 c = mod_p.square(c);
104 n = mod_p.multiply(n, c);
105
106 // s decreases as the algorithm proceeds
107 BOTAN_ASSERT_NOMSG(s >= i);
108 s = i;
109 }
110
111 return r;
112}
static Barrett_Reduction for_public_modulus(const BigInt &m)
Definition barrett.cpp:33
static BigInt from_s32(int32_t n)
Definition bigint.cpp:43
BigInt & square(secure_vector< word > &ws)
Definition big_ops2.cpp:192
int32_t jacobi(BigInt a, BigInt n)
Definition numthry.cpp:119
Montgomery_Int monty_exp_vartime(const Montgomery_Params &params_p, const BigInt &g, const BigInt &k)
Definition monty_exp.h:78

References BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, Botan::Barrett_Reduction::for_public_modulus(), Botan::BigInt::from_s32(), Botan::BigInt::from_word(), Botan::BigInt::is_odd(), jacobi(), low_zero_bits(), monty_exp_vartime(), Botan::BigInt::power_of_2(), Botan::BigInt::square(), and Botan::Montgomery_Int::value().

◆ square() [1/2]

BigInt Botan::square ( const BigInt & x)

Square an integer

Parameters
xan integer
Returns
(x*x)

Definition at line 184 of file numthry.cpp.

184 {
185 BigInt z = x;
187 z.square(ws);
188 return z;
189}

References Botan::BigInt::square().

Referenced by Botan::Ed448Point::decode(), Botan::Ed448Point::double_point(), Botan::Ed448Point::operator+(), Botan::PCurve::GenericPrimeOrderCurve::scalar_square(), Botan::PCurve::PrimeOrderCurveImpl< C >::scalar_square(), and x448().

◆ square() [2/2]

Gf448Elem Botan::square ( const Gf448Elem & elem)

Computes elem^2. Faster than operator*.

Definition at line 445 of file curve448_gf.cpp.

445 {
446 Gf448Elem res(0);
447 gf_square(res.words(), elem.words());
448 return res;
449}

References Botan::Gf448Elem::words().

◆ squeeze_from_sponge() [1/2]

void Botan::squeeze_from_sponge ( detail::SpongeLikeWithTrivialPermute auto & sponge,
std::span< uint8_t > output )
inline

Definition at line 257 of file sponge_processing.h.

257 {
258 squeeze_from_sponge(sponge, output, [&sponge] { sponge.permute(); });
259}
void squeeze_from_sponge(SpongeT &sponge, std::span< uint8_t > output, const detail::PermutationFn auto &permutation_fn)

References squeeze_from_sponge().

◆ squeeze_from_sponge() [2/2]

template<detail::SpongeLike SpongeT>
void Botan::squeeze_from_sponge ( SpongeT & sponge,
std::span< uint8_t > output,
const detail::PermutationFn auto & permutation_fn )
inline

Squeezes output data from the sponge state.

Parameters
Sponge HelperThe sponge state to squeeze data from.
outputThe output buffer to write the squeezed data into.
permutation_fnThe function to call for the sponge's permutation.

Definition at line 244 of file sponge_processing.h.

246 {
247 using word_t = typename SpongeT::word_t;
248
249 BufferStuffer output_stuffer(output);
250 process_bytes_in_sponge(sponge, output.size(), permutation_fn, [&](word_t state_word, auto bounds) {
251 bounds.write_into(output_stuffer, state_word);
252 return state_word;
253 });
254 BOTAN_ASSERT_NOMSG(output_stuffer.full());
255}

References BOTAN_ASSERT_NOMSG, Botan::BufferStuffer::full(), and process_bytes_in_sponge().

Referenced by Botan::Ascon_p::squeeze(), Botan::Keccak_Permutation::squeeze(), and squeeze_from_sponge().

◆ srp6_client_agree() [1/2]

std::pair< BigInt, SymmetricKey > Botan::srp6_client_agree ( std::string_view username,
std::string_view password,
const DL_Group & group,
std::string_view hash_id,
const std::vector< uint8_t > & salt,
const BigInt & B,
size_t a_bits,
RandomNumberGenerator & rng )

SRP6a Client side

Parameters
usernamethe username we are attempting login for
passwordthe password we are attempting to use
groupspecifies the shared SRP group
Hash Function Identificationspecifies a secure hash function
saltis the salt value sent by the server
Bis the server's public value
a_bitssize of secret exponent in bits
Random Number Generatorsis a random number generator
Returns
(A,K) the client public key and the shared secret key

Definition at line 81 of file srp6.cpp.

88 {
89 BOTAN_ARG_CHECK(a_bits <= group.p_bits(), "Invalid a_bits");
90
91 const BigInt& g = group.get_g();
92 const BigInt& p = group.get_p();
93
94 const size_t p_bytes = group.p_bytes();
95
96 if(B <= 0 || B >= p) {
97 throw Decoding_Error("Invalid SRP parameter from server");
98 }
99
100 auto hash_fn = HashFunction::create_or_throw(hash_id);
101 if(8 * hash_fn->output_length() >= group.p_bits()) {
102 throw Invalid_Argument(fmt("Hash function {} too large for SRP6 with this group", hash_fn->name()));
103 }
104
105 const BigInt k = hash_seq(*hash_fn, p_bytes, p, g);
106
107 const BigInt a(rng, a_bits);
108 CT::poison(a);
109
110 const BigInt A = group.power_g_p(a, a_bits);
111 CT::unpoison(A);
112
113 const BigInt u = hash_seq(*hash_fn, p_bytes, A, B);
114 BOTAN_ASSERT_NOMSG(!u.is_zero());
115
116 const BigInt x = compute_x(*hash_fn, identifier, password, salt);
117 CT::poison(x);
118
119 const BigInt g_x_p = group.power_g_p(x, hash_fn->output_length() * 8);
120
121 const BigInt B_k_g_x_p = group.mod_p(B + group.mod_p(p - group.multiply_mod_p(k, g_x_p)));
122
123 // a + u*x, with lengths that depend only on the sizes of the inputs, not on their values
124 secure_vector<word> a_ux_words(std::max(a.size(), u.size() + x.size()) + 1);
126 a_ux_words.data(), a_ux_words.size(), u._data(), u.size(), u.size(), x._data(), x.size(), x.size(), nullptr, 0);
127 const word carry = bigint_add2(a_ux_words.data(), a_ux_words.size(), a._data(), a.size());
129 const BigInt a_ux = BigInt::_from_words(a_ux_words);
130
131 // a < 2^a_bits and u*x < 2^(2H) where H is the hash output bits, so
132 // a + u*x < 2^(max(a_bits, 2H) + 1).
133 const size_t max_aux_bits = std::max<size_t>(a_bits, 2 * 8 * hash_fn->output_length()) + 1;
134 BOTAN_ASSERT_NOMSG(max_aux_bits >= a_ux.bits());
135
136 const BigInt S = group.power_b_p(B_k_g_x_p, a_ux, max_aux_bits);
137
138 // Any further secret handling of the output is up to the caller
139 CT::unpoison_all(a, x, S);
140
141 const SymmetricKey Sk(S.serialize<secure_vector<uint8_t>>(p_bytes));
142
143 return std::make_pair(A, Sk);
144}
BigInt power_g_p(const BigInt &x) const
Definition dl_group.h:266
BigInt mod_p(const BigInt &x) const
Definition dl_group.cpp:580
BigInt multiply_mod_p(const BigInt &x, const BigInt &y) const
Definition dl_group.cpp:584
size_t p_bits() const
Definition dl_group.cpp:549
const BigInt & get_p() const
Definition dl_group.cpp:523
size_t p_bytes() const
Definition dl_group.cpp:553
BigInt power_b_p(const BigInt &b, const BigInt &x, size_t max_x_bits) const
Definition dl_group.cpp:632
const BigInt & get_g() const
Definition dl_group.cpp:530
OctetString SymmetricKey
Definition symkey.h:153

References Botan::BigInt::_data(), Botan::BigInt::_from_words(), bigint_add2(), bigint_mul(), Botan::BigInt::bits(), BOTAN_ARG_CHECK, BOTAN_ASSERT_NOMSG, Botan::HashFunction::create_or_throw(), Botan::CT::driveby_unpoison(), fmt(), Botan::DL_Group::get_g(), Botan::DL_Group::get_p(), Botan::BigInt::is_zero(), Botan::DL_Group::mod_p(), Botan::DL_Group::multiply_mod_p(), Botan::DL_Group::p_bits(), Botan::DL_Group::p_bytes(), Botan::CT::poison(), Botan::DL_Group::power_b_p(), Botan::DL_Group::power_g_p(), Botan::BigInt::serialize(), Botan::BigInt::size(), Botan::CT::unpoison(), and Botan::CT::unpoison_all().

◆ srp6_client_agree() [2/2]

std::pair< BigInt, SymmetricKey > Botan::srp6_client_agree ( std::string_view username,
std::string_view password,
std::string_view group_id,
std::string_view hash_id,
const std::vector< uint8_t > & salt,
const BigInt & B,
RandomNumberGenerator & rng )

SRP6a Client side

Parameters
usernamethe username we are attempting login for
passwordthe password we are attempting to use
group_idspecifies the shared SRP group
Hash Function Identificationspecifies a secure hash function
saltis the salt value sent by the server
Bis the server's public value
Random Number Generatorsis a random number generator
Returns
(A,K) the client public key and the shared secret key

Definition at line 68 of file srp6.cpp.

74 {
75 const auto group = DL_Group::from_name(group_id);
76 const size_t a_bits = group.exponent_bits();
77
78 return srp6_client_agree(identifier, password, group, hash_id, salt, B, a_bits, rng);
79}
std::pair< BigInt, SymmetricKey > srp6_client_agree(std::string_view identifier, std::string_view password, std::string_view group_id, std::string_view hash_id, const std::vector< uint8_t > &salt, const BigInt &B, RandomNumberGenerator &rng)
Definition srp6.cpp:68

References Botan::DL_Group::from_name(), and srp6_client_agree().

Referenced by botan_srp6_client_agree(), and srp6_client_agree().

◆ srp6_generate_verifier() [1/2]

BigInt Botan::srp6_generate_verifier ( std::string_view identifier,
std::string_view password,
const std::vector< uint8_t > & salt,
const DL_Group & group,
std::string_view hash_id )

Generate a new SRP-6 verifier

Parameters
identifiera username or other client identifier
passwordthe secret used to authenticate user
salta randomly chosen value, at least 128 bits long
groupspecifies the shared SRP group
Hash Function Identificationspecifies a secure hash function

Definition at line 155 of file srp6.cpp.

159 {
160 auto hash_fn = HashFunction::create_or_throw(hash_id);
161 if(8 * hash_fn->output_length() >= group.p_bits()) {
162 throw Invalid_Argument(fmt("Hash function {} too large for SRP6 with this group", hash_fn->name()));
163 }
164
165 const BigInt x = compute_x(*hash_fn, identifier, password, salt);
166 const auto scope = CT::scoped_poison(x);
167 return CT::driveby_unpoison(group.power_g_p(x, hash_fn->output_length() * 8));
168}

References Botan::HashFunction::create_or_throw(), Botan::CT::driveby_unpoison(), fmt(), Botan::DL_Group::p_bits(), Botan::DL_Group::power_g_p(), and Botan::CT::scoped_poison().

◆ srp6_generate_verifier() [2/2]

BigInt Botan::srp6_generate_verifier ( std::string_view identifier,
std::string_view password,
const std::vector< uint8_t > & salt,
std::string_view group_id,
std::string_view hash_id )

Generate a new SRP-6 verifier

Parameters
identifiera username or other client identifier
passwordthe secret used to authenticate user
salta randomly chosen value, at least 128 bits long
group_idspecifies the shared SRP group
Hash Function Identificationspecifies a secure hash function

Definition at line 146 of file srp6.cpp.

150 {
151 const auto group = DL_Group::from_name(group_id);
152 return srp6_generate_verifier(identifier, password, salt, group, hash_id);
153}
BigInt srp6_generate_verifier(std::string_view identifier, std::string_view password, const std::vector< uint8_t > &salt, std::string_view group_id, std::string_view hash_id)
Definition srp6.cpp:146

References Botan::DL_Group::from_name(), and srp6_generate_verifier().

Referenced by botan_srp6_generate_verifier(), and srp6_generate_verifier().

◆ srp6_group_identifier()

std::string Botan::srp6_group_identifier ( const BigInt & N,
const BigInt & g )

Return the group id for this SRP param set, or else thrown an exception

Parameters
Nthe group modulus
gthe group generator
Returns
group identifier

Definition at line 49 of file srp6.cpp.

49 {
50 /*
51 This function assumes that only one 'standard' SRP parameter set has
52 been defined for a particular bitsize. As of this writing that is the case.
53 */
54 try {
55 const std::string group_name = "modp/srp/" + std::to_string(N.bits());
56
57 const auto group = DL_Group::from_name(group_name);
58
59 if(group.get_p() == N && group.get_g() == g) {
60 return group_name;
61 }
62 } catch(...) {}
63
64 // If we didn't return, the group was unknown or did not match
65 throw Invalid_Argument("Invalid or unknown SRP group parameters");
66}

References Botan::BigInt::bits(), and Botan::DL_Group::from_name().

◆ SSWU_C1()

template<typename C>
requires C::ValidForSswuHash
const auto & Botan::SSWU_C1 ( )

SSWU constant C1 - (-B / A)

See RFC 9380 section 6.6.2

Definition at line 1859 of file pcurves_impl.h.

1861{
1862 // TODO(Botan4) Make this a constexpr
1863 // We derive it from C2 to avoid a second inversion
1864 static const typename C::FieldElement C1 = (SSWU_C2<C>() * C::SSWU_Z).negate();
1865 return C1;
1866}

References SSWU_C2().

Referenced by map_to_curve_sswu().

◆ SSWU_C2()

template<typename C>
requires C::ValidForSswuHash
const auto & Botan::SSWU_C2 ( )

SSWU constant C2 - (B / (Z * A))

See RFC 9380 section 6.6.2

Definition at line 1845 of file pcurves_impl.h.

1847{
1848 // TODO(Botan4) Make this a constexpr once compilers have caught up
1849 static const typename C::FieldElement C2 = C::B * invert_field_element<C>(C::SSWU_Z * C::A);
1850 return C2;
1851}

References invert_field_element().

Referenced by map_to_curve_sswu(), and SSWU_C1().

◆ store_be()

template<typename ModifierT = detail::AutoDetect, typename... ParamTs>
auto Botan::store_be ( ParamTs &&... params)
inlineconstexpr

Store "something" in big endian byte order See the documentation of this file for more details.

Definition at line 745 of file loadstor.h.

745 {
746 return detail::store_any<std::endian::big, ModifierT>(std::forward<ParamTs>(params)...);
747}
constexpr void store_any(WrappedInT wrapped_in, OutR &&out_range)
Definition loadstor.h:525

References Botan::detail::store_any().

Referenced by Botan::TLS::Connection_Cipher_State::aead_nonce(), Botan::TLS::Connection_Cipher_State::aead_nonce(), base58_check_encode(), base58_decode(), Botan::MDx_MB_Engine< W >::batch_hash(), Botan::BigInt::binary_encode(), Botan::BlindedScalarBits< C, WindowBits+1 >::BlindedScalarBits(), Botan::FPE_FE1::decrypt(), Botan::Blowfish::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::Noekeon::decrypt_n(), Botan::SEED::decrypt_n(), Botan::SHACAL2::decrypt_n(), Botan::TLS::PSKImporter::derive_imported_psk(), Botan::CryptoBox::encrypt(), Botan::FPE_FE1::encrypt(), Botan::TLS::Session::encrypt(), Botan::Blowfish::encrypt_n(), Botan::CAST_128::encrypt_n(), Botan::Noekeon::encrypt_n(), Botan::SEED::encrypt_n(), Botan::SHACAL2::encrypt_n(), Botan::TLS::Connection_Cipher_State::format_ad(), Botan::IPv4Subnet::from_address_and_mask(), hkdf_expand_label(), Botan::TLS::Cipher_State::hkdf_expand_label(), Botan::ML_KEM_Symmetric_Primitives::init_PRF(), Botan::ML_KEM_Symmetric_Primitives::init_XOF(), Botan::TLS::Channel_Impl_12::key_material_export(), Botan::HPKE::labeled_expand(), lmots_compute_pubkey_from_sig(), lmots_compute_pubkeys(), Botan::LMOTS_Public_Key::LMOTS_Public_Key(), Botan::TLS::make_hello_random(), Botan::TLS::make_server_hello_random(), Botan::TPM2::Context::manufacturer(), Botan::TLS::Cipher_State::next_ticket_nonce(), nist_key_wrap(), nist_key_wrap_padded(), Botan::TLS::TLS_Handshake_Layer::prepare_header(), Botan::CTR_BE::seek(), Botan::IPv4Subnet::serialize(), Botan::TLS::New_Session_Ticket_12::serialize(), Botan::TLS::New_Session_Ticket_13::serialize(), Botan::TLS::Record_TLS::serialize_header(), Botan::BLS12_381::FieldElement::serialize_to(), Botan::BLS12_381::Scalar::serialize_to(), Botan::IntMod< MontgomeryRep< ScalarParams > >::serialize_to(), Botan::PseudorandomKeyGeneration::set_i(), Botan::PseudorandomKeyGeneration::set_j(), Botan::PseudorandomKeyGeneration::set_q(), Botan::HSS_LMS_PrivateKeyInternal::sign(), Botan::LMOTS_Private_Key::sign(), Botan::LMS_PrivateKey::sign_and_get_pk(), Botan::HSS_LMS_PrivateKeyInternal::to_bytes(), Botan::HSS_LMS_PublicKeyInternal::to_bytes(), Botan::IPv4Address::to_bytes(), Botan::LMS_PublicKey::to_bytes(), Botan::Sphincs_Address::to_bytes(), Botan::Sphincs_Address::to_bytes_compressed(), Botan::Buffered_Computation::update_be(), Botan::Buffered_Computation::update_be(), Botan::Buffered_Computation::update_be(), and Botan::TPM2::Context::vendor().

◆ store_block()

template<bool BSWAP>
BOTAN_FORCE_INLINE BOTAN_FN_ISA_SIMD_4X32 void Botan::store_block ( const SIMD_4x32 & b,
uint8_t out[] )

Definition at line 96 of file polyval_fn.h.

96 {
97 if constexpr(BSWAP) {
99 } else {
100 b.store_le(out);
101 }
102}

References BOTAN_FORCE_INLINE, Botan::SIMD_4x32::reverse_all_bytes(), and Botan::SIMD_4x32::store_le().

◆ store_le()

template<typename ModifierT = detail::AutoDetect, typename... ParamTs>
auto Botan::store_le ( ParamTs &&... params)
inlineconstexpr

Store "something" in little endian byte order See the documentation of this file for more details.

Definition at line 736 of file loadstor.h.

736 {
737 return detail::store_any<std::endian::little, ModifierT>(std::forward<ParamTs>(params)...);
738}

References Botan::detail::store_any().

Referenced by base58_decode(), Botan::Ascon_AEAD128_Mode::calculate_tag_and_finish(), Botan::GCM_SIV_Mode::compute_tag(), create_aes_row_generator(), create_shake_row_generator(), Botan::Sodium::crypto_core_hsalsa20(), Botan::GCM_SIV_Mode::ctr_xor(), Botan::GOST_28147_89::decrypt_n(), Botan::Kuznyechik::decrypt_n(), Botan::Serpent::decrypt_n(), Botan::Threefish_512::decrypt_n(), Botan::Twofish::decrypt_n(), Botan::X25519_FE::encode(), Botan::GOST_28147_89::encrypt_n(), Botan::Kuznyechik::encrypt_n(), Botan::Serpent::encrypt_n(), Botan::Threefish_512::encrypt_n(), Botan::Twofish::encrypt_n(), Botan::Streebog::final_result(), generate_mceliece_key(), Botan::MDx_MB_Engine< W >::MDx_MB_Engine(), Botan::CRYSTALS::pack(), Botan::Salsa20::salsa_core(), Botan::Classic_McEliece_Minimal_Polynomial::serialize(), Botan::FrodoMatrix::serialize(), Botan::Ed25519_FieldElement::serialize_to(), Botan::Ed25519_Scalar::serialize_to(), Botan::Sodium::sodium_malloc(), Botan::bitvector_base< secure_allocator >::subvector_replace(), Botan::Gf448Elem::to_bytes(), Botan::Scalar448::to_bytes(), Botan::Buffered_Computation::update_le(), Botan::Buffered_Computation::update_le(), Botan::Buffered_Computation::update_le(), Botan::ChaCha20Poly1305_Mode::update_len(), Botan::detail::FullWordBounds< SpongeT >::write_into(), and Botan::detail::PartialWordBounds< SpongeT >::write_into().

◆ string_join()

std::string Botan::string_join ( const std::vector< std::string > & strs,
char delim )

Join a string

Parameters
strsstrings to join
delimthe delimiter
Returns
string joined by delim

Definition at line 112 of file parsing.cpp.

112 {
113 std::ostringstream out;
114
115 for(size_t i = 0; i != strs.size(); ++i) {
116 if(i != 0) {
117 out << delim;
118 }
119 out << strs[i];
120 }
121
122 return out.str();
123}

Referenced by Botan::CPUID::to_string(), and Botan::Key_Constraints::to_string().

◆ swap_bits()

template<std::unsigned_integral T>
BOTAN_FORCE_INLINE constexpr void Botan::swap_bits ( T & x,
T & y,
T mask,
size_t shift )
constexpr

Definition at line 203 of file bit_ops.h.

203 {
204 const T swap = ((x >> shift) ^ y) & mask;
205 x ^= swap << shift;
206 y ^= swap;
207}

References BOTAN_FORCE_INLINE.

◆ swar_in_range()

template<std::unsigned_integral T>
T Botan::swar_in_range ( T v,
T lower,
T upper )
constexpr

SWAR (SIMD within a word) byte-by-byte comparison

This individually compares each byte of the provided words. It returns a mask which contains, for each byte, 0x80 if the byte in a was less than the byte in b. Otherwise the mask is 00.

This implementation assumes that the high bits of each byte in both lower and upper are clear! It is possible to support the full range of bytes, but this requires additional comparisons.

Definition at line 144 of file int_utils.h.

144 {
145 // The constant 0x808080... as a T
146 constexpr T hi1 = (static_cast<T>(-1) / 255) << 7;
147 // The constant 0x7F7F7F... as a T
148 constexpr T lo7 = ~hi1;
149
150 const T sub = ((v | hi1) - (lower & lo7)) ^ ((v ^ (~lower)) & hi1);
151 const T a_lo = sub & lo7;
152 const T a_hi = sub & hi1;
153 return (lo7 - a_lo + upper) & hi1 & ~a_hi;
154}

◆ swar_lt()

template<std::unsigned_integral T>
T Botan::swar_lt ( T a,
T b )
constexpr

SWAR (SIMD within a word) byte-by-byte comparison

This individually compares each byte of the provided words. It returns a mask which contains, for each byte, 0xFF if the byte in a was less than the byte in b. Otherwise the mask is 00.

This implementation assumes that the high bits of each byte in both a and b are clear! It is possible to support the full range of bytes, but this requires additional comparisons.

Definition at line 121 of file int_utils.h.

121 {
122 // The constant 0x808080... as a T
123 constexpr T hi1 = (static_cast<T>(-1) / 255) << 7;
124 // The constant 0x7F7F7F... as a T
125 constexpr T lo7 = static_cast<T>(~hi1);
126 T r = (lo7 - a + b) & hi1;
127 // Currently the mask is 80 if lt, otherwise 00. Convert to FF/00
128 return (r << 1) - (r >> 7);
129}

◆ syndrome_init()

std::vector< polyn_gf2m > Botan::syndrome_init ( const polyn_gf2m & generator,
const std::vector< gf2m > & support,
int n )

Definition at line 621 of file polyn_gf2m.cpp.

621 {
622 int i = 0;
623 int j = 0;
624 int t = 0;
625 gf2m a = 0;
626
627 const std::shared_ptr<GF2m_Field> m_sp_field = generator.get_sp_field();
628
629 std::vector<polyn_gf2m> result;
630 t = generator.get_degree();
631
632 //g(z)=g_t+g_(t-1).z^(t-1)+......+g_1.z+g_0
633 //f(z)=f_(t-1).z^(t-1)+......+f_1.z+f_0
634
635 for(j = 0; j < n; j++) {
636 result.push_back(polyn_gf2m(t - 1, m_sp_field));
637
638 (*&result[j]).set_coef(t - 1, 1);
639 for(i = t - 2; i >= 0; i--) {
640 (*&result[j]).set_coef(i, (generator)[i + 1] ^ m_sp_field->gf_mul(lex_to_gray(support[j]), result[j][i + 1]));
641 }
642 a = ((generator)[0] ^ m_sp_field->gf_mul(lex_to_gray(support[j]), result[j][0]));
643 for(i = 0; i < t; i++) {
644 (*&result[j]).set_coef(i, m_sp_field->gf_div(result[j][i], a));
645 }
646 }
647 return result;
648}
gf2m lex_to_gray(gf2m lex)

References Botan::polyn_gf2m::get_degree(), Botan::polyn_gf2m::get_sp_field(), and lex_to_gray().

Referenced by generate_mceliece_key().

◆ system_rng()

RandomNumberGenerator & Botan::system_rng ( )

Return a shared reference to a global PRNG instance provided by the operating system. For instance might be instantiated by /dev/urandom or CryptGenRandom.

Definition at line 384 of file system_rng.cpp.

384 {
385 static System_RNG_Impl g_system_rng;
386 return g_system_rng;
387}

Referenced by Botan::System_RNG::accepts_input(), Botan::AutoSeeded_RNG::AutoSeeded_RNG(), botan_pk_op_decrypt_create(), botan_pk_op_encrypt_create(), botan_pk_op_kem_decrypt_create(), botan_pk_op_key_agreement_create(), botan_pk_op_sign_create(), botan_rng_reseed(), botan_system_rng_get(), Botan::System_RNG::clear(), Botan::System_RNG::fill_bytes_with_input(), Botan::System_RNG::is_seeded(), Botan::System_RNG::name(), and Botan::Sodium::randombytes_buf().

◆ throw_invalid_argument()

void BOTAN_UNSTABLE_API Botan::throw_invalid_argument ( const char * message,
const char * func,
const char * file )

Called when an invalid argument is used Throws Invalid_Argument

Definition at line 23 of file assert.cpp.

23 {
24 throw Invalid_Argument(fmt("{} in {}:{}", message, func, file));
25}

References fmt().

◆ throw_invalid_state()

void BOTAN_UNSTABLE_API Botan::throw_invalid_state ( const char * message,
const char * func,
const char * file )

Called when an invalid state is encountered Throws Invalid_State

Definition at line 27 of file assert.cpp.

27 {
28 throw Invalid_State(fmt("Invalid state: expr {} was false in {}:{}", expr, func, file));
29}

References fmt().

◆ to_affine()

template<typename C>
auto Botan::to_affine ( const typename C::ProjectivePoint & pt)
inlineconstexpr

Convert a projective point into affine

Definition at line 77 of file pcurves_algos.h.

77 {
78 // Not strictly required right? - default should work as long
79 // as (0,0) is identity and invert returns 0 on 0
80
81 if constexpr(curve_supports_fe_invert2<C>) {
82 const auto z2_inv = C::fe_invert2(pt.z());
83 const auto z3_inv = z2_inv.square() * pt.z();
84 return typename C::AffinePoint(pt.x() * z2_inv, pt.y() * z3_inv);
85 } else {
86 const auto z_inv = invert_field_element<C>(pt.z());
87 const auto z2_inv = z_inv.square();
88 const auto z3_inv = z_inv * z2_inv;
89 return typename C::AffinePoint(pt.x() * z2_inv, pt.y() * z3_inv);
90 }
91}

References invert_field_element().

Referenced by Botan::PCurve::GenericPrimeOrderCurve::point_to_affine(), Botan::PCurve::PrimeOrderCurveImpl< C >::point_to_affine(), and to_affine_batch().

◆ to_affine_batch()

template<typename C, bool VariableTime = false>
auto Botan::to_affine_batch ( std::span< const typename C::ProjectivePoint > projective)

Definition at line 108 of file pcurves_algos.h.

108 {
109 using AffinePoint = typename C::AffinePoint;
110
111 const size_t N = projective.size();
112 std::vector<AffinePoint> affine;
113 affine.reserve(N);
114
115 CT::Choice any_identity = CT::Choice::no();
116
117 for(const auto& pt : projective) {
118 any_identity = any_identity || pt.is_identity();
119 }
120
121 // Conditional acceptable: N is public. State of points is not necessarily
122 // public, but we don't leak which point was the identity. In practice with
123 // the algorithms currently in use, the only time an identity can occur is
124 // during mul2 where the two points g/h have a small relation (ie h = g*k for
125 // some k < 16)
126
127 if(N <= 2 || any_identity.as_bool()) {
128 // If there are identity elements, using the batch inversion gets
129 // tricky. It can be done, but this should be a rare situation so
130 // just punt to the serial conversion if it occurs
131 for(size_t i = 0; i != N; ++i) {
132 affine.push_back(to_affine<C>(projective[i]));
133 }
134 } else {
135 std::vector<typename C::FieldElement> c;
136 c.reserve(N);
137
138 /*
139 Batch projective->affine using Montgomery's trick
140
141 See Algorithm 2.26 in "Guide to Elliptic Curve Cryptography"
142 (Hankerson, Menezes, Vanstone)
143 */
144
145 c.push_back(projective[0].z());
146 for(size_t i = 1; i != N; ++i) {
147 c.push_back(c[i - 1] * projective[i].z());
148 }
149
150 auto s_inv = [&]() {
151 if constexpr(VariableTime) {
152 return c[N - 1].invert_vartime();
153 } else {
154 return invert_field_element<C>(c[N - 1]);
155 }
156 }();
157
158 for(size_t i = N - 1; i > 0; --i) {
159 const auto& p = projective[i];
160
161 const auto z_inv = s_inv * c[i - 1];
162 const auto z2_inv = z_inv.square();
163 const auto z3_inv = z_inv * z2_inv;
164
165 s_inv = s_inv * p.z();
166
167 affine.push_back(AffinePoint(p.x() * z2_inv, p.y() * z3_inv));
168 }
169
170 const auto z2_inv = s_inv.square();
171 const auto z3_inv = s_inv * z2_inv;
172 affine.push_back(AffinePoint(projective[0].x() * z2_inv, projective[0].y() * z3_inv));
173 std::reverse(affine.begin(), affine.end());
174 return affine;
175 }
176
177 return affine;
178}
static constexpr Choice no()
Definition ct_utils.h:307
constexpr bool as_bool() const
Definition ct_utils.h:329
constexpr auto to_affine(const typename C::ProjectivePoint &pt)

References Botan::CT::Choice::as_bool(), invert_field_element(), Botan::CT::Choice::no(), and to_affine().

Referenced by basemul_booth_setup(), basemul_setup(), and odd_multiples_setup_vartime().

◆ to_affine_x()

template<typename C>
auto Botan::to_affine_x ( const typename C::ProjectivePoint & pt)

Convert a projective point into affine and return x coordinate only

Definition at line 97 of file pcurves_algos.h.

97 {
98 if constexpr(curve_supports_fe_invert2<C>) {
99 return pt.x() * C::fe_invert2(pt.z());
100 } else {
101 const auto z_inv = invert_field_element<C>(pt.z());
102 const auto z2_inv = z_inv.square();
103 return pt.x() * z2_inv;
104 }
105}

References invert_field_element().

Referenced by Botan::PCurve::GenericPrimeOrderCurve::base_point_mul_x_mod_order(), Botan::PCurve::PrimeOrderCurveImpl< C >::base_point_mul_x_mod_order(), Botan::PCurve::GenericPrimeOrderCurve::mul_x_only(), and Botan::PCurve::PrimeOrderCurveImpl< C >::mul_x_only().

◆ to_string() [1/2]

const char * Botan::to_string ( Certificate_Status_Code code)

Convert a status code to a human readable diagnostic message

Parameters
codethe certificate status
Returns
string literal constant, or nullptr if code unknown

Definition at line 11 of file cert_status.cpp.

11 {
12 switch(code) {
14 return "Verified";
16 return "OCSP response accepted as affirming unrevoked status for certificate";
18 return "Signature on OCSP response was found valid";
20 return "Valid CRL examined";
21
23 return "Certificate serial number is negative";
25 return "Distinguished name too long";
27 return "OCSP URL not available";
29 return "OCSP server not available";
31 return "Trusted certificate is not yet valid";
33 return "Trusted certificate has expired";
35 return "OCSP issuer is not trustworthy";
36
38 return "No revocation data";
40 return "Signature method too weak";
42 return "Hash function used is considered too weak for security";
43
45 return "Certificate is not yet valid";
47 return "Certificate has expired";
49 return "OCSP is not yet valid";
51 return "OCSP response has expired";
53 return "OCSP response is too old";
55 return "CRL response is not yet valid";
57 return "CRL has expired";
58
60 return "Certificate issuer not found";
62 return "Cannot establish trust";
64 return "Loop in certificate chain";
66 return "Certificate chain does not end in a CA certificate";
68 return "Certificate issuer does not match subject of issuing cert";
69
71 return "Certificate policy error";
73 return "Certificate contains duplicate policy";
75 return "Certificate extension encoding error";
77 return "Certificate does not allow the requested usage";
79 return "Certificate chain too long";
81 return "CA certificate not allowed to issue certs";
83 return "CA certificate not allowed to issue CRLs";
85 return "No CRL with matching distribution point for certificate";
87 return "OCSP cert not listed";
89 return "OCSP bad status";
91 return "Certificate does not match provided name";
93 return "Certificate does not pass name constraint";
95 return "IP Address Blocks extension invalid";
97 return "AS Number Blocks extension invalid";
99 return "TN Authorization List not encompassed by a CA in the path";
101 return "noRevAvail extension used in an invalid manner";
103 return "Invalid use of OCSP NoCheck extension";
105 return "CRL contains a critical extension that could not be processed";
107 return "Unknown critical extension encountered";
109 return "Duplicate certificate extension encountered";
111 return "Encountered extension in certificate with version that does not allow it";
113 return "Encountered v2 identifiers in v1 certificate";
115 return "OCSP signature error";
117 return "Unable to find certificate issuing OCSP response";
119 return "OCSP issuer's keyusage prohibits OCSP";
121 return "OCSP response was unparsable or had invalid encoding";
123 return "OCSP requests not available, no HTTP support compiled in";
125 return "Certificate is revoked";
127 return "CRL bad signature";
129 return "Signature error";
131 return "Certificate public key invalid";
133 return "Certificate signed with unknown/unavailable algorithm";
135 return "Certificate signature has invalid parameters";
137 return "Exceeded search limitations while pathfinding";
138
139 // intentionally no default so we are warned if new enum values are added
140 }
141
142 return nullptr;
143}

References AS_BLOCKS_ERROR, CA_CERT_NOT_FOR_CERT_ISSUER, CA_CERT_NOT_FOR_CRL_ISSUER, CANNOT_ESTABLISH_TRUST, CERT_CHAIN_LOOP, CERT_CHAIN_TOO_LONG, CERT_HAS_EXPIRED, CERT_IS_REVOKED, CERT_ISSUER_NOT_FOUND, CERT_NAME_NOMATCH, CERT_NOT_YET_VALID, CERT_PUBKEY_INVALID, CERT_SERIAL_NEGATIVE, CHAIN_LACKS_TRUST_ROOT, CHAIN_NAME_MISMATCH, CRL_BAD_SIGNATURE, CRL_HAS_EXPIRED, CRL_HAS_UNKNOWN_CRITICAL_EXTENSION, CRL_NOT_YET_VALID, DN_TOO_LONG, DUPLICATE_CERT_EXTENSION, DUPLICATE_CERT_POLICY, EXCEEDED_SEARCH_LIMITS, EXT_IN_V1_V2_CERT, EXTENSION_ENCODING_ERROR, INVALID_OCSP_NOCHECK, INVALID_USAGE, IPADDR_BLOCKS_ERROR, NAME_CONSTRAINT_ERROR, NO_MATCHING_CRLDP, NO_REV_AVAIL_INVALID_USE, NO_REVOCATION_DATA, OCSP_BAD_STATUS, OCSP_CERT_NOT_LISTED, OCSP_HAS_EXPIRED, OCSP_IS_TOO_OLD, OCSP_ISSUER_NOT_FOUND, OCSP_ISSUER_NOT_TRUSTED, OCSP_NO_HTTP, OCSP_NO_REVOCATION_URL, OCSP_NOT_YET_VALID, OCSP_RESPONSE_GOOD, OCSP_RESPONSE_INVALID, OCSP_RESPONSE_MISSING_KEYUSAGE, OCSP_SERVER_NOT_AVAILABLE, OCSP_SIGNATURE_ERROR, OCSP_SIGNATURE_OK, POLICY_ERROR, SIGNATURE_ALGO_BAD_PARAMS, SIGNATURE_ALGO_UNKNOWN, SIGNATURE_ERROR, SIGNATURE_METHOD_TOO_WEAK, TN_AUTH_LIST_ERROR, TRUSTED_CERT_HAS_EXPIRED, TRUSTED_CERT_NOT_YET_VALID, UNKNOWN_CRITICAL_EXTENSION, UNTRUSTED_HASH, V2_IDENTIFIERS_IN_V1_CERT, VALID_CRL_CHECKED, and VERIFIED.

◆ to_string() [2/2]

std::string Botan::to_string ( ErrorType type)

Convert an ErrorType to string.

Definition at line 13 of file exceptn.cpp.

13 {
14 switch(type) {
16 return "Unknown";
18 return "SystemError";
20 return "NotImplemented";
22 return "OutOfMemory";
24 return "InternalError";
26 return "IoError";
28 return "InvalidObjectState";
30 return "KeyNotSet";
32 return "InvalidArgument";
34 return "InvalidKeyLength";
36 return "InvalidNonceLength";
38 return "LookupError";
40 return "EncodingFailure";
42 return "DecodingFailure";
44 return "TLSError";
46 return "HttpError";
48 return "InvalidTag";
50 return "RoughtimeError";
52 return "CommonCryptoError";
54 return "Pkcs11Error";
56 return "TPMError";
58 return "DatabaseError";
60 return "ZlibError";
62 return "Bzip2Error";
64 return "LzmaError";
65 }
66
67 // No default case in above switch so compiler warns
68 return "Unrecognized Botan error";
69}

References Bzip2Error, CommonCryptoError, DatabaseError, DecodingFailure, EncodingFailure, HttpError, InternalError, InvalidArgument, InvalidKeyLength, InvalidNonceLength, InvalidObjectState, InvalidTag, IoError, KeyNotSet, LookupError, LzmaError, NotImplemented, OutOfMemory, Pkcs11Error, RoughtimeError, SystemError, TLSError, TPMError, Unknown, and ZlibError.

Referenced by Botan::TLS::Server_Hello_13::basic_validation(), botan_x509_cert_validation_status(), Botan::Cert_Extension::TNAuthList::Entry::encode_into(), Botan::PKCS11::PKCS11_ReturnError::PKCS11_ReturnError(), and Botan::Path_Validation_Result::status_string().

◆ to_u32bit()

BOTAN_TEST_API uint32_t Botan::to_u32bit ( std::string_view input)

Convert a decimal string to a number, throwing if invalid

Parameters
inputthe string to convert
Returns
number value of the string

Definition at line 75 of file parsing.cpp.

75 {
76 if(const auto parsed = parse_u32(input)) {
77 return *parsed;
78 } else {
79 throw Invalid_Argument(fmt("Failed to parse input '{}' as a 32-bit integer", input));
80 }
81}
std::optional< uint32_t > parse_u32(std::string_view input, bool require_canonical)
Definition parsing.cpp:63

References fmt(), and parse_u32().

Referenced by argon2_check_pwhash(), create_private_key(), Botan::TLS::Text_Policy::dtls_maximum_hello_verify_requests(), Botan::ASN1_Time::from_string(), Botan::TLS::Text_Policy::get_len(), and Botan::TLS::Text_Policy::max_useless_records().

◆ to_underlying()

template<typename T>
auto Botan::to_underlying ( T e)
noexcept

Definition at line 158 of file stl_util.h.

158 {
159 return static_cast<std::underlying_type_t<T>>(e);
160}

Referenced by Botan::TLS::Cipher_State::marshall_and_protect(), Botan::TLS::Transcript_Hash_State::recreate_after_hello_retry_request(), and Botan::TLS::Record_TLS::serialize_header().

◆ tolower_string()

std::string Botan::tolower_string ( std::string_view str)

Definition at line 125 of file parsing.cpp.

125 {
126 // Locale-independent ASCII fold; the only callers (DNS name canonicalization
127 // for SAN/name-constraints) work on ASCII strings per RFC 1035.
128 std::string lower(str);
129 for(char& c : lower) {
130 if(c >= 'A' && c <= 'Z') {
131 c = static_cast<char>(c + ('a' - 'A'));
132 }
133 }
134 return lower;
135}

Referenced by Botan::URI::filter_scheme(), and Botan::URI::from_string().

◆ treehash() [1/2]

BOTAN_TEST_API void Botan::treehash ( StrongSpan< SphincsTreeNode > out_root,
StrongSpan< SphincsAuthenticationPath > out_auth_path,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hashes,
std::optional< TreeNodeIndex > leaf_idx,
uint32_t idx_offset,
uint32_t tree_height,
const GenerateLeavesFunction & gen_leaves,
Sphincs_Address & tree_address )

Implements a generic Merkle tree hash. Will be used for both FORS and XMSS signatures. gen_leaves is used to create batches of leaf nodes in the respective trees. Additionally XMSS uses the gen_leaves logic to store the WOTS Signature in the main SLH-DSA signature. The leaf_idx is the index of leaf to sign. If only the root node must be computed (without a signature), the leaf_idx is set to std::nullopt.

Definition at line 17 of file sp_treehash.cpp.

25 {
26 BOTAN_ASSERT_NOMSG(out_root.size() == params.n());
27 BOTAN_ASSERT_NOMSG(out_auth_path.size() == params.n() * total_tree_height);
28 BOTAN_ASSERT_NOMSG(total_tree_height < 32);
29
30 const TreeNodeIndex max_idx((uint32_t(1) << total_tree_height) - 1);
31 // Not has_value() || value(), which GCC may compile to test the payload first
32 BOTAN_ASSERT_NOMSG(leaf_idx.value_or(TreeNodeIndex(0)) <= max_idx);
33
34 std::vector<uint8_t> stack(total_tree_height * params.n());
35
36 // Leaves are created in batches to enable batched hashing. Both the batch
37 // size and the leaf count are powers of two, so batches are always full.
38 const uint32_t leaves_per_batch = std::min<uint32_t>(uint32_t(1) << total_tree_height, 128);
39 std::vector<uint8_t> leaves(leaves_per_batch * params.n());
40
41 /* Traverse the tree from the left-most leaf, matching siblings and up until
42 * the root (Post-order traversal). Collect the adjacent nodes (A) to build
43 * the authentication path (X) along the way.
44 *
45 * 7R
46 * / \
47 * 3X 6A
48 * / \ / \
49 * 1X 2A 4 5
50 */
51 for(TreeNodeIndex idx(0); true; ++idx) {
52 const uint32_t batch_pos = idx.get() % leaves_per_batch;
53 if(batch_pos == 0) {
54 gen_leaves(leaves, idx + idx_offset, leaves_per_batch);
55 }
56 // Current logical node, evolved in place as siblings are combined
57 const auto current_node = std::span(leaves).subspan(batch_pos * params.n(), params.n());
58
59 // Now combine the freshly generated right node with previously generated
60 // left ones
61 uint32_t internal_idx_offset = idx_offset;
62 TreeNodeIndex internal_idx = idx;
63 auto internal_leaf = leaf_idx;
64
65 for(TreeLayerIndex h(0); true; ++h) {
66 // Check if we hit the top of the tree
67 if(h.get() == total_tree_height) {
68 copy_mem(out_root, current_node);
69 return;
70 }
71
72 // Check if the node we have is a part of the authentication path; if
73 // it is, write it out. The XOR sum of both nodes (at internal_idx and internal_leaf)
74 // is 1 iff they have the same parent node in the FORS tree
75 if(internal_leaf.has_value() && (internal_idx ^ internal_leaf.value()) == 0x01U) {
76 const auto auth_path_location = out_auth_path.get().subspan(h.get() * params.n(), params.n());
77 copy_mem(auth_path_location, current_node);
78 }
79
80 // At this point we know that we'll need to use the stack. Get a
81 // reference to the correct location.
82 const auto stack_location = std::span(stack).subspan(h.get() * params.n(), params.n());
83
84 // Check if we're at a left child; if so, stop going up the stack
85 // Exception: if we've reached the end of the tree, keep on going (so
86 // we combine the last 4 nodes into the one root node in two more
87 // iterations)
88 if((internal_idx & 1) == 0U && idx < max_idx) {
89 // We've hit a left child; save the current for when we get the
90 // corresponding right child.
91 copy_mem(stack_location, current_node);
92 break;
93 }
94
95 // Ok, we're at a right node. Now combine the left and right logical
96 // nodes together.
97
98 // Set the address of the node we're creating.
99 internal_idx_offset /= 2;
100 tree_address.set_tree_height(h + 1);
101 tree_address.set_tree_index(internal_idx / 2 + internal_idx_offset);
102
103 hashes.T(current_node, tree_address, stack_location, current_node);
104
105 internal_idx /= 2;
106 if(internal_leaf.has_value()) {
107 internal_leaf.value() /= 2;
108 }
109 }
110 }
111}
underlying_span get() const

References BOTAN_ASSERT_NOMSG, copy_mem(), Botan::StrongSpan< T >::get(), Botan::Sphincs_Parameters::n(), Botan::Sphincs_Address::set_tree_height(), Botan::Sphincs_Address::set_tree_index(), Botan::StrongSpan< T >::size(), and Botan::Sphincs_Hash_Functions::T().

Referenced by fors_sign_and_pkgen(), and xmss_sign_and_pkgen().

◆ treehash() [2/2]

template<concepts::contiguous_strong_type TreeNode, concepts::strong_span AuthPathSS, concepts::tree_node_index TreeNodeIndex, concepts::tree_layer_index TreeLayerIndex, typename Address>
void Botan::treehash ( StrongSpan< TreeNode > out_root,
std::optional< AuthPathSS > out_auth_path,
std::optional< TreeNodeIndex > leaf_idx,
size_t node_size,
TreeLayerIndex total_tree_height,
uint32_t idx_offset,
concepts::tree_hash_node_pair< TreeNodeIndex, TreeLayerIndex, Address, StrongSpan< TreeNode > > auto node_pair_hash,
concepts::tree_gen_leaves< TreeNodeIndex > auto gen_leaves,
Address & tree_address )
inline

Treehash logic to build up a merkle hash tree.

Computes the root of the merkle tree. Can also output an authentication path necessary for a hash based signature.

Given the following tree: Layer: 2 7R / \ 1 3X 6A / \ / \ 0 1X 2A 4 5

The treehash logic traverses the tree (Post-order traversal), i.e., the nodes are discovered in order 1,2,3,...,7. If we want to create a signature using leaf node 1, the authentication path is (Node 2, Node 6), since we need those to compute the root.

Parameters
out_rootAn output buffer to store the root node in (size: node_size ).
out_auth_pathOptional buffer to store the authentication path in (size: node_size * total_tree_height).
leaf_idxThe optional index of the leaf used to sign in the bottom tree layer beginning with index 0. nullopt if no node is signed, so we need no auth path.
node_sizeThe size of each node in the tree.
total_tree_heightThe height of the merkle tree to construct.
idx_offsetIf we compute a subtree this marks the index of the leftmost leaf node in the bottom layer
node_pair_hashThe function to process two child nodes to compute their parent node.
gen_leavesThe logic to create a batch of consecutive leaf nodes, given the index of the first leaf (including the tree's index offset) and the leaf count. Probably this function creates one-time/few-time-signatures' public keys which are hashed to be the leaf nodes.
tree_addressThe address that is passed to node_pair hash. This function will update the address accordings to the currently processed node. This object may contain further algorithm specific information, like the position of this merkle tree in a hypertree.

Definition at line 111 of file tree_hash.h.

120 {
121 BOTAN_ASSERT_NOMSG(out_root.size() == node_size);
122 BOTAN_ASSERT(out_auth_path.has_value() == leaf_idx.has_value(),
123 "Both leaf index and auth path buffer is given or neither.");
124 const bool is_signing = leaf_idx.has_value();
125 BOTAN_ASSERT_NOMSG(!is_signing || out_auth_path.value().size() == node_size * total_tree_height.get());
126 BOTAN_ASSERT_NOMSG(total_tree_height.get() < 32);
127
128 const TreeNodeIndex max_idx((uint32_t(1) << total_tree_height.get()) - 1);
129 // Not has_value() || value(), which GCC may compile to test the payload first
130 BOTAN_ASSERT_NOMSG(leaf_idx.value_or(TreeNodeIndex(0)) <= max_idx);
131
132 std::vector<TreeNode> last_visited_left_child_at_layer(total_tree_height.get(), TreeNode(node_size));
133
134 TreeNode current_node(node_size); // Current logical node
135
136 // Leaves are created in batches to enable batched hashing. Both the
137 // batch size and the leaf count are powers of two, so batches are
138 // always full.
139 const uint32_t leaves_per_batch = std::min<uint32_t>(uint32_t(1) << total_tree_height.get(), 32);
140 std::vector<uint8_t> leaves(leaves_per_batch * node_size);
141
142 // Traverse the tree from the left-most leaf, matching siblings and up until
143 // the root (Post-order traversal). Collect the adjacent nodes to build
144 // the authentication path along the way.
145 for(TreeNodeIndex idx(0); true; ++idx) {
146 const uint32_t batch_pos = idx.get() % leaves_per_batch;
147 if(batch_pos == 0) {
148 gen_leaves(std::span(leaves), idx + idx_offset, leaves_per_batch);
149 }
150 copy_mem(current_node, std::span(leaves).subspan(batch_pos * node_size, node_size));
151
152 // Now combine the freshly generated right node with previously generated
153 // left ones
154 uint32_t internal_idx_offset = idx_offset;
155 TreeNodeIndex internal_idx = idx;
156 auto internal_leaf = leaf_idx;
157
158 for(TreeLayerIndex h(0); true; ++h) {
159 // Check if we hit the top of the tree
160 if(h == total_tree_height) {
161 copy_mem(out_root, current_node);
162 return;
163 }
164
165 // Check if the node we have is a part of the authentication path; if
166 // it is, write it out. The XOR sum of both nodes (at internal_idx and internal_leaf)
167 // is 1 iff they have the same parent node in the FORS tree
168 if(is_signing && (internal_idx ^ internal_leaf.value()) == 0x01U) {
169 const auto auth_path_location = out_auth_path.value().get().subspan(h.get() * node_size, node_size);
170 copy_mem(auth_path_location, current_node);
171 }
172
173 // Check if we're at a left child; if so, stop going up the tree
174 // Exception: if we've reached the end of the tree, keep on going (so
175 // we combine the last 4 nodes into the one root node in two more
176 // iterations)
177 if((internal_idx & 1) == 0U && idx < max_idx) {
178 // We've hit a left child; save the current for when we get the
179 // corresponding right child.
180 copy_mem(last_visited_left_child_at_layer.at(h.get()), current_node);
181 break;
182 }
183
184 // Ok, we're at a right node. Now combine the left and right logical
185 // nodes together.
186
187 // Set the address of the node we're creating.
188 internal_idx_offset /= 2;
189 tree_address.set_address(h + 1, internal_idx / 2 + internal_idx_offset);
190
191 node_pair_hash(current_node, tree_address, last_visited_left_child_at_layer.at(h.get()), current_node);
192
193 internal_idx /= 2;
194 if(internal_leaf.has_value()) {
195 internal_leaf.value() /= 2;
196 }
197 }
198 }
199}

References BOTAN_ASSERT, BOTAN_ASSERT_NOMSG, copy_mem(), Botan::detail::Strong_Base< T >::get(), and Botan::StrongSpan< T >::size().

◆ typecast_copy() [1/9]

template<typename ToT, ranges::contiguous_range FromR>
ToT Botan::typecast_copy ( const FromR & src)
inlineconstexpr

Create a trivial type by bit-casting a range of trivially copyable type with matching length into it.

Definition at line 210 of file mem_ops.h.

210 {
211 ToT dst; // NOLINT(*-member-init)
212 typecast_copy(dst, src);
213 return dst;
214}

References typecast_copy().

◆ typecast_copy() [2/9]

template<typename To>
To Botan::typecast_copy ( const uint8_t src[])
inlineconstexprnoexcept

Reinterpret a byte array as a single trivial object

Parameters
srcthe input byte array, must hold sizeof(To) bytes
Returns
the object read from src

Definition at line 279 of file mem_ops.h.

279 {
280 // asserts that *src points to the correct amount of memory
281 return typecast_copy<To>(std::span<const uint8_t, sizeof(To)>(src, sizeof(To)));
282}

References typecast_copy().

◆ typecast_copy() [3/9]

template<typename T>
void Botan::typecast_copy ( T & out,
const uint8_t in[] )
inlineconstexpr

Reinterpret a byte array as a single trivial object

Parameters
outthe object to copy into
inthe input byte array, must hold sizeof(T) bytes

Definition at line 266 of file mem_ops.h.

266 {
267 // asserts that *in points to the correct amount of memory
268 typecast_copy(out, std::span<const uint8_t, sizeof(T)>(in, sizeof(T)));
269}

References typecast_copy().

◆ typecast_copy() [4/9]

template<typename T>
requires std::is_trivial_v<T>
void Botan::typecast_copy ( T out[],
const uint8_t in[],
size_t N )
inlineconstexpr

Reinterpret a byte array as an array of trivial objects

Parameters
outthe output array, must have room for N elements
inthe input byte array, must hold sizeof(T)*N bytes
Nthe number of elements to produce

Definition at line 239 of file mem_ops.h.

241{
242 // asserts that *in and *out point to the correct amount of memory
243 typecast_copy(std::span<T>(out, N), std::span<const uint8_t>(in, N * sizeof(T)));
244}

References typecast_copy().

◆ typecast_copy() [5/9]

template<ranges::contiguous_output_range ToR, ranges::contiguous_range FromR>
void Botan::typecast_copy ( ToR && out,
const FromR & in )
inlineconstexpr

◆ typecast_copy() [6/9]

template<ranges::contiguous_output_range ToR, typename FromT>
void Botan::typecast_copy ( ToR && out,
const FromT & in )
inlineconstexpr

Copy an instance of trivially copyable type into a range of trivially copyable type with matching length.

Definition at line 199 of file mem_ops.h.

199 {
200 typecast_copy(out, std::span<const FromT, 1>(&in, 1));
201}

References typecast_copy().

◆ typecast_copy() [7/9]

template<typename ToT, ranges::contiguous_range FromR>
void Botan::typecast_copy ( ToT & out,
const FromR & in )
inlineconstexpr

Copy a range of trivially copyable type into an instance of trivially copyable type with matching length.

Definition at line 188 of file mem_ops.h.

188 {
189 typecast_copy(std::span<ToT, 1>(&out, 1), in);
190}

References typecast_copy().

◆ typecast_copy() [8/9]

template<typename T>
void Botan::typecast_copy ( uint8_t out[],
const T & in )
inlineconstexpr

Copy the bytes of a single object into a byte array

Parameters
outthe output byte array, must have room for sizeof(T) bytes
inthe object to copy from

Definition at line 253 of file mem_ops.h.

253 {
254 // asserts that *out points to the correct amount of memory
255 typecast_copy(std::span<uint8_t, sizeof(T)>(out, sizeof(T)), in);
256}

References typecast_copy().

◆ typecast_copy() [9/9]

template<typename T>
requires std::is_trivially_copyable_v<T>
void Botan::typecast_copy ( uint8_t out[],
T in[],
size_t N )
inlineconstexpr

Copy the bytes of an array of trivially copyable objects into a byte array

Parameters
outthe output byte array, must have room for sizeof(T)*N bytes
inthe input array
Nthe number of elements in the input array

Definition at line 224 of file mem_ops.h.

226{
227 // asserts that *in and *out point to the correct amount of memory
228 typecast_copy(std::span<uint8_t>(out, sizeof(T) * N), std::span<const T>(in, N));
229}

References typecast_copy().

◆ ucs2_to_utf8()

BOTAN_TEST_API std::string Botan::ucs2_to_utf8 ( std::span< const uint8_t > ucs2)

Convert a sequence of UCS-2 (big endian) characters to a UTF-8 string This is used for ASN.1 BMPString type

Parameters
ucs2the sequence of UCS-2 characters, length must be a multiple of 2

Definition at line 121 of file charset.cpp.

121 {
122 if(ucs2.size() % 2 != 0) {
123 throw Decoding_Error("Invalid length for UCS-2 string");
124 }
125
126 const size_t chars = ucs2.size() / 2;
127
128 std::string s;
129 for(size_t i = 0; i != chars; ++i) {
130 const uint32_t c = load_be<uint16_t>(ucs2.data(), i);
131 append_utf8_for(s, c);
132 }
133
134 return s;
135}

References load_be().

Referenced by Botan::ASN1_String::decode_from().

◆ ucs4_to_utf8()

BOTAN_TEST_API std::string Botan::ucs4_to_utf8 ( std::span< const uint8_t > ucs4)

Convert a sequence of UCS-4 (big endian) characters to a UTF-8 string This is used for ASN.1 UniversalString type

Parameters
ucs4the sequence of UCS-4 characters, length must be a multiple of 4

Definition at line 155 of file charset.cpp.

155 {
156 if(ucs4.size() % 4 != 0) {
157 throw Decoding_Error("Invalid length for UCS-4 string");
158 }
159
160 const size_t chars = ucs4.size() / 4;
161
162 std::string s;
163 for(size_t i = 0; i != chars; ++i) {
164 const uint32_t c = load_be<uint32_t>(ucs4.data(), i);
165 append_utf8_for(s, c);
166 }
167
168 return s;
169}

References load_be().

Referenced by Botan::ASN1_String::decode_from().

◆ unchecked_copy_memory()

template<std::unsigned_integral T>
void Botan::unchecked_copy_memory ( T * out,
const T * in,
size_t n )
inline

Definition at line 44 of file mem_utils.h.

44 {
45 if(in != nullptr && out != nullptr && n > 0) {
46 std::memmove(out, in, sizeof(T) * n);
47 }
48}

Referenced by bigint_shl1(), bigint_shl2(), bigint_shr1(), bigint_shr2(), and Botan::BigInt::mod_sub().

◆ unlock()

template<typename T>
std::vector< T > Botan::unlock ( const secure_vector< T > & in)

Copy a secure_vector into an ordinary vector

Parameters
inthe vector to copy
Returns
a std::vector holding the same contents

Definition at line 155 of file secmem.h.

155 {
156 return std::vector<T>(in.begin(), in.end());
157}

Referenced by Botan::Roughtime::Chain::Chain(), Botan::DL_Group::DL_Group(), Botan::KeyPair::encryption_consistency_check(), Botan::PKCS12::export_to(), Botan::DL_Group::from_PEM(), and Botan::Cipher_Mode_Filter::set_iv().

◆ unpoison_asm_output()

template<size_t K, WordType W>
void Botan::unpoison_asm_output ( const W * ptr)
inline

Inform MemorySanitizer that inline asm has written the K words at ptr

MSan does not see the stores an asm block makes through a pointer operand, so memory that was uninitialized before the asm would otherwise still be considered uninitialized afterwards.

Definition at line 101 of file mp_asmi.h.

101 {
102#if defined(BOTAN_MP_ASM_HAS_MSAN)
103 __msan_unpoison(ptr, K * sizeof(W));
104#endif
105}

Referenced by bigint_mulx_mul4(), bigint_mulx_mul6(), bigint_mulx_mul8(), bigint_mulx_mul9(), bigint_mulx_sqr4(), bigint_mulx_sqr6(), bigint_mulx_sqr8(), bigint_mulx_sqr9(), word8_add2(), word8_add3(), word8_linmul3(), word8_madd3(), word8_sub2(), and word8_sub3().

◆ unsafe_for_production_build()

bool Botan::unsafe_for_production_build ( )

Certain build-time options, used for testing, result in a binary which is not safe for use in a production system. This function can be used to test for such a configuration at runtime.

Currently these unsafe conditions include:

  • Unsafe fuzzer mode (–unsafe-fuzzer-mode) which intentionally disables various checks in order to improve the effectiveness of fuzzing.
  • Terminate on asserts (–unsafe-terminate-on-asserts) which intentionally aborts if any internal assertion failure occurs, rather than throwing an exception.

Definition at line 67 of file version.cpp.

67 {
68#if defined(BOTAN_UNSAFE_FUZZER_MODE) || defined(BOTAN_TERMINATE_ON_ASSERTS)
69 return true;
70#else
71 return false;
72#endif
73}

◆ unwrap_strong_type()

template<typename T>
decltype(auto) Botan::unwrap_strong_type ( T && t)
nodiscardconstexpr

Generically unwraps a strong type to its underlying type.

If the provided type is not a strong type, it is returned as is.

Note
This is meant as a helper for generic code that needs to deal with both wrapped strong types and bare objects. Use the ordinary get() method if you know that you are dealing with a strong type.
Parameters
tvalue to be unwrapped
Returns
the unwrapped value

Definition at line 119 of file strong_type_helpers.h.

119 {
121 // If the parameter type isn't a strong type, return it as is.
122 return std::forward<T>(t);
123 } else {
124 // Unwrap the strong type and return the underlying value.
125 return std::forward<T>(t).get();
126 }
127}

Referenced by checked_cast_to_or_throw(), Botan::detail::concatenate(), Botan::bitvector_base< secure_allocator >::ct_conditional_xor(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_octet_aligned_bitstring(), Botan::BER_Decoder::decode_optional_octet_aligned_bitstring(), Botan::BER_Decoder::decode_optional_string(), Botan::bitvector_base< secure_allocator >::equals(), Botan::bitvector_base< secure_allocator >::equals_vartime(), Botan::bitvector_base< secure_allocator >::operator&=(), Botan::bitvector_base< secure_allocator >::operator^=(), Botan::bitvector_base< secure_allocator >::operator|=(), Botan::BER_Decoder::raw_bytes(), Botan::bitvector_base< secure_allocator >::subvector(), Botan::bitvector_base< secure_allocator >::subvector_replace(), and Botan::detail::unwrap_strong_type_or_enum().

◆ use_mulx_monty()

bool Botan::use_mulx_monty ( size_t p_size)
inline

Definition at line 33 of file mp_mulx.h.

33 {
35}
constexpr size_t MulxMontyMinWords
Definition mp_mulx.h:31

References Botan::CPUFeature::ADX, Botan::CPUFeature::BMI, Botan::CPUID::has(), and MulxMontyMinWords.

Referenced by bigint_monty_mul(), and bigint_monty_sqr().

◆ utf8_to_ucs2()

BOTAN_TEST_API std::vector< uint8_t > Botan::utf8_to_ucs2 ( std::string_view utf8)

Convert a UTF-8 string to a sequence of UCS-2 (big endian) characters This is used for ASN.1 BMPString type

Parameters
utf8the UTF-8 string
Returns
a vector of bytes containing the UCS-2 (big endian) encoding
Exceptions
Decoding_Errorif the input is not valid UTF-8 (including overlong encodings, surrogate code points, or values outside Unicode), or if a code point exceeds U+FFFF and cannot be represented in UCS-2

Definition at line 137 of file charset.cpp.

137 {
138 std::vector<uint8_t> out;
139 out.reserve(utf8.size() * 2);
140
141 size_t pos = 0;
142 while(pos < utf8.size()) {
143 const uint32_t c = next_utf8_codepoint(utf8, pos);
144 if(c > 0xFFFF) {
145 throw Decoding_Error("Cannot encode character in UCS-2");
146 }
147 const uint16_t val = static_cast<uint16_t>(c);
148 out.push_back(get_byte<0>(val));
149 out.push_back(get_byte<1>(val));
150 }
151
152 return out;
153}

References get_byte(), and next_utf8_codepoint().

◆ utf8_to_ucs4()

BOTAN_TEST_API std::vector< uint8_t > Botan::utf8_to_ucs4 ( std::string_view utf8)

Convert a UTF-8 string to a sequence of UCS-4 (big endian) characters This is used for ASN.1 UniversalString type

Parameters
utf8the UTF-8 string
Returns
a vector of bytes containing the UCS-4 (big endian) encoding
Exceptions
Decoding_Errorif the input is not valid UTF-8 (including overlong encodings, surrogate code points, or values outside the Unicode scalar value range U+0000..U+10FFFF)

Definition at line 171 of file charset.cpp.

171 {
172 std::vector<uint8_t> out;
173 out.reserve(utf8.size() * 4);
174
175 size_t pos = 0;
176 while(pos < utf8.size()) {
177 const uint32_t val = next_utf8_codepoint(utf8, pos);
178 out.push_back(get_byte<0>(val));
179 out.push_back(get_byte<1>(val));
180 out.push_back(get_byte<2>(val));
181 out.push_back(get_byte<3>(val));
182 }
183
184 return out;
185}

References get_byte(), and next_utf8_codepoint().

◆ validate_for_hash_based_signature()

void Botan::validate_for_hash_based_signature ( const PK_Signature_Options_Reader & options,
std::string_view algo_name,
std::string_view hash_fn )

For schemes where the hash function is fixed by the key (XMSS, SLH-DSA, ...)

Accepts the hash option only if it names the hash the key already uses.

Definition at line 324 of file pk_options_impl.cpp.

326 {
327 if(options.using_hash() && options.hash_function_name() != hash_fn) {
328 throw Invalid_Argument(
329 fmt("This {} key can only be used with {}, not {}", algo_name, hash_fn, options.hash_function_name()));
330 }
331}
const std::string & hash_function_name() const

References fmt(), Botan::PK_Signature_Options_Reader::hash_function_name(), and Botan::PK_Signature_Options_Reader::using_hash().

Referenced by Botan::HSS_LMS_PrivateKey::_create_signature_op(), Botan::SphincsPlus_PrivateKey::_create_signature_op(), Botan::XMSS_PrivateKey::_create_signature_op(), Botan::HSS_LMS_PublicKey::_create_verification_op(), Botan::SphincsPlus_PublicKey::_create_verification_op(), and Botan::XMSS_PublicKey::_create_verification_op().

◆ value_exists()

◆ var_ctz64()

BOTAN_FORCE_INLINE constexpr size_t Botan::var_ctz64 ( uint64_t n)
constexpr

Definition at line 181 of file bit_ops.h.

181 {
182#if BOTAN_COMPILER_HAS_BUILTIN(__builtin_ctzll)
183 if(n == 0) {
184 return 64;
185 }
186 return __builtin_ctzll(n);
187#else
188 return ctz<uint64_t>(n);
189#endif
190}

References BOTAN_FORCE_INLINE, and ctz().

◆ varpoint_exec()

template<typename C, size_t WindowBits, typename BlindedScalar, typename Blinding>
C::ProjectivePoint Botan::varpoint_exec ( const SharedZPointTable< C > & table,
const BlindedScalar & scalar,
const Blinding & blinding )

Definition at line 494 of file pcurves_mul.h.

496 {
497 const size_t windows = (scalar.bits() + WindowBits - 1) / WindowBits;
498
499 auto accum = [&]() {
500 const size_t w_0 = scalar.get_window((windows - 1) * WindowBits);
501 auto pt = C::ProjectivePoint::from_affine(table.ct_select(w_0));
502 blinding.randomize_rep(pt, 0);
503 return pt;
504 }();
505
506 for(size_t i = 1; i != windows; ++i) {
507 accum = accum.dbl_n_iso(table.a(), WindowBits);
508 auto w_i = scalar.get_window((windows - i - 1) * WindowBits);
509
510 /*
511 This point addition cannot be a doubling (except once)
512
513 Consider the sequence of points that are operated on, and specifically
514 their discrete logarithms. We start out at the point at infinity
515 (dlog 0) and then add the initial window which is precisely P*w_0
516
517 We then perform WindowBits doublings, so accum's dlog at the point
518 of the addition in the first iteration of the loop (when i == 1) is
519 at least 2^W * w_0.
520
521 Since we know w_0 > 0, then in every iteration of the loop, accums
522 dlog will always be greater than the dlog of the table element we
523 just looked up (something between 0 and 2^W-1), and thus the
524 addition into accum cannot be a doubling.
525
526 However due to blinding this argument fails, since we perform
527 multiplications using a scalar that is larger than the group
528 order. In this case it's possible that the dlog of accum becomes
529 `order + x` (or, effectively, `x`) and `x` is smaller than 2^W.
530 In this case, a doubling may occur. Future iterations of the loop
531 cannot be doublings by the same argument above. Since the blinding
532 factor is always less than the group order (substantially so),
533 it is not possible for the dlog of accum to overflow a second time.
534 */
535
536 accum = C::ProjectivePoint::add_mixed_iso(accum, table.ct_select(w_i), table.a());
537
538 // Conditional ok: loop iteration count is public
539 if(i < Blinding::Rerandomizations) {
540 blinding.randomize_rep(accum, i);
541 }
542 }
543
544 // Map back from the isomorphic curve
545 return typename C::ProjectivePoint(accum.x(), accum.y(), accum.z() * table.z());
546}

References Botan::SharedZPointTable< C >::a(), Botan::SharedZPointTable< C >::ct_select(), and Botan::SharedZPointTable< C >::z().

◆ varpoint_mul()

template<typename C, size_t W>
C::ProjectivePoint Botan::varpoint_mul ( const typename C::AffinePoint & p,
const typename C::Scalar & s,
RandomNumberGenerator & rng )

Variable point multiplication

This is a fixed window multiplication with Booth recoding, using a table [1*P, 2*P, ..., 2^W*P] with a shared Z coordinate. The scalar blinding, the accumulator re-randomizations, and the random curve isomorphism of the table all come from a single RNG request.

Definition at line 1673 of file pcurves_impl.h.

1675 {
1676 using ProjectivePoint = typename C::ProjectivePoint;
1677
1678 constexpr size_t TableBits = W;
1679 static_assert(TableBits >= 1 && TableBits <= 7);
1680
1681 constexpr size_t WindowBits = TableBits + 1;
1682
1683 using BlindedScalar = BlindedScalarBits<C, WindowBits + 1>;
1684 using Blinding = BlindingRandomness<BlindedScalar>;
1685
1686 // 2^W elements [1*P, 2*P, ..., 2^W*P]
1687 constexpr size_t TableSize = 1 << TableBits;
1688
1689 const Blinding blinding(rng);
1690 const SharedZPointTable<C> table(p, TableSize, C::A, blinding.isomorphism());
1691 const BlindedScalar bits(s, blinding);
1692
1693 const size_t scalar_bits = bits.bits();
1694 const size_t full_windows = booth_full_windows(scalar_bits + 1, WindowBits);
1695 const size_t initial_shift = booth_initial_shift(scalar_bits + 1, WindowBits);
1696
1697 BOTAN_DEBUG_ASSERT(full_windows * WindowBits + initial_shift == scalar_bits + 1);
1698 BOTAN_DEBUG_ASSERT(initial_shift > 0);
1699
1700 auto accum = ProjectivePoint::identity();
1701
1702 for(size_t i = 0; i != full_windows; ++i) {
1703 const size_t idx = scalar_bits - initial_shift - WindowBits * i;
1704
1705 const size_t w_i = bits.get_window(idx);
1706 const auto [tidx, tneg] = booth_recode<WindowBits>(w_i);
1707
1708 // Conditional ok: loop iteration count is public
1709 if(i == 0) {
1710 accum = ProjectivePoint::from_affine(table.ct_select(tidx));
1711 accum.conditional_assign(tneg, accum.negate());
1712 } else {
1713 accum = ProjectivePoint::add_or_sub_iso(accum, table.ct_select(tidx), tneg, table.a());
1714 }
1715
1716 accum = accum.dbl_n_iso(table.a(), WindowBits);
1717
1718 // Conditional ok: loop iteration count is public
1719 if(i < Blinding::Rerandomizations) {
1720 blinding.randomize_rep(accum, i);
1721 }
1722 }
1723
1724 // final window (note one bit shorter than previous reads)
1725 const size_t w_l = bits.get_window(0) & ((1 << WindowBits) - 1);
1726 const auto [tidx, tneg] = booth_recode<WindowBits>(w_l << 1);
1727 accum = ProjectivePoint::add_or_sub_iso(accum, table.ct_select(tidx), tneg, table.a());
1728
1729 // Map back from the isomorphic curve
1730 return ProjectivePoint(accum.x(), accum.y(), accum.z() * table.z());
1731}
constexpr size_t booth_full_windows(size_t sb, size_t wb)
constexpr size_t booth_initial_shift(size_t sb, size_t wb)

References Botan::SharedZPointTable< C >::a(), booth_full_windows(), booth_initial_shift(), booth_recode(), BOTAN_DEBUG_ASSERT, Botan::SharedZPointTable< C >::ct_select(), and Botan::SharedZPointTable< C >::z().

Referenced by Botan::PCurve::GenericPrimeOrderCurve::mul(), Botan::PCurve::PrimeOrderCurveImpl< C >::mul(), Botan::PCurve::GenericPrimeOrderCurve::mul_x_only(), and Botan::PCurve::PrimeOrderCurveImpl< C >::mul_x_only().

◆ varpoint_mul2()

template<typename C, size_t W>
C::ProjectivePoint Botan::varpoint_mul2 ( const typename C::AffinePoint & p,
const typename C::Scalar & x,
const typename C::AffinePoint & q,
const typename C::Scalar & y,
RandomNumberGenerator & rng )

Constant time 2-ary multiplication x*P + y*Q

Uses a joint table of all combinations of W bit windows of the two scalars, with a shared Z coordinate.

Definition at line 1740 of file pcurves_impl.h.

1744 {
1745 // We look at W bits of each scalar per iteration
1746 static_assert(W >= 1 && W <= 4);
1747
1748 using BlindedScalar = BlindedScalarBits<C, W>;
1749
1750 const BlindingRandomness<BlindedScalar, 2> blinding(rng);
1751 const SharedZPointTable<C> table(mul2_setup<C, W>(p, q), C::A, C::FieldElement::one(), blinding.isomorphism());
1752 const BlindedScalar x_bits(x, blinding, 0);
1753 const BlindedScalar y_bits(y, blinding, 1);
1754
1755 return mul2_exec<C, W>(table, x_bits, y_bits, blinding);
1756}
C::ProjectivePoint mul2_exec(const SharedZPointTable< C > &table, const BlindedScalar &x, const BlindedScalar &y, const Blinding &blinding)
std::vector< typename C::ProjectivePoint > mul2_setup(const typename C::AffinePoint &p, const typename C::AffinePoint &q)

References Botan::BlindingRandomness< BlindedScalar, Scalars >::isomorphism(), mul2_exec(), and mul2_setup().

Referenced by Botan::PCurve::GenericPrimeOrderCurve::mul_px_qy(), and Botan::PCurve::PrimeOrderCurveImpl< C >::mul_px_qy().

◆ verify_signature()

bool Botan::verify_signature ( std::span< const uint8_t, ED448_LEN > pk,
bool phflag,
std::span< const uint8_t > context,
std::span< const uint8_t > sig,
std::span< const uint8_t > msg )

Verify a signature(RFC 8032 5.2.7).

Parameters
pkthe public key
phflagthe prehash flag (true iff using Ed448ph)
contextthe context string
sigthe signature
msgthe message to verify
Exceptions
Decoding_Errorif the public key or signature is malformed
Returns
true if the signature is valid

Definition at line 433 of file ed448_internal.cpp.

437 {
438 // RFC 8032 5.2.7. Verify
439 // 1. To verify a signature on a message M using context C and public
440 // key A, with F being 0 for Ed448 and 1 for Ed448ph, first split
441 // the signature into two 57-octet halves. Decode the first half as
442 // a point R, and the second half as an integer S, in the range 0 <=
443 // s < L. Decode the public key A as point A'. If any of the
444 // decodings fail (including S being out of range), the signature is
445 // invalid.
446 if(sig.size() != 2 * ED448_LEN) {
447 // Wrong signature size
448 throw Decoding_Error("Ed448 signature has wrong size");
449 }
450 const auto [big_r_bytes, big_s_bytes] = split(sig.first<2 * ED448_LEN>());
451 // The identity is a valid R; small order checks apply to the public key only
452 const auto big_r = Ed448Point::decode(big_r_bytes);
453 if(!Scalar448::bytes_are_reduced(big_s_bytes)) {
454 // S not in range 0 <= s < L
455 throw Decoding_Error("Ed448 signature has invalid S");
456 }
457 const Scalar448 big_s(big_s_bytes);
458 // 2. Compute SHAKE256(dom4(F, C) || R || A || PH(M), 114), and
459 // interpret the 114-octet digest as a little-endian integer k.
460 const Scalar448 k(shake(phflag, context, big_r_bytes, pk, msg));
461 // 3. Check the group equation [4][S]B = [4]R + [4][k]A'. It's
462 // sufficient, but not required, to instead check [S]B = R + [k]A'.
463 // Rearranged as [S]B + [k](-A') = R, computed via Shamir's trick.
464 const auto neg_A = Ed448Point::decode(pk).negate();
465 return Ed448Point::double_scalar_mul_vartime(big_s, Ed448Point::base_point(), k, neg_A) == big_r;
466}
Ed448Point negate() const
Negate the point.
static Ed448Point double_scalar_mul_vartime(const Scalar448 &s1, const Ed448Point &p1, const Scalar448 &s2, const Ed448Point &p2)
Variable-time double scalar multiplication using Shamir's trick: [s1]P + [s2]Q.
static Ed448Point base_point()
Create the curve's base point ('B' in RFC 8032 5.2).
static bool bytes_are_reduced(std::span< const uint8_t > x)

References Botan::Ed448Point::base_point(), Botan::Scalar448::bytes_are_reduced(), Botan::Ed448Point::decode(), Botan::Ed448Point::double_scalar_mul_vartime(), ED448_LEN, and Botan::Ed448Point::negate().

Referenced by Botan::Roughtime::Response::from_bits().

◆ version_cstr()

const char * Botan::version_cstr ( )

Same as version_string() except returning a pointer to a statically allocated string.

Returns
version string

Definition at line 20 of file version.cpp.

20 {
21 return BOTAN_FULL_VERSION_STRING;
22}

Referenced by botan_version_string(), and version_string().

◆ version_datestamp()

uint32_t Botan::version_datestamp ( )

Return the date this version of botan was released, in an integer of the form YYYYMMDD. For instance a version released on May 21, 2013 would return the integer 20130521. If the currently running version is not an official release, this function will return 0 instead.

Returns
release date, or zero if unreleased

Definition at line 32 of file version.cpp.

32 {
34}
#define BOTAN_VERSION_DATESTAMP
Definition build.h:45

References BOTAN_VERSION_DATESTAMP.

Referenced by botan_version_datestamp().

◆ version_distribution_info()

std::optional< std::string > Botan::version_distribution_info ( )

Return any string that is set at build time using the --distribution-info option. It allows a packager of the library to specify any distribution-specific patches. If no value is given at build time, returns nullopt.

Returns
distribution info

Definition at line 44 of file version.cpp.

44 {
45#if defined(BOTAN_DISTRIBUTION_INFO_STRING)
46 return std::string(BOTAN_DISTRIBUTION_INFO_STRING);
47#else
48 return std::nullopt;
49#endif
50}

◆ version_major()

uint32_t Botan::version_major ( )

Get the major version number.

Returns
major version number

Definition at line 55 of file version.cpp.

55 {
57}

References BOTAN_VERSION_MAJOR.

Referenced by botan_version_major(), and runtime_version_check().

◆ version_minor()

uint32_t Botan::version_minor ( )

Get the minor version number.

Returns
minor version number

Definition at line 59 of file version.cpp.

59 {
61}

References BOTAN_VERSION_MINOR.

Referenced by botan_version_minor(), and runtime_version_check().

◆ version_patch()

uint32_t Botan::version_patch ( )

Get the patch number.

Returns
patch number

Definition at line 63 of file version.cpp.

63 {
65}

References BOTAN_VERSION_PATCH.

Referenced by botan_version_patch(), and runtime_version_check().

◆ version_string()

std::string Botan::version_string ( )

Get a human-readable single-line string identifying the version of Botan. No particular format should be assumed.

Returns
version string

Definition at line 24 of file version.cpp.

24 {
25 return std::string(version_cstr());
26}
const char * version_cstr()
Definition version.cpp:20

References version_cstr().

◆ version_vc_revision()

std::optional< std::string > Botan::version_vc_revision ( )

Returns a string that is set to a revision identifier corresponding to the source, or nullopt if this could not be determined. It is set for all official releases, and for builds that originated from within a git checkout.

Returns
VC revision

Definition at line 36 of file version.cpp.

36 {
37#if defined(BOTAN_VC_REVISION)
38 return std::string(BOTAN_VC_REVISION);
39#else
40 return std::nullopt;
41#endif
42}

◆ whirlpool_rc()

template<bool LittleEndian = false>
std::array< uint64_t, 10 > Botan::whirlpool_rc ( )
constevalnoexcept

Definition at line 42 of file whirlpool_consts.h.

42 {
43 constexpr auto S80 = whirlpool_sbox<80>();
44 std::array<uint64_t, 10> RC = {};
45 for(size_t r = 0; r != 10; ++r) {
46 if(LittleEndian) {
47 RC[r] = load_le<uint64_t>(S80.data(), r);
48 } else {
49 RC[r] = load_be<uint64_t>(S80.data(), r);
50 }
51 }
52 return RC;
53}
consteval std::array< uint8_t, N > whirlpool_sbox() noexcept

References load_be(), load_le(), and whirlpool_sbox().

Referenced by Botan::Whirlpool::compress_n().

◆ whirlpool_sbox()

template<size_t N = 256>
std::array< uint8_t, N > Botan::whirlpool_sbox ( )
constevalnoexcept

Definition at line 18 of file whirlpool_consts.h.

18 {
19 static_assert(N == 256 || N == 80);
20
21 constexpr uint8_t Ebox[16] = {1, 11, 9, 12, 13, 6, 15, 3, 14, 8, 7, 4, 10, 2, 5, 0};
22 constexpr uint8_t Rbox[16] = {7, 12, 11, 13, 14, 4, 9, 15, 6, 3, 8, 10, 2, 5, 1, 0};
23
24 // Derive the inverse of the E table
25 uint8_t Eibox[16] = {};
26 for(size_t i = 0; i != 16; ++i) {
27 Eibox[Ebox[i]] = static_cast<uint8_t>(i);
28 }
29
30 std::array<uint8_t, N> S = {};
31 for(size_t i = 0; i != N; ++i) {
32 const uint8_t L = Ebox[i >> 4];
33 const uint8_t R = Eibox[i & 0x0F];
34 const uint8_t T = Rbox[L ^ R];
35 S[i] = static_cast<uint8_t>((Ebox[L ^ T] << 4) | Eibox[R ^ T]);
36 }
37 return S;
38}

Referenced by whirlpool_rc().

◆ wildcard_intersects_excluded_dns_subtree()

BOTAN_TEST_API bool Botan::wildcard_intersects_excluded_dns_subtree ( std::string_view pattern,
std::string_view constraint )

Definition at line 153 of file name_constraint.cpp.

153 {
154 if(pattern.empty() || constraint.empty()) {
155 return false;
156 }
157 const bool subtree_form = (constraint.front() == '.');
158 const std::string_view c_base = subtree_form ? constraint.substr(1) : constraint;
159 if(c_base.empty()) {
160 return false;
161 }
162
163 const auto first_dot = pattern.find('.');
164 const std::string_view p_left = (first_dot == std::string_view::npos) ? pattern : pattern.substr(0, first_dot);
165 const std::string_view p_tail =
166 (first_dot == std::string_view::npos) ? std::string_view{} : pattern.substr(first_dot);
167
168 if(p_tail.empty()) {
169 // Single-label wildcard. Matches single-label names only, so it
170 // can only land inside a bare-host subtree whose base is also a
171 // single label.
172 if(subtree_form || c_base.find('.') != std::string_view::npos) {
173 return false;
174 }
175 return wildcard_label_matches(p_left, c_base);
176 }
177
178 // p_tail starts with ".". If it ends (label-aligned) with "." + c_base,
179 // then every wildcard expansion produces a name ending with that
180 // suffix, which is inside c_base's subtree (both bare-host and
181 // leading-dot forms accept proper-subdomain entries).
182 if(auto suffix_len = checked_add(c_base.size(), size_t{1})) {
183 if(p_tail.size() >= *suffix_len) {
184 const auto tail_suffix = p_tail.substr(p_tail.size() - *suffix_len);
185 if(tail_suffix.front() == '.' && tail_suffix.substr(1) == c_base) {
186 return true;
187 }
188 }
189 }
190
191 // Bare-host subtrees also contain c_base itself. The wildcard can
192 // produce c_base directly iff c_base = (single label) + p_tail and
193 // the prefix label fits p_left.
194 if(!subtree_form && c_base.size() > p_tail.size() && c_base.substr(c_base.size() - p_tail.size()) == p_tail) {
195 const auto x_view = c_base.substr(0, c_base.size() - p_tail.size());
196 return wildcard_label_matches(p_left, x_view);
197 }
198
199 return false;
200}

References checked_add().

Referenced by Botan::NameConstraints::is_excluded().

◆ word8_add2()

template<WordType W>
auto Botan::word8_add2 ( W x[8],
const W y[8],
W carry ) -> W
inlineconstexpr

Definition at line 297 of file mp_asmi.h.

297 {
298#if defined(BOTAN_MP_USE_X86_64_ASM)
299 if constexpr(std::same_as<W, uint64_t>) {
300 if(!std::is_constant_evaluated()) {
301 asm volatile(ADD_OR_SUBTRACT(DO_8_TIMES(ADDSUB2_OP, "adcq"))
302 : [carry] "=r"(carry)
303 : [x] "r"(x), [y] "r"(y), "0"(carry)
304 : "cc", "memory");
306 return carry;
307 }
308 }
309#endif
310
311 x[0] = word_add(x[0], y[0], &carry);
312 x[1] = word_add(x[1], y[1], &carry);
313 x[2] = word_add(x[2], y[2], &carry);
314 x[3] = word_add(x[3], y[3], &carry);
315 x[4] = word_add(x[4], y[4], &carry);
316 x[5] = word_add(x[5], y[5], &carry);
317 x[6] = word_add(x[6], y[6], &carry);
318 x[7] = word_add(x[7], y[7], &carry);
319 return carry;
320}

References unpoison_asm_output(), and word_add().

Referenced by bigint_add2().

◆ word8_add3()

template<WordType W>
auto Botan::word8_add3 ( W z[8],
const W x[8],
const W y[8],
W carry ) -> W
inlineconstexpr

Definition at line 326 of file mp_asmi.h.

326 {
327#if defined(BOTAN_MP_USE_X86_64_ASM)
328 if constexpr(std::same_as<W, uint64_t>) {
329 if(!std::is_constant_evaluated()) {
330 asm volatile(ADD_OR_SUBTRACT(DO_8_TIMES(ADDSUB3_OP, "adcq"))
331 : [carry] "=r"(carry)
332 : [x] "r"(x), [y] "r"(y), [z] "r"(z), "0"(carry)
333 : "cc", "memory");
335 return carry;
336 }
337 }
338#endif
339
340 z[0] = word_add(x[0], y[0], &carry);
341 z[1] = word_add(x[1], y[1], &carry);
342 z[2] = word_add(x[2], y[2], &carry);
343 z[3] = word_add(x[3], y[3], &carry);
344 z[4] = word_add(x[4], y[4], &carry);
345 z[5] = word_add(x[5], y[5], &carry);
346 z[6] = word_add(x[6], y[6], &carry);
347 z[7] = word_add(x[7], y[7], &carry);
348 return carry;
349}

References unpoison_asm_output(), and word_add().

Referenced by bigint_add3().

◆ word8_linmul3()

template<WordType W>
auto Botan::word8_linmul3 ( W z[8],
const W x[8],
W y,
W carry ) -> W
inlineconstexpr

Definition at line 438 of file mp_asmi.h.

438 {
439#if defined(BOTAN_MP_USE_X86_64_ASM)
440 if constexpr(std::same_as<W, uint64_t>) {
441 if(!std::is_constant_evaluated()) {
442 asm volatile(DO_8_TIMES(LINMUL_OP, "z")
443 : [carry] "=r"(carry)
444 : [z] "r"(z), [x] "r"(x), [y] "rm"(y), "0"(carry)
445 : "cc", "%rax", "%rdx", "memory");
447 return carry;
448 }
449 }
450#endif
451
452 z[0] = word_madd2(x[0], y, &carry);
453 z[1] = word_madd2(x[1], y, &carry);
454 z[2] = word_madd2(x[2], y, &carry);
455 z[3] = word_madd2(x[3], y, &carry);
456 z[4] = word_madd2(x[4], y, &carry);
457 z[5] = word_madd2(x[5], y, &carry);
458 z[6] = word_madd2(x[6], y, &carry);
459 z[7] = word_madd2(x[7], y, &carry);
460 return carry;
461}

References unpoison_asm_output(), and word_madd2().

Referenced by bigint_linmul3().

◆ word8_madd3()

template<WordType W>
auto Botan::word8_madd3 ( W z[8],
const W x[8],
W y,
W carry ) -> W
inlineconstexpr

Definition at line 467 of file mp_asmi.h.

467 {
468#if defined(BOTAN_MP_USE_X86_64_ASM)
469 if constexpr(std::same_as<W, uint64_t>) {
470 if(!std::is_constant_evaluated()) {
471 asm volatile(DO_8_TIMES(MULADD_OP, "")
472 : [carry] "=r"(carry)
473 : [z] "r"(z), [x] "r"(x), [y] "rm"(y), "0"(carry)
474 : "cc", "%rax", "%rdx", "memory");
476 return carry;
477 }
478 }
479#endif
480
481 z[0] = word_madd3(x[0], y, z[0], &carry);
482 z[1] = word_madd3(x[1], y, z[1], &carry);
483 z[2] = word_madd3(x[2], y, z[2], &carry);
484 z[3] = word_madd3(x[3], y, z[3], &carry);
485 z[4] = word_madd3(x[4], y, z[4], &carry);
486 z[5] = word_madd3(x[5], y, z[5], &carry);
487 z[6] = word_madd3(x[6], y, z[6], &carry);
488 z[7] = word_madd3(x[7], y, z[7], &carry);
489 return carry;
490}

References unpoison_asm_output(), and word_madd3().

Referenced by basecase_mul(), and basecase_sqr().

◆ word8_sub2()

template<WordType W>
auto Botan::word8_sub2 ( W x[8],
const W y[8],
W carry ) -> W
inlineconstexpr

Definition at line 380 of file mp_asmi.h.

380 {
381#if defined(BOTAN_MP_USE_X86_64_ASM)
382 if constexpr(std::same_as<W, uint64_t>) {
383 if(!std::is_constant_evaluated()) {
384 asm volatile(ADD_OR_SUBTRACT(DO_8_TIMES(ADDSUB2_OP, "sbbq"))
385 : [carry] "=r"(carry)
386 : [x] "r"(x), [y] "r"(y), "0"(carry)
387 : "cc", "memory");
389 return carry;
390 }
391 }
392#endif
393
394 x[0] = word_sub(x[0], y[0], &carry);
395 x[1] = word_sub(x[1], y[1], &carry);
396 x[2] = word_sub(x[2], y[2], &carry);
397 x[3] = word_sub(x[3], y[3], &carry);
398 x[4] = word_sub(x[4], y[4], &carry);
399 x[5] = word_sub(x[5], y[5], &carry);
400 x[6] = word_sub(x[6], y[6], &carry);
401 x[7] = word_sub(x[7], y[7], &carry);
402 return carry;
403}

References unpoison_asm_output(), and word_sub().

Referenced by bigint_sub2().

◆ word8_sub3()

template<WordType W>
auto Botan::word8_sub3 ( W z[8],
const W x[8],
const W y[8],
W carry ) -> W
inlineconstexpr

Definition at line 409 of file mp_asmi.h.

409 {
410#if defined(BOTAN_MP_USE_X86_64_ASM)
411 if constexpr(std::same_as<W, uint64_t>) {
412 if(!std::is_constant_evaluated()) {
413 asm volatile(ADD_OR_SUBTRACT(DO_8_TIMES(ADDSUB3_OP, "sbbq"))
414 : [carry] "=r"(carry)
415 : [x] "r"(x), [y] "r"(y), [z] "r"(z), "0"(carry)
416 : "cc", "memory");
418 return carry;
419 }
420 }
421#endif
422
423 z[0] = word_sub(x[0], y[0], &carry);
424 z[1] = word_sub(x[1], y[1], &carry);
425 z[2] = word_sub(x[2], y[2], &carry);
426 z[3] = word_sub(x[3], y[3], &carry);
427 z[4] = word_sub(x[4], y[4], &carry);
428 z[5] = word_sub(x[5], y[5], &carry);
429 z[6] = word_sub(x[6], y[6], &carry);
430 z[7] = word_sub(x[7], y[7], &carry);
431 return carry;
432}

References unpoison_asm_output(), and word_sub().

Referenced by bigint_monty_maybe_sub(), bigint_sub3(), and bigint_sub_abs().

◆ word_add()

template<WordType W>
auto Botan::word_add ( W x,
W y,
W * carry ) -> W
inlineconstexpr

Definition at line 260 of file mp_asmi.h.

260 {
261#if BOTAN_COMPILER_HAS_BUILTIN(__builtin_addc)
262 if(!std::is_constant_evaluated()) {
263 if constexpr(std::same_as<W, unsigned int>) {
264 return __builtin_addc(x, y, *carry & 1, carry);
265 } else if constexpr(std::same_as<W, unsigned long>) {
266 return __builtin_addcl(x, y, *carry & 1, carry);
267 } else if constexpr(std::same_as<W, unsigned long long>) {
268 return __builtin_addcll(x, y, *carry & 1, carry);
269 }
270 }
271#endif
272
273 if constexpr(WordInfo<W>::dword_is_native && use_dword_for_word_add) {
274 /*
275 TODO(Botan4) this is largely a performance hack for GCCs that don't
276 support __builtin_addc, if we increase the minimum supported version of
277 GCC to GCC 14 then we can remove this and not worry about it
278 */
279 const W cb = *carry & 1;
280 const auto s = typename WordInfo<W>::dword(x) + y + cb;
281 *carry = static_cast<W>(s >> WordInfo<W>::bits);
282 return static_cast<W>(s);
283 } else {
284 const W cb = *carry & 1;
285 W z = x + y;
286 W c1 = (z < x);
287 z += cb;
288 *carry = c1 | (z < cb);
289 return z;
290 }
291}

Referenced by Botan::BLS12_381::FieldElement::add(), Botan::BLS12_381::Scalar::add(), Botan::Ed25519_FieldElement::add(), Botan::word3< W >::add(), bigint_add2(), bigint_add3(), bigint_cnd_abs(), bigint_cnd_add(), bigint_mulx_sqr(), Botan::BigInt::ct_cond_add(), Botan::IntMod< MontgomeryRep< ScalarParams > >::div2(), Botan::word3< W >::mul(), Botan::word3< W >::mul_x2(), Botan::IntMod< MontgomeryRep< ScalarParams > >::operator+, Botan::IntMod< MontgomeryRep< ScalarParams > >::operator-, solinas_correct_redc(), Botan::BLS12_381::FieldElement::sub(), Botan::BLS12_381::Scalar::sub(), word8_add2(), and word8_add3().

◆ word_madd2()

template<WordType W>
auto Botan::word_madd2 ( W a,
W b,
W * c ) -> W
inlineconstexpr

Definition at line 111 of file mp_asmi.h.

111 {
112#if defined(BOTAN_MP_USE_X86_64_ASM)
113 if constexpr(std::same_as<W, uint64_t>) {
114 if(!std::is_constant_evaluated()) {
115 asm(R"(
116 mulq %[b]
117 addq %[c],%[a]
118 adcq $0,%[carry]
119 )"
120 : [a] "=a"(a), [b] "=rm"(b), [carry] "=&d"(*c)
121 : "0"(a), "1"(b), [c] "g"(*c)
122 : "cc");
123
124 return a;
125 }
126 }
127#elif defined(BOTAN_MP_USE_AARCH64_ASM)
128 if constexpr(std::same_as<W, uint64_t>) {
129 if(!std::is_constant_evaluated()) {
130 W lo = 0;
131 W hi = 0;
132 asm(R"(
133 mul %[lo], %[a], %[b]
134 umulh %[hi], %[a], %[b]
135 adds %[lo], %[lo], %[c]
136 adc %[hi], %[hi], xzr
137 )"
138 : [lo] "=&r"(lo), [hi] "=&r"(hi)
139 : [a] "r"(a), [b] "r"(b), [c] "r"(*c)
140 : "cc");
141
142 *c = hi;
143 return lo;
144 }
145 }
146#endif
147
148 typedef typename WordInfo<W>::dword dword;
149 const dword s = dword(a) * b + *c;
150 *c = static_cast<W>(s >> WordInfo<W>::bits);
151 return static_cast<W>(s);
152}

Referenced by bigint_linmul2(), bigint_linmul3(), bigint_mulx_sqr(), bigint_submul(), Botan::Montgomery_Int::mul_by_word(), reciprocal_word(), redc_crandall(), and word8_linmul3().

◆ word_madd3()

template<WordType W>
auto Botan::word_madd3 ( W a,
W b,
W c,
W * d ) -> W
inlineconstexpr

Definition at line 158 of file mp_asmi.h.

158 {
159#if defined(BOTAN_MP_USE_X86_64_ASM)
160 if constexpr(std::same_as<W, uint64_t>) {
161 if(!std::is_constant_evaluated()) {
162 asm(R"(
163 mulq %[b]
164
165 addq %[c],%[a]
166 adcq $0,%[carry]
167
168 addq %[d],%[a]
169 adcq $0,%[carry]
170 )"
171 : [a] "=a"(a), [b] "=rm"(b), [carry] "=&d"(*d)
172 : "0"(a), "1"(b), [c] "g"(c), [d] "g"(*d)
173 : "cc");
174
175 return a;
176 }
177 }
178#elif defined(BOTAN_MP_USE_AARCH64_ASM)
179 if constexpr(std::same_as<W, uint64_t>) {
180 if(!std::is_constant_evaluated()) {
181 W lo = 0;
182 W hi = 0;
183 asm(R"(
184 mul %[lo], %[a], %[b]
185 umulh %[hi], %[a], %[b]
186 adds %[lo], %[lo], %[c]
187 adc %[hi], %[hi], xzr
188 adds %[lo], %[lo], %[d]
189 adc %[hi], %[hi], xzr
190 )"
191 : [lo] "=&r"(lo), [hi] "=&r"(hi)
192 : [a] "r"(a), [b] "r"(b), [c] "r"(c), [d] "r"(*d)
193 : "cc");
194
195 *d = hi;
196 return lo;
197 }
198 }
199#endif
200
201 typedef typename WordInfo<W>::dword dword;
202 const dword s = dword(a) * b + c + *d;
203 *d = static_cast<W>(s >> WordInfo<W>::bits);
204 return static_cast<W>(s);
205}

Referenced by basecase_mul(), basecase_sqr(), redc_crandall(), and word8_madd3().

◆ word_sub()

template<WordType W>
auto Botan::word_sub ( W x,
W y,
W * carry ) -> W
inlineconstexpr

Definition at line 355 of file mp_asmi.h.

355 {
356#if BOTAN_COMPILER_HAS_BUILTIN(__builtin_subc)
357 if(!std::is_constant_evaluated()) {
358 if constexpr(std::same_as<W, unsigned int>) {
359 return __builtin_subc(x, y, *carry & 1, carry);
360 } else if constexpr(std::same_as<W, unsigned long>) {
361 return __builtin_subcl(x, y, *carry & 1, carry);
362 } else if constexpr(std::same_as<W, unsigned long long>) {
363 return __builtin_subcll(x, y, *carry & 1, carry);
364 }
365 }
366#endif
367
368 const W cb = *carry & 1;
369 W t0 = x - y;
370 W c1 = (t0 > x);
371 W z = t0 - cb;
372 *carry = c1 | (z > t0);
373 return z;
374}

Referenced by bigint_cnd_sub(), bigint_monty_maybe_sub(), bigint_monty_maybe_sub(), bigint_sub2(), bigint_sub2_rev(), bigint_sub3(), bigint_sub_abs(), bigint_submul(), Botan::Ed25519_FieldElement::deserialize(), Botan::Ed25519_Scalar::from_canonical_bytes(), Botan::IntMod< MontgomeryRep< ScalarParams > >::negate(), Botan::Ed25519_Scalar::operator-(), Botan::IntMod< MontgomeryRep< ScalarParams > >::operator-, redc_crandall(), solinas_correct_redc(), Botan::BLS12_381::FieldElement::sub(), Botan::BLS12_381::Scalar::sub(), Botan::Ed25519_FieldElement::sub(), word8_sub2(), and word8_sub3().

◆ words_for_bits()

size_t Botan::words_for_bits ( size_t x)
constexpr

Definition at line 17 of file curve448_scalar.h.

17 {
18 constexpr size_t word_bits = sizeof(word) * 8;
19 return (x + word_bits - 1) / word_bits;
20}

◆ wots_public_key_from_signature()

BOTAN_TEST_API WotsPublicKey Botan::wots_public_key_from_signature ( const SphincsTreeNode & hashed_message,
StrongSpan< const WotsSignature > signature,
const Sphincs_Address & address,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hashes )

FIPS 205, Algorithm 8: wots_pkFromSig.

Reconstructs the WOTS public key from a given WOTS signature and message. This is tailored for the use case in the SLH-DSA implementation and is not meant for general usability in non SLH-DSA algorithms.

Definition at line 81 of file sp_wots.cpp.

85 {
86 const std::vector<WotsHashIndex> lengths = chain_lengths(hashed_message, params);
87 const size_t len = params.wots_len();
88 const size_t n = params.n();
89
90 // The chains start with the nodes in the signature
91 WotsPublicKey pk_buffer(len * n);
92 std::copy(signature.begin(), signature.end(), pk_buffer.begin());
93 const std::span<uint8_t> pk_bytes(pk_buffer.get());
94
95 std::vector<Sphincs_Address> chain_addrs(len, address);
96 for(size_t i = 0; i != len; ++i) {
97 chain_addrs[i].set_chain_address(WotsChainIndex(static_cast<uint32_t>(i)));
98 }
99
100 std::vector<Sphincs_Address> addrs;
101 std::vector<std::span<uint8_t>> outs;
102 std::vector<std::span<const uint8_t>> ins;
103 addrs.reserve(len);
104 outs.reserve(len);
105 ins.reserve(len);
106
107 // Walk the chains in lock-step; chain i joins in once the step counter
108 // reaches its position in the signature
109 for(WotsHashIndex k(0); k < params.w() - 1; k++) {
110 addrs.clear();
111 outs.clear();
112 ins.clear();
113
114 for(size_t i = 0; i != len; ++i) {
115 if(lengths[i] <= k) {
116 chain_addrs[i].set_hash_address(k);
117 addrs.push_back(chain_addrs[i]);
118 const auto node = pk_bytes.subspan(i * n, n);
119 outs.push_back(node);
120 ins.push_back(node);
121 }
122 }
123
124 hashes.T_batch(outs, addrs, ins);
125 }
126
127 return pk_buffer;
128}
uint32_t wots_len() const
decltype(auto) begin() noexcept(noexcept(this->m_span.begin()))
decltype(auto) end() noexcept(noexcept(this->m_span.end()))
Strong< uint8_t, struct WotsHashIndex_, EnableArithmeticWithPlainNumber > WotsHashIndex
Index of a hash application inside a single WOTS chain (integers in "base_w").
Definition sp_types.h:98
Strong< std::vector< uint8_t >, struct WotsPublicKey_ > WotsPublicKey
Definition sp_types.h:73
Strong< uint32_t, struct WotsChainIndex_ > WotsChainIndex
Index of a WOTS chain within a single usage of WOTS.
Definition sp_types.h:95
std::vector< WotsHashIndex > chain_lengths(const SphincsTreeNode &msg, const Sphincs_Parameters &params)
Definition sp_wots.cpp:69

References Botan::detail::Container_Strong_Adapter_Base< T >::begin(), Botan::StrongSpan< T >::begin(), chain_lengths(), Botan::StrongSpan< T >::end(), Botan::detail::Strong_Base< T >::get(), Botan::Sphincs_Parameters::n(), Botan::Sphincs_Hash_Functions::T_batch(), Botan::Sphincs_Parameters::w(), and Botan::Sphincs_Parameters::wots_len().

Referenced by ht_verify().

◆ wots_sign_and_pkgen()

BOTAN_TEST_API void Botan::wots_sign_and_pkgen ( StrongSpan< WotsSignature > sig_out,
std::span< uint8_t > leaves_out,
const SphincsSecretSeed & secret_seed,
TreeNodeIndex first_leaf_idx,
size_t leaf_count,
std::optional< TreeNodeIndex > sign_leaf_idx,
const std::vector< WotsHashIndex > & wots_steps,
Sphincs_Address & leaf_addr,
Sphincs_Address & pk_addr,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hashes )

FIPS 205, Algorithm 6 and 7: wots_pkGen and wots_sign.

Implements a domain specific wrapper for the one-time signature scheme WOTS+ (Winternitz OTS). It is meant to be used inside SLH-DSA and does not aim to be applicable for other use cases. If this function is not used in a signing operation (i.e. sign_leaf_idx is not set), wots_steps may be empty.

Computes the WOTS public key leaves for leaf_count consecutive leaves starting at first_leaf_idx into leaves_out, batching the hash invocations across all leaves' chains. If sign_leaf_idx falls into this range, its WOTS signature is written to sig_out in passing.

Definition at line 130 of file sp_wots.cpp.

140 {
141 // `wots_steps` are needed only if `sign_leaf_idx` is set
142 BOTAN_ASSERT_NOMSG(!sign_leaf_idx.has_value() || wots_steps.size() == params.wots_len());
144 BOTAN_ASSERT_NOMSG(leaves_out.size() == leaf_count * params.n());
145
146 const size_t len = params.wots_len();
147 const size_t n = params.n();
148 const size_t lanes = leaf_count * len;
149
150 // WOTS public key buffers of all leaves, one lane per chain
151 secure_vector<uint8_t> pk_buffers(leaf_count * params.wots_bytes());
152
153 // The chains share their leaf's address except for their chain field
155 leaf_addr.set_hash_address(WotsHashIndex(0));
156
157 std::vector<Sphincs_Address> addrs;
158 addrs.reserve(lanes);
159 std::vector<std::span<uint8_t>> nodes(lanes);
160 std::vector<std::span<const uint8_t>> cnodes(lanes);
161 for(size_t j = 0; j != leaf_count; ++j) {
162 leaf_addr.set_keypair_address(first_leaf_idx + static_cast<uint32_t>(j));
163 for(size_t i = 0; i != len; ++i) {
164 addrs.push_back(leaf_addr);
165 addrs.back().set_chain_address(WotsChainIndex(static_cast<uint32_t>(i)));
166 const auto node = std::span(pk_buffers).subspan((j * len + i) * n, n);
167 nodes[j * len + i] = node;
168 cnodes[j * len + i] = node;
169 }
170 }
171
172 // Start each chain with its secret seed
173 hashes.PRF_batch(nodes, secret_seed, addrs);
174
175 for(auto& addr : addrs) {
176 addr.set_type(Sphincs_Address_Type::WotsHash);
177 }
178
179 const bool signing_in_batch = sign_leaf_idx.has_value() && sign_leaf_idx.value() >= first_leaf_idx &&
180 sign_leaf_idx.value() < first_leaf_idx + static_cast<uint32_t>(leaf_count);
181 const size_t sign_j = signing_in_batch ? static_cast<size_t>(sign_leaf_idx.value().get() - first_leaf_idx.get()) : 0;
182
183 // Iterate down all chains of all leaves in lock-step
184 for(WotsHashIndex k(0);; k++) {
185 // Check for values that need to be saved as a part of the WOTS signature
186 if(signing_in_batch) {
187 for(size_t i = 0; i != len; ++i) {
188 if(wots_steps[i] == k) {
189 copy_mem(sig_out.get().subspan(i * n, n), nodes[sign_j * len + i]);
190 }
191 }
192 }
193
194 // Check if the top of the chains was hit
195 if(k == params.w() - 1) {
196 break;
197 }
198
199 for(auto& addr : addrs) {
200 addr.set_hash_address(k);
201 }
202
203 hashes.T_batch(nodes, addrs, cnodes);
204 }
205
206 // Do the final thashes compressing each leaf's WOTS public key
207 std::vector<Sphincs_Address> pk_addrs;
208 pk_addrs.reserve(leaf_count);
209 std::vector<std::span<uint8_t>> leaf_outs(leaf_count);
210 std::vector<std::span<const uint8_t>> pk_spans(leaf_count);
211 for(size_t j = 0; j != leaf_count; ++j) {
212 pk_addr.set_keypair_address(first_leaf_idx + static_cast<uint32_t>(j));
213 pk_addrs.push_back(pk_addr);
214 leaf_outs[j] = leaves_out.subspan(j * n, n);
215 pk_spans[j] = std::span(pk_buffers).subspan(j * params.wots_bytes(), params.wots_bytes());
216 }
217 hashes.T_batch(leaf_outs, pk_addrs, pk_spans);
218}
Sphincs_Address_Type get_type() const
Definition sp_address.h:134
Sphincs_Address & set_hash_address(WotsHashIndex hash)
Definition sp_address.h:91
Sphincs_Address & set_keypair_address(TreeNodeIndex keypair)
Definition sp_address.h:76

References BOTAN_ASSERT_NOMSG, copy_mem(), Botan::detail::Strong_Base< T >::get(), Botan::StrongSpan< T >::get(), Botan::Sphincs_Address::get_type(), Botan::Sphincs_Parameters::n(), Botan::Sphincs_Hash_Functions::PRF_batch(), Botan::Sphincs_Address::set_hash_address(), Botan::Sphincs_Address::set_keypair_address(), Botan::Sphincs_Address::set_type(), Botan::Sphincs_Hash_Functions::T_batch(), Botan::Sphincs_Parameters::w(), Botan::Sphincs_Parameters::wots_bytes(), Botan::Sphincs_Parameters::wots_len(), WotsHash, WotsKeyGeneration, and WotsPublicKeyCompression.

Referenced by xmss_sign_and_pkgen().

◆ wrap_strong_type()

template<typename T, typename ParamT>
decltype(auto) Botan::wrap_strong_type ( ParamT && t)
nodiscardconstexpr

Wraps a value into a caller-defined (strong) type.

If the provided object t is already of type T, it is returned as is.

Note
This is meant as a helper for generic code that needs to deal with both wrapped strong types and bare objects. Use the ordinary constructor if you know that you are dealing with a bare value type.
Parameters
tvalue to be wrapped
Returns
the wrapped value

Definition at line 144 of file strong_type_helpers.h.

144 {
145 if constexpr(std::same_as<std::remove_cvref_t<ParamT>, T>) {
146 // Noop, if the parameter type already is the desired return type.
147 return std::forward<ParamT>(t);
148 } else if constexpr(std::constructible_from<T, ParamT>) {
149 // Implicit conversion from the parameter type to the return type.
150 return T{std::forward<ParamT>(t)};
151 } else {
152 // Explicitly calling the wrapped type's constructor to support
153 // implicit conversions on types that mark their constructors as explicit.
154 static_assert(concepts::strong_type<T> && std::constructible_from<typename T::wrapped_type, ParamT>);
155 return T{typename T::wrapped_type{std::forward<ParamT>(t)}};
156 }
157}

Referenced by checked_cast_to_or_throw(), Botan::detail::load_any(), Botan::bitvector_base< secure_allocator >::subvector(), and Botan::detail::wrap_strong_type_or_enum().

◆ x25519_basepoint()

void Botan::x25519_basepoint ( std::span< uint8_t, 32 > out,
std::span< const uint8_t, 32 > scalar )

X25519 public key derivation

Clamps the scalar and writes the u-coordinate of [k]B to out, where B is the X25519 base point with u = 9.

Definition at line 38 of file x25519_scalarmult.cpp.

38 {
39 /*
40 * Compute the public key as [k]B on the Ed25519 curve using the fixed-base
41 * tables, then map the result to Curve25519. This gives the same result as
42 * running the Montgomery ladder on u = 9 since the base points correspond
43 * under the birational map and B has order l, but is several times faster.
44 */
45 auto k = x25519_clamp(scalar);
46 const auto s = Ed25519_Scalar::from_bytes(k);
48 secure_scrub_memory(k.data(), k.size());
49}
static Ed25519_Scalar from_bytes(std::span< const uint8_t, BYTES > b)
void ed25519_basepoint_mul_to_x25519(std::span< uint8_t, 32 > out, const Ed25519_Scalar &scalar)

References ed25519_basepoint_mul_to_x25519(), Botan::Ed25519_Scalar::from_bytes(), and secure_scrub_memory().

Referenced by Botan::X25519_PrivateKey::check_key(), Botan::Sodium::crypto_scalarmult_curve25519_base(), and curve25519_basepoint().

◆ x25519_ladder()

BOTAN_FORCE_INLINE void Botan::x25519_ladder ( std::span< uint8_t, 32 > out,
std::span< const uint8_t, 32 > k,
std::span< const uint8_t, 32 > u )

The X25519 Montgomery ladder (RFC 7748 Section 5)

Computes the u-coordinate of [k]P where P is the point with u-coordinate u. The scalar must already be clamped.

Definition at line 345 of file x25519_fe.h.

347 {
348 const auto x1 = X25519_FE::decode(u);
349
350 auto x2 = X25519_FE::one();
351 auto z2 = X25519_FE();
352 auto x3 = x1;
353 auto z3 = X25519_FE::one();
354
355 auto swap = CT::Mask<uint64_t>::cleared();
356
357 // Bit 255 of a clamped scalar is always zero, so start at bit 254
358 for(size_t t = 255; t-- > 0;) {
359 const auto kt = CT::Mask<uint64_t>::expand_bit(static_cast<uint64_t>(k[t / 8]), t % 8);
360 swap = swap ^ kt;
361 X25519_FE::conditional_swap(swap, x2, x3);
362 X25519_FE::conditional_swap(swap, z2, z3);
363 swap = kt;
364
365 const auto A = x2 + z2;
366 const auto B = x2 - z2;
367 const auto C = x3 + z3;
368 const auto D = x3 - z3;
369 const auto AA = A.sqr();
370 const auto BB = B.sqr();
371 const auto E = AA - BB;
372 const auto DA = D * A;
373 const auto CB = C * B;
374
375 x3 = (DA + CB).sqr();
376 z3 = x1 * (DA - CB).sqr();
377 x2 = AA * BB;
378 z2 = E * (AA + E.mul_a24());
379 }
380
381 X25519_FE::conditional_swap(swap, x2, x3);
382 X25519_FE::conditional_swap(swap, z2, z3);
383
384 const auto result = x2 * z2.invert();
385 result.encode(out);
386}
static constexpr Mask< T > expand_bit(T v, size_t bit)
Definition ct_utils.h:426
static constexpr X25519_FE one()
Definition x25519_fe.h:61
static BOTAN_FORCE_INLINE void conditional_swap(CT::Mask< uint64_t > swap, X25519_FE &a, X25519_FE &b)
Definition x25519_fe.h:298
static BOTAN_FORCE_INLINE X25519_FE decode(std::span< const uint8_t, 32 > in)
Definition x25519_fe.h:74

References BOTAN_FORCE_INLINE, Botan::CT::Mask< T >::cleared(), Botan::X25519_FE::conditional_swap(), Botan::X25519_FE::decode(), Botan::CT::Mask< T >::expand_bit(), and Botan::X25519_FE::one().

Referenced by x25519_scalarmult().

◆ x25519_scalarmult()

void Botan::x25519_scalarmult ( std::span< uint8_t, 32 > out,
std::span< const uint8_t, 32 > scalar,
std::span< const uint8_t, 32 > u )

X25519 scalar multiplication (RFC 7748 Section 5)

Clamps the scalar and writes the u-coordinate of [k]P to out, where P is the point with u-coordinate u. The output is all zero if P has low order; callers that want to reject such points must check for this themselves.

Definition at line 30 of file x25519_scalarmult.cpp.

32 {
33 auto k = x25519_clamp(scalar);
34 x25519_ladder(out, k, u);
35 secure_scrub_memory(k.data(), k.size());
36}
BOTAN_FORCE_INLINE void x25519_ladder(std::span< uint8_t, 32 > out, std::span< const uint8_t, 32 > k, std::span< const uint8_t, 32 > u)
Definition x25519_fe.h:345

References secure_scrub_memory(), and x25519_ladder().

Referenced by Botan::X25519_PublicKey::check_key(), Botan::Sodium::crypto_scalarmult_curve25519(), and curve25519_donna().

◆ x448()

Point448 Botan::x448 ( const ScalarX448 & k,
const Point448 & u )

Multiply a scalar k with a point u.

Parameters
kscalar
upoint on curve
Returns
k * u

Definition at line 48 of file x448_internal.cpp.

48 {
49 const Gf448Elem x_1 = Gf448Elem(u.get());
52 Gf448Elem x_3 = Gf448Elem(u.get());
54 auto swap = CT::Mask<uint64_t>::cleared();
55
56 for(int16_t t = 448 - 1; t >= 0; --t) {
57 const auto k_t = CT::Mask<uint64_t>::expand(get_bit(k, t));
58 swap ^= k_t;
59
60 x_2.ct_cond_swap(swap, x_3);
61 z_2.ct_cond_swap(swap, z_3);
62 swap = k_t;
63
64 const auto A = x_2 + z_2;
65 const auto AA = square(A);
66 const auto B = x_2 - z_2;
67 const auto BB = square(B);
68 const auto E = AA - BB;
69 const auto C = x_3 + z_3;
70 const auto D = x_3 - z_3;
71 const auto DA = D * A;
72 const auto CB = C * B;
73 x_3 = square(DA + CB);
74 z_3 = x_1 * square(DA - CB);
75 x_2 = AA * BB;
76 z_2 = E * (AA + mul_a24(E));
77 }
78
79 x_2.ct_cond_swap(swap, x_3);
80 z_2.ct_cond_swap(swap, z_3);
81
82 const auto res = x_2 / z_2;
83
84 return Point448(res.to_bytes());
85}
static Gf448Elem zero()
Definition curve448_gf.h:59
void ct_cond_swap(CT::Mask< uint64_t > mask, Gf448Elem &other)
Swap this and other if mask is set. Constant time.
static Gf448Elem one()
Definition curve448_gf.h:64
Gf448Elem mul_a24(const Gf448Elem &a)
Multiply a field element by the Curve448 constant a24 = 39081.
BigInt square(const BigInt &x)
Definition numthry.cpp:184
Strong< std::array< uint8_t, X448_LEN >, struct Point448_ > Point448

References Botan::CT::Mask< T >::cleared(), Botan::Gf448Elem::ct_cond_swap(), Botan::CT::Mask< T >::expand(), Botan::detail::Strong_Base< T >::get(), mul_a24(), Botan::Gf448Elem::one(), square(), and Botan::Gf448Elem::zero().

Referenced by Botan::X448_PublicKey::check_key(), and x448_basepoint().

◆ x448_basepoint()

Point448 Botan::x448_basepoint ( const ScalarX448 & k)

Multiply a scalar with the base group element (5).

Multiply a scalar with the standard group element (5).

Parameters
kscalar
Returns
encoded point

Definition at line 41 of file x448_internal.cpp.

41 {
42 const Point448 u({5});
43 return x448(k, u);
44}
Point448 x448(const ScalarX448 &k, const Point448 &u)
Multiply a scalar k with a point u.

References x448().

◆ x509_dn_subtree_match()

bool Botan::x509_dn_subtree_match ( const X509_DN & name,
const X509_DN & constraint )

Definition at line 359 of file x509_dn.cpp.

359 {
360 const auto& name_bits = name._canonical_bytes();
361 const auto& constraint_bits = constraint._canonical_bytes();
362
363 if(constraint_bits.size() > name_bits.size()) {
364 return false;
365 }
366
367 return std::equal(constraint_bits.begin(), constraint_bits.end(), name_bits.begin());
368}

References Botan::X509_DN::_canonical_bytes(), and name.

◆ x509_path_validate() [1/4]

Path_Validation_Result Botan::x509_path_validate ( const std::vector< X509_Certificate > & end_certs,
const Path_Validation_Restrictions & restrictions,
const Certificate_Store & store,
std::string_view hostname = "",
Usage_Type usage = Usage_Type::UNSPECIFIED,
std::chrono::system_clock::time_point validation_time = std::chrono::system_clock::now(),
std::chrono::milliseconds ocsp_timeout = std::chrono::milliseconds(0),
const std::vector< std::optional< OCSP::Response > > & ocsp_resp = {} )

PKIX Path Validation

Parameters
end_certscertificate chain to validate
restrictionspath validation restrictions
storestore that contains trusted certificates
hostnameif not empty, compared against the DNS name in end_certs[0]
usageif not set to UNSPECIFIED, compared against the key usage in end_certs[0]
validation_timewhat reference time to use for validation
ocsp_timeouttimeout for OCSP operations, 0 disables OCSP check
ocsp_respadditional OCSP responses to consider (eg from peer)
Returns
result of the path validation

Definition at line 1330 of file x509path.cpp.

1337 {
1338 std::vector<Certificate_Store*> trusted_roots;
1339 trusted_roots.push_back(const_cast<Certificate_Store*>(&store));
1340
1341 return x509_path_validate(end_certs, restrictions, trusted_roots, hostname, usage, when, ocsp_timeout, ocsp_resp);
1342}
Path_Validation_Result x509_path_validate(const std::vector< X509_Certificate > &end_certs, const Path_Validation_Restrictions &restrictions, const std::vector< Certificate_Store * > &trusted_roots, std::string_view hostname, Usage_Type usage, std::chrono::system_clock::time_point ref_time, std::chrono::milliseconds ocsp_timeout, const std::vector< std::optional< OCSP::Response > > &ocsp_resp)

References x509_path_validate().

◆ x509_path_validate() [2/4]

Path_Validation_Result Botan::x509_path_validate ( const std::vector< X509_Certificate > & end_certs,
const Path_Validation_Restrictions & restrictions,
const std::vector< Certificate_Store * > & trusted_roots,
std::string_view hostname = "",
Usage_Type usage = Usage_Type::UNSPECIFIED,
std::chrono::system_clock::time_point validation_time = std::chrono::system_clock::now(),
std::chrono::milliseconds ocsp_timeout = std::chrono::milliseconds(0),
const std::vector< std::optional< OCSP::Response > > & ocsp_resp = {} )

PKIX Path Validation

Parameters
end_certscertificate chain to validate (with end entity certificate in end_certs[0])
restrictionspath validation restrictions
trusted_rootslist of certificate stores that contain trusted certificates
hostnameif not empty, compared against the DNS name in end_certs[0]
usageif not set to UNSPECIFIED, compared against the key usage in end_certs[0]
validation_timewhat reference time to use for validation
ocsp_timeouttimeout for OCSP operations, 0 disables OCSP check
ocsp_respadditional OCSP responses to consider (eg from peer)
Returns
result of the path validation

Definition at line 1198 of file x509path.cpp.

1205 {
1206 if(end_certs.empty()) {
1207 throw Invalid_Argument("x509_path_validate called with no subjects");
1208 }
1209
1210 const X509_Certificate& end_entity = end_certs[0];
1211 const auto end_entity_extra = std::span<const X509_Certificate>(end_certs).subspan(1);
1212
1213 const bool require_self_signed = restrictions.require_self_signed_trust_anchors();
1214
1215 CertificatePathBuilder builder(
1216 trusted_roots, end_entity, end_entity_extra, PathBuildingDfsBudget, require_self_signed);
1217
1218 std::optional<Path_Validation_Result> first_path_error;
1219 size_t paths_checked = 0;
1220 size_t certs_checked = 0;
1221
1222 while(auto cert_path = builder.next()) {
1223 BOTAN_ASSERT_NOMSG(cert_path->empty() == false);
1224
1225 if(cert_path->size() > PathBuildingMaximumChainLength) {
1226 continue;
1227 }
1228
1229 paths_checked += 1;
1230 certs_checked += cert_path->size();
1231 if(paths_checked > PathBuildingMaxPathsExamined || certs_checked > PathBuildingVerificationBudget) {
1233 break;
1234 }
1235
1236 CertificatePathStatusCodes status = PKIX::check_chain(*cert_path, ref_time, hostname, usage, restrictions);
1237
1238 // Skip revocation checks if the chain already has fatal errors.
1240 const CertificatePathStatusCodes crl_status =
1241 PKIX::check_crl(*cert_path, trusted_roots, ref_time, restrictions);
1242
1243 CertificatePathStatusCodes ocsp_status;
1244
1245 if(!ocsp_resp.empty()) {
1246 ocsp_status = PKIX::check_ocsp(*cert_path, ocsp_resp, trusted_roots, ref_time, restrictions);
1247 }
1248
1249 if(ocsp_timeout != std::chrono::milliseconds(0)) {
1250 const size_t to_online = restrictions.ocsp_all_intermediates() ? (cert_path->size() - 1) : 1;
1251 bool need_online = false;
1252 for(size_t i = 0; i < to_online; ++i) {
1253 if((*cert_path)[i].skip_revocation_check()) {
1254 continue;
1255 }
1256 if(i >= ocsp_status.size() || ocsp_status[i].empty()) {
1257 need_online = true;
1258 break;
1259 }
1260 }
1261
1262 if(need_online) {
1263#if defined(BOTAN_TARGET_OS_HAS_THREADS) && defined(BOTAN_HAS_HTTP_UTIL)
1264 auto online_status =
1265 PKIX::check_ocsp_online(*cert_path, trusted_roots, ref_time, ocsp_timeout, restrictions);
1266 if(ocsp_status.size() < online_status.size()) {
1267 ocsp_status.resize(online_status.size());
1268 }
1269 for(size_t i = 0; i < online_status.size(); ++i) {
1270 if(ocsp_status[i].empty()) {
1271 ocsp_status[i] = std::move(online_status[i]);
1272 }
1273 }
1274#else
1275 if(ocsp_status.size() < to_online) {
1276 ocsp_status.resize(to_online);
1277 }
1278 for(size_t i = 0; i < to_online; ++i) {
1279 if(ocsp_status[i].empty()) {
1280 ocsp_status[i].insert(Certificate_Status_Code::OCSP_NO_HTTP);
1281 }
1282 }
1283#endif
1284 }
1285 }
1286
1287 PKIX::merge_revocation_status(status, crl_status, ocsp_status, restrictions);
1288
1289 // merge_revocation_status flags NO_REVOCATION_DATA when require_revocation
1290 // is set; clear it for certs where RFC 9608 Section 4 says to skip the check.
1291 for(size_t i = 0; i + 1 < cert_path->size() && i < status.size(); ++i) {
1292 if((*cert_path)[i].skip_revocation_check()) {
1294 }
1295 }
1296 }
1297
1298 Path_Validation_Result pvd(status, std::move(*cert_path));
1299 if(pvd.successful_validation()) {
1300 return pvd;
1301 } else if(!first_path_error.has_value()) {
1302 // Save the errors from the first path we attempted
1303 first_path_error = std::move(pvd);
1304 }
1305 }
1306
1307 if(first_path_error.has_value()) {
1308 // We found at least one path, but none of them verified
1309 // Return arbitrarily the error from the first path attempted
1310 return first_path_error.value();
1311 } else {
1312 // Failed to build any path at all
1313 return Path_Validation_Result(builder.error());
1314 }
1315}
bool require_self_signed_trust_anchors() const
Definition x509path.h:175
void merge_revocation_status(CertificatePathStatusCodes &chain_status, const CertificatePathStatusCodes &crl_status, const CertificatePathStatusCodes &ocsp_status, const Path_Validation_Restrictions &restrictions)
CertificatePathStatusCodes check_crl(const std::vector< X509_Certificate > &cert_path, const std::vector< std::optional< X509_CRL > > &crls, std::chrono::system_clock::time_point ref_time, const Path_Validation_Restrictions &restrictions)
Definition x509path.cpp:744
Certificate_Status_Code overall_status(const CertificatePathStatusCodes &cert_status)
CertificatePathStatusCodes check_ocsp(const std::vector< X509_Certificate > &cert_path, const std::vector< std::optional< OCSP::Response > > &ocsp_responses, const std::vector< Certificate_Store * > &certstores, std::chrono::system_clock::time_point ref_time, const Path_Validation_Restrictions &restrictions)
Definition x509path.cpp:705
CertificatePathStatusCodes check_chain(const std::vector< X509_Certificate > &cert_path, std::chrono::system_clock::time_point ref_time, std::string_view hostname, Usage_Type usage, const Path_Validation_Restrictions &restrictions)
Definition x509path.cpp:344
std::vector< std::set< Certificate_Status_Code > > CertificatePathStatusCodes
Definition x509path.h:29

References BOTAN_ASSERT_NOMSG, Botan::PKIX::check_chain(), Botan::PKIX::check_crl(), Botan::PKIX::check_ocsp(), EXCEEDED_SEARCH_LIMITS, FIRST_ERROR_STATUS_TO_SKIP_REVOCATION, Botan::PKIX::merge_revocation_status(), NO_REVOCATION_DATA, Botan::Path_Validation_Restrictions::ocsp_all_intermediates(), OCSP_NO_HTTP, Botan::PKIX::overall_status(), Botan::Path_Validation_Restrictions::require_self_signed_trust_anchors(), and Botan::Path_Validation_Result::successful_validation().

Referenced by botan_x509_cert_verify(), botan_x509_cert_verify_with_crl(), Botan::TLS::Callbacks::tls_verify_cert_chain(), x509_path_validate(), x509_path_validate(), and x509_path_validate().

◆ x509_path_validate() [3/4]

Path_Validation_Result Botan::x509_path_validate ( const X509_Certificate & end_cert,
const Path_Validation_Restrictions & restrictions,
const Certificate_Store & store,
std::string_view hostname = "",
Usage_Type usage = Usage_Type::UNSPECIFIED,
std::chrono::system_clock::time_point validation_time = std::chrono::system_clock::now(),
std::chrono::milliseconds ocsp_timeout = std::chrono::milliseconds(0),
const std::vector< std::optional< OCSP::Response > > & ocsp_resp = {} )

PKIX Path Validation

Parameters
end_certcertificate to validate
restrictionspath validation restrictions
storestore that contains trusted certificates
hostnameif not empty, compared against the DNS name in end_cert
usageif not set to UNSPECIFIED, compared against the key usage in end_cert
validation_timewhat reference time to use for validation
ocsp_timeouttimeout for OCSP operations, 0 disables OCSP check
ocsp_respadditional OCSP responses to consider (eg from peer)
Returns
result of the path validation

Definition at line 1344 of file x509path.cpp.

1351 {
1352 std::vector<X509_Certificate> certs;
1353 certs.push_back(end_cert);
1354
1355 std::vector<Certificate_Store*> trusted_roots;
1356 trusted_roots.push_back(const_cast<Certificate_Store*>(&store));
1357
1358 return x509_path_validate(certs, restrictions, trusted_roots, hostname, usage, when, ocsp_timeout, ocsp_resp);
1359}

References x509_path_validate().

◆ x509_path_validate() [4/4]

Path_Validation_Result Botan::x509_path_validate ( const X509_Certificate & end_cert,
const Path_Validation_Restrictions & restrictions,
const std::vector< Certificate_Store * > & trusted_roots,
std::string_view hostname = "",
Usage_Type usage = Usage_Type::UNSPECIFIED,
std::chrono::system_clock::time_point validation_time = std::chrono::system_clock::now(),
std::chrono::milliseconds ocsp_timeout = std::chrono::milliseconds(0),
const std::vector< std::optional< OCSP::Response > > & ocsp_resp = {} )

PKIX Path Validation

Parameters
end_certcertificate to validate
restrictionspath validation restrictions
trusted_rootslist of stores that contain trusted certificates
hostnameif not empty, compared against the DNS name in end_cert
usageif not set to UNSPECIFIED, compared against the key usage in end_cert
validation_timewhat reference time to use for validation
ocsp_timeouttimeout for OCSP operations, 0 disables OCSP check
ocsp_respadditional OCSP responses to consider (eg from peer)
Returns
result of the path validation

Definition at line 1317 of file x509path.cpp.

1324 {
1325 std::vector<X509_Certificate> certs;
1326 certs.push_back(end_cert);
1327 return x509_path_validate(certs, restrictions, trusted_roots, hostname, usage, when, ocsp_timeout, ocsp_resp);
1328}

References x509_path_validate().

◆ xmss_concat() [1/2]

template<std::unsigned_integral T>
void Botan::xmss_concat ( secure_vector< uint8_t > & target,
const T & src )

Concatenates the byte representation in big-endian order of any integral value to a secure_vector.

Parameters
targetVector to concatenate the byte representation of the integral value to.
srcintegral value to concatenate.

Definition at line 28 of file xmss_tools.h.

28 {
29 const uint8_t* src_bytes = reinterpret_cast<const uint8_t*>(&src);
30 if constexpr(std::endian::native == std::endian::little) {
31 std::reverse_copy(src_bytes, src_bytes + sizeof(src), std::back_inserter(target));
32 } else {
33 std::copy(src_bytes, src_bytes + sizeof(src), std::back_inserter(target));
34 }
35}

Referenced by Botan::XMSS_Signature_Operation::sign().

◆ xmss_concat() [2/2]

template<std::unsigned_integral T>
void Botan::xmss_concat ( secure_vector< uint8_t > & target,
const T & src,
size_t len )

Concatenates the last n bytes of the byte representation in big-endian order of any integral value to a to a secure_vector.

Parameters
targetVector to concatenate the byte representation of the integral value to.
srcIntegral value to concatenate.
lennumber of bytes to concatenate. This value must be smaller or equal to the size of type T.

Definition at line 48 of file xmss_tools.h.

48 {
49 const size_t c = static_cast<size_t>(std::min(len, sizeof(src)));
50 if(len > sizeof(src)) {
51 target.resize(target.size() + len - sizeof(src), 0);
52 }
53
54 const uint8_t* src_bytes = reinterpret_cast<const uint8_t*>(&src);
55 if constexpr(std::endian::native == std::endian::little) {
56 std::reverse_copy(src_bytes, src_bytes + c, std::back_inserter(target));
57 } else {
58 std::copy(src_bytes + sizeof(src) - c, src_bytes + sizeof(src), std::back_inserter(target));
59 }
60}

◆ xmss_gen_root()

SphincsTreeNode Botan::xmss_gen_root ( const Sphincs_Parameters & params,
const SphincsSecretSeed & secret_seed,
Sphincs_Hash_Functions & hashes )

Compute the XMSS public key (root node) of the top-most subtree. Contains logic of FIPS 205, Algorithm 18: slh_keygen_internal

Definition at line 75 of file sp_xmss.cpp.

77 {
78 // We do not need the a sig/auth path in key generation, but it simplifies the
79 // code to have just one treehash routine that computes both root and path
80 // in one function.
81 SphincsXmssSignature dummy_sig(params.xmss_tree_height() * params.n() + params.wots_bytes());
82 const SphincsTreeNode dummy_root(params.n());
83
86
87 top_tree_addr.set_layer_address(HypertreeLayerIndex(params.d() - 1));
88 wots_addr.set_layer_address(HypertreeLayerIndex(params.d() - 1));
89
91 xmss_sign_and_pkgen(dummy_sig, dummy_root, secret_seed, wots_addr, top_tree_addr, std::nullopt, params, hashes);
92
93 return root;
94}
Gf448Elem root(const Gf448Elem &elem)
Compute the root of elem in the field.

References Botan::Sphincs_Parameters::d(), HashTree, Botan::Sphincs_Parameters::n(), root(), Botan::Sphincs_Address::set_layer_address(), Botan::Sphincs_Parameters::wots_bytes(), WotsPublicKeyCompression, xmss_sign_and_pkgen(), and Botan::Sphincs_Parameters::xmss_tree_height().

Referenced by Botan::SphincsPlus_PrivateKey::check_key(), and Botan::SphincsPlus_PrivateKey::SphincsPlus_PrivateKey().

◆ xmss_sign_and_pkgen()

SphincsTreeNode Botan::xmss_sign_and_pkgen ( StrongSpan< SphincsXmssSignature > out_sig,
const SphincsTreeNode & message,
const SphincsSecretSeed & secret_seed,
const Sphincs_Address & wots_addr,
Sphincs_Address & tree_addr,
std::optional< TreeNodeIndex > idx_leaf,
const Sphincs_Parameters & params,
Sphincs_Hash_Functions & hashes )

FIPS 205, Algorithm 10: xmss_sign.

This generates a Merkle signature of message (i.e. a FORS public key (bottom layer) or an XMSS root node). The Merkle authentication path logic is mostly hidden in treehash_spec. The WOTS signature followed by the Merkle authentication path are stored in out_sig. Set idx_leaf to std::nullopt if no signature is desired.

Returns
the XMSS public key (i.e. the root of the XMSS merkle tree)

Definition at line 19 of file sp_xmss.cpp.

26 {
27 BufferStuffer sig(out_sig);
28 auto wots_bytes_s = sig.next<WotsSignature>(params.wots_bytes());
29 const auto auth_path_s = sig.next<SphincsAuthenticationPath>(sig.remaining_capacity());
30
31 const auto steps = [&]() -> std::vector<WotsHashIndex> {
32 // if `idx_leaf` is not set, we don't want to calculate a signature and
33 // therefore won't need to bother preparing the chain lengths either.
34 if(idx_leaf.has_value()) {
35 return chain_lengths(message, params);
36 } else {
37 return {};
38 };
39 }();
40
43
45
46 // Each leaf is a full WOTS+ key generation; the hashing is batched over
47 // all chains of a group of leaves at once. The group size bounds the
48 // WOTS public key scratch while still offering wide hash batches.
49 const GenerateLeavesFunction xmss_gen_leaves =
50 [&](std::span<uint8_t> out_leaves, TreeNodeIndex first_idx, uint32_t count) {
51 constexpr uint32_t leaf_group = 128;
52 for(uint32_t j = 0; j < count; j += leaf_group) {
53 const uint32_t leaves = std::min(leaf_group, count - j);
54 wots_sign_and_pkgen(wots_bytes_s,
55 out_leaves.subspan(j * params.n(), leaves * params.n()),
56 secret_seed,
57 first_idx + j,
58 leaves,
59 idx_leaf,
60 steps,
61 leaf_addr,
62 pk_addr,
63 params,
64 hashes);
65 }
66 };
67
68 SphincsTreeNode next_root(params.n());
70 treehash(next_root, auth_path_s, params, hashes, idx_leaf, 0, params.xmss_tree_height(), xmss_gen_leaves, tree_addr);
71
72 return next_root;
73}
static Sphincs_Address as_subtree_from(const Sphincs_Address &other)
Definition sp_address.h:112
void wots_sign_and_pkgen(StrongSpan< WotsSignature > sig_out, std::span< uint8_t > leaves_out, const SphincsSecretSeed &secret_seed, TreeNodeIndex first_leaf_idx, size_t leaf_count, std::optional< TreeNodeIndex > sign_leaf_idx, const std::vector< WotsHashIndex > &wots_steps, Sphincs_Address &leaf_addr, Sphincs_Address &pk_addr, const Sphincs_Parameters &params, Sphincs_Hash_Functions &hashes)
FIPS 205, Algorithm 6 and 7: wots_pkGen and wots_sign.
Definition sp_wots.cpp:130

References Botan::Sphincs_Address::as_subtree_from(), BOTAN_ASSERT_NOMSG, chain_lengths(), Botan::Sphincs_Address::get_type(), HashTree, Botan::Sphincs_Parameters::n(), Botan::BufferStuffer::next(), Botan::BufferStuffer::remaining_capacity(), Botan::Sphincs_Address::set_type(), treehash(), Botan::Sphincs_Parameters::wots_bytes(), wots_sign_and_pkgen(), WotsPublicKeyCompression, and Botan::Sphincs_Parameters::xmss_tree_height().

Referenced by ht_sign(), and xmss_gen_root().

◆ xmss_wots_chains()

void Botan::xmss_wots_chains ( const XMSS_WOTS_Parameters & params,
std::span< uint8_t > nodes,
std::span< const uint8_t > from,
std::span< const uint8_t > to,
std::span< XMSS_Address > addrs,
std::span< const uint8_t > seed,
XMSS_Hash & hash )

Algorithm 2: Chaining Function, applied to many WOTS+ chains in lock-step.

For each chain i the hash addresses [from[i], to[i]) are applied to the i'th n-byte node of nodes, batching the hash calls across all chains active in each step.

Parameters
paramsThe WOTS parameters to use
[in,out]nodesThe chain nodes, transformed in place
fromPer chain, the first hash address to apply
toPer chain, the hash address to stop at (exclusive)
[in,out]addrsPer chain, its OTS hash address with the chain address set. The hash address and key/mask mode are modified.
SEEDThe public seed
HashesInstance of XMSS_Hash, that may only be used by the thread executing xmss_wots_chains.

Definition at line 112 of file xmss_wots.cpp.

118 {
119 const size_t count = addrs.size();
120 const size_t n = hash.output_length();
121
122 BOTAN_ASSERT_NOMSG(nodes.size() == count * n);
123 BOTAN_ASSERT_NOMSG(from.size() == count && to.size() == count);
124
125 for(size_t i = 0; i < count; ++i) {
126 BOTAN_ASSERT_NOMSG(to[i] < params.wots_parameter());
127 }
128
129 // Each step computes the bitmask and the key of every active chain
130 // with a single PRF batch. The addresses differ only in the key/mask
131 // mode, so a second set of addresses in mask mode is kept alongside.
132 std::vector<XMSS_Address> mask_addrs(addrs.begin(), addrs.end());
133 for(size_t i = 0; i < count; ++i) {
134 mask_addrs[i].set_key_mask_mode(XMSS_Address::Key_Mask::Mask_Mode);
135 addrs[i].set_key_mask_mode(XMSS_Address::Key_Mask::Key_Mode);
136 }
137
138 // Lane descriptors for the case that every chain is active; the
139 // bitmasks are lanes [0, count) and the keys lanes [count, 2*count).
140 // The address bytes are updated in place each step so the spans
141 // stay valid throughout. The filtered variants are subsets of these.
142 secure_vector<uint8_t> prf_outputs(2 * count * n);
143 std::vector<std::span<uint8_t>> all_prf_out(2 * count);
144 std::vector<std::span<const uint8_t>> all_prf_in(2 * count);
145 std::vector<std::span<uint8_t>> all_node(count);
146 std::vector<std::span<const uint8_t>> all_key(count);
147 std::vector<std::span<const uint8_t>> all_node_in(count);
148
149 for(size_t i = 0; i < count; ++i) {
150 all_prf_out[i] = std::span(prf_outputs).subspan(i * n, n);
151 all_prf_out[count + i] = std::span(prf_outputs).subspan((count + i) * n, n);
152 all_prf_in[i] = mask_addrs[i].bytes();
153 all_prf_in[count + i] = addrs[i].bytes();
154 all_node[i] = nodes.subspan(i * n, n);
155 all_key[i] = all_prf_out[count + i];
156 all_node_in[i] = all_node[i];
157 }
158
159 std::vector<size_t> active;
160 std::vector<std::span<uint8_t>> prf_out;
161 std::vector<std::span<const uint8_t>> prf_in;
162 std::vector<std::span<uint8_t>> node_out;
163 std::vector<std::span<const uint8_t>> keys;
164 std::vector<std::span<const uint8_t>> node_in;
165
166 for(size_t s = 0; s + 1 < params.wots_parameter(); ++s) {
167 active.clear();
168 for(size_t i = 0; i < count; ++i) {
169 if(from[i] <= s && s < to[i]) {
170 active.push_back(i);
171 }
172 }
173 if(active.empty()) {
174 continue;
175 }
176
177 for(const size_t i : active) {
178 addrs[i].set_hash_address(static_cast<uint32_t>(s));
179 mask_addrs[i].set_hash_address(static_cast<uint32_t>(s));
180 }
181
182 if(active.size() == count) {
183 hash.prf_batch(all_prf_out, seed, all_prf_in);
184
185 // Calculate tmp XOR bitmask, then f(key, tmp XOR bitmask)
186 for(size_t i = 0; i < count; ++i) {
187 xor_buf(all_node[i], all_prf_out[i]);
188 }
189 hash.f_batch(all_node, all_key, all_node_in);
190 } else {
191 prf_out.clear();
192 prf_in.clear();
193 node_out.clear();
194 keys.clear();
195 node_in.clear();
196
197 for(const size_t i : active) {
198 prf_out.push_back(all_prf_out[i]);
199 prf_in.push_back(all_prf_in[i]);
200 }
201 for(const size_t i : active) {
202 prf_out.push_back(all_prf_out[count + i]);
203 prf_in.push_back(all_prf_in[count + i]);
204 }
205 hash.prf_batch(prf_out, seed, prf_in);
206
207 for(const size_t i : active) {
208 xor_buf(all_node[i], all_prf_out[i]);
209 node_out.push_back(all_node[i]);
210 keys.push_back(all_key[i]);
211 node_in.push_back(all_node_in[i]);
212 }
213 hash.f_batch(node_out, keys, node_in);
214 }
215 }
216}
size_t output_length() const
Definition xmss_hash.h:196
void prf_batch(std::span< std::span< uint8_t > > outputs, std::span< const uint8_t > key, std::span< std::span< const uint8_t > > data)
Definition xmss_hash.h:153
void f_batch(std::span< std::span< uint8_t > > outputs, std::span< std::span< const uint8_t > > keys, std::span< std::span< const uint8_t > > data)
Definition xmss_hash.h:171

References BOTAN_ASSERT_NOMSG, Botan::XMSS_Hash::f_batch(), Botan::XMSS_Address::Key_Mode, Botan::XMSS_Address::Mask_Mode, Botan::XMSS_Hash::output_length(), Botan::XMSS_Hash::prf_batch(), Botan::XMSS_WOTS_Parameters::wots_parameter(), and xor_buf().

◆ xor_buf() [1/7]

void Botan::xor_buf ( ranges::contiguous_output_range< uint8_t > auto && out,
ranges::contiguous_range< uint8_t > auto && in )
inlineconstexpr

XOR arrays. Postcondition out[i] = in[i] ^ out[i] forall i = 0...length

Parameters
outthe input/output range
inthe read-only input range

Definition at line 403 of file mem_ops.h.

404 {
406
407 std::span<uint8_t> o(out);
408 std::span<const uint8_t> i(in);
409
410 for(; o.size_bytes() >= 32; o = o.subspan(32), i = i.subspan(32)) {
411 auto x = typecast_copy<std::array<uint64_t, 4>>(o.template first<32>());
412 const auto y = typecast_copy<std::array<uint64_t, 4>>(i.template first<32>());
413
414 x[0] ^= y[0];
415 x[1] ^= y[1];
416 x[2] ^= y[2];
417 x[3] ^= y[3];
418
419 typecast_copy(o.template first<32>(), x);
420 }
421
422 for(size_t off = 0; off != o.size_bytes(); ++off) {
423 o[off] ^= i[off];
424 }
425}

References Botan::ranges::assert_equal_byte_lengths(), and typecast_copy().

Referenced by Botan::TLS::Connection_Cipher_State::aead_nonce(), Botan::TLS::Connection_Cipher_State::aead_nonce(), Botan::Salsa20::cipher_bytes(), Botan::GCM_SIV_Mode::compute_tag(), Botan::XMSS_Common_Ops::create_l_trees(), Botan::GCM_SIV_Mode::ctr_xor(), Botan::Lion::decrypt_n(), Botan::Lion::encrypt_n(), Botan::GHASH::final(), mgf1_mask(), operator^(), Botan::OctetString::operator^=(), operator^=(), pbkdf2(), Botan::SIV_Mode::S2V(), xmss_wots_chains(), xor_buf(), xor_buf(), xor_buf(), xor_buf(), and xor_buf().

◆ xor_buf() [2/7]

void Botan::xor_buf ( ranges::contiguous_output_range< uint8_t > auto && out,
ranges::contiguous_range< uint8_t > auto && in1,
ranges::contiguous_range< uint8_t > auto && in2 )
inlineconstexpr

XOR arrays. Postcondition out[i] = in1[i] ^ in2[i] forall i = 0...length

Parameters
outthe output range
in1the first input range
in2the second input range

Definition at line 433 of file mem_ops.h.

435 {
437
438 std::span o{out};
439 std::span i1{in1};
440 std::span i2{in2};
441
442 for(; o.size_bytes() >= 32; o = o.subspan(32), i1 = i1.subspan(32), i2 = i2.subspan(32)) {
443 auto x = typecast_copy<std::array<uint64_t, 4>>(i1.template first<32>());
444 const auto y = typecast_copy<std::array<uint64_t, 4>>(i2.template first<32>());
445
446 x[0] ^= y[0];
447 x[1] ^= y[1];
448 x[2] ^= y[2];
449 x[3] ^= y[3];
450
451 typecast_copy(o.template first<32>(), x);
452 }
453
454 for(size_t off = 0; off != o.size_bytes(); ++off) {
455 o[off] = i1[off] ^ i2[off];
456 }
457}

References Botan::ranges::assert_equal_byte_lengths(), and typecast_copy().

◆ xor_buf() [3/7]

void Botan::xor_buf ( std::span< uint8_t > out,
std::span< const uint8_t > in,
size_t n )
inline

XOR the first n bytes of in into out

Parameters
outthe buffer to XOR into, must hold at least n bytes
inthe buffer to read from, must hold at least n bytes
nthe number of bytes to XOR

Definition at line 489 of file mem_ops.h.

489 {
490 BOTAN_ARG_CHECK(out.size() >= n, "output span is too small");
491 BOTAN_ARG_CHECK(in.size() >= n, "input span is too small");
492 xor_buf(out.first(n), in.first(n));
493}

References BOTAN_ARG_CHECK, and xor_buf().

◆ xor_buf() [4/7]

template<typename Alloc, typename Alloc2>
void Botan::xor_buf ( std::vector< uint8_t, Alloc > & out,
const uint8_t * in,
const std::vector< uint8_t, Alloc2 > & in2,
size_t n )

Set the front of a vector to the XOR of two inputs

Parameters
outthe vector to write into, must hold at least n bytes
inthe first input, must point to at least n bytes
in2the second input, must hold at least n bytes
nthe number of bytes to process

Definition at line 518 of file mem_ops.h.

518 {
519 BOTAN_ARG_CHECK(out.size() >= n, "output vector is too small");
520 BOTAN_ARG_CHECK(in2.size() >= n, "input vector is too small");
521 // simply assumes that *in points to "n" allocated bytes at least
522 xor_buf(std::span{out}.first(n), std::span{in, n}, std::span{in2}.first(n));
523}

References BOTAN_ARG_CHECK, and xor_buf().

◆ xor_buf() [5/7]

template<typename Alloc>
void Botan::xor_buf ( std::vector< uint8_t, Alloc > & out,
const uint8_t * in,
size_t n )

XOR n bytes into the front of a vector

Parameters
outthe vector to XOR into, must hold at least n bytes
inthe bytes to read from, must point to at least n bytes
nthe number of bytes to XOR

Definition at line 503 of file mem_ops.h.

503 {
504 BOTAN_ARG_CHECK(out.size() >= n, "output vector is too small");
505 // simply assumes that *in points to "n" allocated bytes at least
506 xor_buf(std::span{out}.first(n), std::span{in, n});
507}

References BOTAN_ARG_CHECK, and xor_buf().

◆ xor_buf() [6/7]

void Botan::xor_buf ( uint8_t out[],
const uint8_t in[],
const uint8_t in2[],
size_t length )
inline

XOR arrays. Postcondition out[i] = in[i] ^ in2[i] forall i = 0...length

Parameters
outthe output buffer
inthe first input buffer
in2the second input buffer
lengththe length of the three buffers

Definition at line 477 of file mem_ops.h.

477 {
478 // simply assumes that *out, *in, and *in2 point to "length" allocated bytes at least
479 xor_buf(std::span{out, length}, std::span{in, length}, std::span{in2, length});
480}

References xor_buf().

◆ xor_buf() [7/7]

void Botan::xor_buf ( uint8_t out[],
const uint8_t in[],
size_t length )
inline

XOR arrays. Postcondition out[i] = in[i] ^ out[i] forall i = 0...length

Parameters
outthe input/output buffer
inthe read-only input buffer
lengththe length of the buffers

Definition at line 465 of file mem_ops.h.

465 {
466 // simply assumes that *out and *in point to "length" allocated bytes at least
467 xor_buf(std::span{out, length}, std::span{in, length});
468}

References xor_buf().

◆ xts_compute_tweak_block()

void Botan::xts_compute_tweak_block ( uint8_t tweak[],
size_t BS,
size_t blocks_in_tweak )

Definition at line 119 of file poly_dbl.cpp.

119 {
120 BOTAN_ASSERT_NOMSG(blocks_in_tweak > 0);
121
122 if(BS == 16) {
123 constexpr size_t LIMBS = 2;
124
125 uint64_t W[LIMBS];
126 load_le(W, &tweak[0], LIMBS);
127
128 for(size_t i = 1; i < blocks_in_tweak; ++i) {
129 const uint64_t carry = return_carry<MinWeightPolynomial::P128>(W[1]);
130 W[1] = (W[1] << 1) ^ (W[0] >> 63);
131 W[0] = (W[0] << 1) ^ carry;
132 copy_out_le(std::span(&tweak[i * BS], 2 * 8), W);
133 }
134 } else {
135 for(size_t i = 1; i < blocks_in_tweak; ++i) {
136 const uint8_t* prev = &tweak[(i - 1) * BS];
137 uint8_t* cur = &tweak[i * BS];
138 poly_double_n_le(cur, prev, BS);
139 }
140 }
141}
void copy_out_le(std::span< uint8_t > out, const InR &in)
Definition loadstor.h:789
void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n)
Definition poly_dbl.cpp:100

References BOTAN_ASSERT_NOMSG, copy_out_le(), load_le(), and poly_double_n_le().

Referenced by Botan::XTS_Mode::update_tweak().

◆ zap()

template<typename T, typename Alloc>
void Botan::zap ( std::vector< T, Alloc > & vec)

Zeroise the values then free the memory

TODO(Botan4): make these not-inlined and only for secure_vector, eg declare void zap(secure_vector<uint8_t>& v); void zap(secure_vector<uint16_t>& v); void zap(secure_vector<uint32_t>& v); void zap(secure_vector<uint64_t>& v);

[And maybe rename as well]

Parameters
vecthe vector to zeroise and free

Definition at line 261 of file secmem.h.

261 {
262 zeroise(vec);
263 vec.clear();
264 vec.shrink_to_fit();
265}
void zeroise(std::vector< T, Alloc > &vec)
Definition secmem.h:241

References zeroise().

Referenced by Botan::TLS::Cipher_State::advance_with_client_finished(), Botan::TLS::Cipher_State::advance_with_client_hello(), Botan::AES_128::clear(), Botan::AES_192::clear(), Botan::AES_256::clear(), Botan::ANSI_X919_MAC::clear(), Botan::ARIA_128::clear(), Botan::ARIA_192::clear(), Botan::ARIA_256::clear(), Botan::Blowfish::clear(), Botan::Camellia_128::clear(), Botan::Camellia_192::clear(), Botan::Camellia_256::clear(), Botan::CAST_128::clear(), Botan::ChaCha::clear(), Botan::CTR_BE::clear(), Botan::DES::clear(), Botan::GCM_SIV_Mode::clear(), Botan::GHASH::clear(), Botan::GOST_28147_89::clear(), Botan::HMAC::clear(), Botan::IDEA::clear(), Botan::KMAC::clear(), Botan::Kuznyechik::clear(), Botan::Lion::clear(), Botan::Noekeon::clear(), Botan::Poly1305::clear(), Botan::Polyval::clear(), Botan::RC4::clear(), Botan::Salsa20::clear(), Botan::SEED::clear(), Botan::Serpent::clear(), Botan::SHACAL2::clear(), Botan::SipHash::clear(), Botan::SM4::clear(), Botan::Threefish_512::clear(), Botan::TripleDES::clear(), and Botan::Twofish::clear().

◆ zeroise()

template<typename T, typename Alloc>
void Botan::zeroise ( std::vector< T, Alloc > & vec)

Zeroise the values; length remains unchanged

Note this is not intended for cases where the compiler might elide the writes as being without side-effects; use secure_scrub_memory for that.

TODO(Botan4): make these not-inlined and only for secure_vector, eg declare void zeroize(secure_vector<uint8_t>& v); void zeroize(secure_vector<uint16_t>& v); void zeroize(secure_vector<uint32_t>& v); void zeroize(secure_vector<uint64_t>& v);

Parameters
vecthe vector to zeroise

Definition at line 241 of file secmem.h.

241 {
242 for(size_t i = 0; i != vec.size(); ++i) {
243 vec[i] = static_cast<T>(0);
244 }
245}

Referenced by Botan::BLAKE2b::clear(), Botan::CMAC::clear(), Botan::CTR_BE::clear(), Botan::GMAC::clear(), Botan::GOST_34_11::clear(), Botan::OCB_Mode::clear(), Botan::OFB::clear(), Botan::SHAKE_Cipher::clear(), Botan::Streebog::clear(), Botan::Whirlpool::init(), Botan::OctetString::operator^=(), Botan::CBC_Decryption::reset(), Botan::CFB_Mode::reset(), Botan::OCB_Mode::reset(), Botan::CTR_BE::seek(), and zap().

◆ zeroize_buffer()

template<std::unsigned_integral T>
void Botan::zeroize_buffer ( T buf[],
size_t n )
inline
Parameters
bufa pointer to the start of the region
nthe number of elements in buf

Definition at line 37 of file mem_utils.h.

37 {
38 if(n > 0) {
39 std::memset(buf, 0, sizeof(T) * n);
40 }
41}

Referenced by basecase_mul(), basecase_sqr(), bigint_monty_redc_inplace(), bigint_mul(), bigint_shl1(), bigint_shl2(), bigint_shr1(), bigint_shr2(), bigint_sqr(), Botan::AlignmentBuffer< T, BLOCK_SIZE, FINAL_BLOCK_STRATEGY >::clear(), and Botan::AlignmentBuffer< T, BLOCK_SIZE, FINAL_BLOCK_STRATEGY >::fill_up_with_zeros().

Variable Documentation

◆ BLAKE2B_BLOCKBYTES

size_t Botan::BLAKE2B_BLOCKBYTES = 128
constexpr

Definition at line 18 of file blake2b.h.

Referenced by Botan::BLAKE2b::add_data().

◆ BYTES_448

size_t Botan::BYTES_448 = ceil_tobytes<size_t>(448)
constexpr

Definition at line 21 of file curve448_gf.h.

◆ DefaultBufferSize

size_t Botan::DefaultBufferSize = 4096
constexpr

How much to allocate for a buffer of no particular size

Definition at line 150 of file types.h.

Referenced by operator<<(), operator<<(), operator>>(), operator>>(), Botan::Pipe::read_all_as_string(), Botan::HTTP::read_response_from_socket(), and Botan::Pipe::write().

◆ ED448_LEN

◆ HEX_CODEC_BUFFER_SIZE

const size_t Botan::HEX_CODEC_BUFFER_SIZE = 256

Size used for internal buffer in hex encoder/decoder

Definition at line 20 of file hex_filt.cpp.

Referenced by Botan::Hex_Decoder::Hex_Decoder(), Botan::Hex_Encoder::Hex_Encoder(), and Botan::Hex_Encoder::Hex_Encoder().

◆ HwAesKeyFirst

bool Botan::HwAesKeyFirst = false
constexpr

True if the round instructions add the round key before SubBytes, as on ARMv8, rather than after MixColumns as on x86 and POWER

Definition at line 139 of file simd_hwaes.h.

◆ is_strong_span_v

template<typename T>
bool Botan::is_strong_span_v = is_strong_span<T>::value
constexpr

Definition at line 71 of file strong_type_helpers.h.

◆ is_strong_type_v

template<typename... Ts>
bool Botan::is_strong_type_v = is_strong_type<std::remove_const_t<Ts>...>::value
constexpr

Definition at line 39 of file strong_type_helpers.h.

◆ KECCAK_MB_ABSORB_BLOCKS

size_t Botan::KECCAK_MB_ABSORB_BLOCKS = 8
inlineconstexpr

Definition at line 38 of file hash_engine_keccak.h.

Referenced by keccak_mb_absorb_x8().

◆ KECCAK_RC

uint64_t Botan::KECCAK_RC[24]
inlineconstexpr
Initial value:
= {
0x0000000000000001, 0x0000000000008082, 0x800000000000808A, 0x8000000080008000, 0x000000000000808B,
0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008A, 0x0000000000000088,
0x0000000080008009, 0x000000008000000A, 0x000000008000808B, 0x800000000000008B, 0x8000000000008089,
0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 0x000000000000800A, 0x800000008000000A,
0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008}

Definition at line 16 of file keccak_perm_round.h.

16 {
17 0x0000000000000001, 0x0000000000008082, 0x800000000000808A, 0x8000000080008000, 0x000000000000808B,
18 0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008A, 0x0000000000000088,
19 0x0000000080008009, 0x000000008000000A, 0x000000008000808B, 0x800000000000008B, 0x8000000000008089,
20 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 0x000000000000800A, 0x800000008000000A,
21 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008};

Referenced by keccak_mb_absorb_x4(), keccak_mb_absorb_x8(), keccak_mb_permute_x4(), keccak_mb_permute_x8(), and Botan::Keccak_Permutation::permute().

◆ LMS_IDENTIFIER_LEN

◆ MAX_EXT_DEG

const size_t Botan::MAX_EXT_DEG = 15

Definition at line 20 of file gf2m_small_m.cpp.

◆ MulxMontyMinWords

size_t Botan::MulxMontyMinWords = 9
constexpr

Definition at line 31 of file mp_mulx.h.

Referenced by use_mulx_monty().

◆ PKCS12_MAX_ITERATIONS

size_t Botan::PKCS12_MAX_ITERATIONS = 100'000'000
inlineconstexpr

Maximum allowed iteration count for PKCS#12 KDF/PBE/MAC operations

This matches the limit used by NSS, AWS-LC and BoringSSL for PKCS12 files

Definition at line 25 of file pkcs12_pbe.h.

Referenced by Botan::PKCS12::PKCS12(), pkcs12_pbe_decrypt(), and pkcs12_pbe_encrypt().

◆ PRIME_TABLE_SIZE

const size_t Botan::PRIME_TABLE_SIZE = 6541

The size of the PRIMES[] array

Definition at line 177 of file numthry.h.

Referenced by mod_small_primes(), mod_small_primes(), and random_prime().

◆ PRIMES

uint16_t Botan::PRIMES
constexpr

A const array of all odd primes less than 65535

Definition at line 17 of file primes.cpp.

17 {
18 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
19 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
20 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
21 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
22 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
23 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
24 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617,
25 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
26 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
27 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947,
28 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051,
29 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171,
30 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289,
31 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427,
32 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523,
33 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621,
34 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753,
35 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879,
36 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011,
37 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131,
38 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269,
39 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381,
40 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521,
41 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659,
42 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749,
43 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879,
44 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019,
45 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169,
46 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307,
47 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433,
48 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547,
49 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673,
50 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803,
51 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929,
52 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073,
53 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217,
54 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339,
55 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483,
56 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637,
57 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759,
58 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919,
59 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021,
60 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171,
61 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323,
62 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449,
63 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581,
64 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717,
65 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851,
66 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011,
67 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143,
68 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277,
69 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389,
70 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569,
71 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703,
72 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841,
73 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977,
74 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127,
75 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283,
76 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459,
77 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573,
78 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699,
79 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867,
80 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011,
81 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167,
82 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293,
83 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447,
84 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623,
85 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737,
86 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863,
87 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013,
88 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173,
89 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319,
90 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437,
91 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601,
92 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739,
93 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859,
94 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973, 10007, 10009, 10037, 10039,
95 10061, 10067, 10069, 10079, 10091, 10093, 10099, 10103, 10111, 10133, 10139, 10141, 10151, 10159, 10163, 10169,
96 10177, 10181, 10193, 10211, 10223, 10243, 10247, 10253, 10259, 10267, 10271, 10273, 10289, 10301, 10303, 10313,
97 10321, 10331, 10333, 10337, 10343, 10357, 10369, 10391, 10399, 10427, 10429, 10433, 10453, 10457, 10459, 10463,
98 10477, 10487, 10499, 10501, 10513, 10529, 10531, 10559, 10567, 10589, 10597, 10601, 10607, 10613, 10627, 10631,
99 10639, 10651, 10657, 10663, 10667, 10687, 10691, 10709, 10711, 10723, 10729, 10733, 10739, 10753, 10771, 10781,
100 10789, 10799, 10831, 10837, 10847, 10853, 10859, 10861, 10867, 10883, 10889, 10891, 10903, 10909, 10937, 10939,
101 10949, 10957, 10973, 10979, 10987, 10993, 11003, 11027, 11047, 11057, 11059, 11069, 11071, 11083, 11087, 11093,
102 11113, 11117, 11119, 11131, 11149, 11159, 11161, 11171, 11173, 11177, 11197, 11213, 11239, 11243, 11251, 11257,
103 11261, 11273, 11279, 11287, 11299, 11311, 11317, 11321, 11329, 11351, 11353, 11369, 11383, 11393, 11399, 11411,
104 11423, 11437, 11443, 11447, 11467, 11471, 11483, 11489, 11491, 11497, 11503, 11519, 11527, 11549, 11551, 11579,
105 11587, 11593, 11597, 11617, 11621, 11633, 11657, 11677, 11681, 11689, 11699, 11701, 11717, 11719, 11731, 11743,
106 11777, 11779, 11783, 11789, 11801, 11807, 11813, 11821, 11827, 11831, 11833, 11839, 11863, 11867, 11887, 11897,
107 11903, 11909, 11923, 11927, 11933, 11939, 11941, 11953, 11959, 11969, 11971, 11981, 11987, 12007, 12011, 12037,
108 12041, 12043, 12049, 12071, 12073, 12097, 12101, 12107, 12109, 12113, 12119, 12143, 12149, 12157, 12161, 12163,
109 12197, 12203, 12211, 12227, 12239, 12241, 12251, 12253, 12263, 12269, 12277, 12281, 12289, 12301, 12323, 12329,
110 12343, 12347, 12373, 12377, 12379, 12391, 12401, 12409, 12413, 12421, 12433, 12437, 12451, 12457, 12473, 12479,
111 12487, 12491, 12497, 12503, 12511, 12517, 12527, 12539, 12541, 12547, 12553, 12569, 12577, 12583, 12589, 12601,
112 12611, 12613, 12619, 12637, 12641, 12647, 12653, 12659, 12671, 12689, 12697, 12703, 12713, 12721, 12739, 12743,
113 12757, 12763, 12781, 12791, 12799, 12809, 12821, 12823, 12829, 12841, 12853, 12889, 12893, 12899, 12907, 12911,
114 12917, 12919, 12923, 12941, 12953, 12959, 12967, 12973, 12979, 12983, 13001, 13003, 13007, 13009, 13033, 13037,
115 13043, 13049, 13063, 13093, 13099, 13103, 13109, 13121, 13127, 13147, 13151, 13159, 13163, 13171, 13177, 13183,
116 13187, 13217, 13219, 13229, 13241, 13249, 13259, 13267, 13291, 13297, 13309, 13313, 13327, 13331, 13337, 13339,
117 13367, 13381, 13397, 13399, 13411, 13417, 13421, 13441, 13451, 13457, 13463, 13469, 13477, 13487, 13499, 13513,
118 13523, 13537, 13553, 13567, 13577, 13591, 13597, 13613, 13619, 13627, 13633, 13649, 13669, 13679, 13681, 13687,
119 13691, 13693, 13697, 13709, 13711, 13721, 13723, 13729, 13751, 13757, 13759, 13763, 13781, 13789, 13799, 13807,
120 13829, 13831, 13841, 13859, 13873, 13877, 13879, 13883, 13901, 13903, 13907, 13913, 13921, 13931, 13933, 13963,
121 13967, 13997, 13999, 14009, 14011, 14029, 14033, 14051, 14057, 14071, 14081, 14083, 14087, 14107, 14143, 14149,
122 14153, 14159, 14173, 14177, 14197, 14207, 14221, 14243, 14249, 14251, 14281, 14293, 14303, 14321, 14323, 14327,
123 14341, 14347, 14369, 14387, 14389, 14401, 14407, 14411, 14419, 14423, 14431, 14437, 14447, 14449, 14461, 14479,
124 14489, 14503, 14519, 14533, 14537, 14543, 14549, 14551, 14557, 14561, 14563, 14591, 14593, 14621, 14627, 14629,
125 14633, 14639, 14653, 14657, 14669, 14683, 14699, 14713, 14717, 14723, 14731, 14737, 14741, 14747, 14753, 14759,
126 14767, 14771, 14779, 14783, 14797, 14813, 14821, 14827, 14831, 14843, 14851, 14867, 14869, 14879, 14887, 14891,
127 14897, 14923, 14929, 14939, 14947, 14951, 14957, 14969, 14983, 15013, 15017, 15031, 15053, 15061, 15073, 15077,
128 15083, 15091, 15101, 15107, 15121, 15131, 15137, 15139, 15149, 15161, 15173, 15187, 15193, 15199, 15217, 15227,
129 15233, 15241, 15259, 15263, 15269, 15271, 15277, 15287, 15289, 15299, 15307, 15313, 15319, 15329, 15331, 15349,
130 15359, 15361, 15373, 15377, 15383, 15391, 15401, 15413, 15427, 15439, 15443, 15451, 15461, 15467, 15473, 15493,
131 15497, 15511, 15527, 15541, 15551, 15559, 15569, 15581, 15583, 15601, 15607, 15619, 15629, 15641, 15643, 15647,
132 15649, 15661, 15667, 15671, 15679, 15683, 15727, 15731, 15733, 15737, 15739, 15749, 15761, 15767, 15773, 15787,
133 15791, 15797, 15803, 15809, 15817, 15823, 15859, 15877, 15881, 15887, 15889, 15901, 15907, 15913, 15919, 15923,
134 15937, 15959, 15971, 15973, 15991, 16001, 16007, 16033, 16057, 16061, 16063, 16067, 16069, 16073, 16087, 16091,
135 16097, 16103, 16111, 16127, 16139, 16141, 16183, 16187, 16189, 16193, 16217, 16223, 16229, 16231, 16249, 16253,
136 16267, 16273, 16301, 16319, 16333, 16339, 16349, 16361, 16363, 16369, 16381, 16411, 16417, 16421, 16427, 16433,
137 16447, 16451, 16453, 16477, 16481, 16487, 16493, 16519, 16529, 16547, 16553, 16561, 16567, 16573, 16603, 16607,
138 16619, 16631, 16633, 16649, 16651, 16657, 16661, 16673, 16691, 16693, 16699, 16703, 16729, 16741, 16747, 16759,
139 16763, 16787, 16811, 16823, 16829, 16831, 16843, 16871, 16879, 16883, 16889, 16901, 16903, 16921, 16927, 16931,
140 16937, 16943, 16963, 16979, 16981, 16987, 16993, 17011, 17021, 17027, 17029, 17033, 17041, 17047, 17053, 17077,
141 17093, 17099, 17107, 17117, 17123, 17137, 17159, 17167, 17183, 17189, 17191, 17203, 17207, 17209, 17231, 17239,
142 17257, 17291, 17293, 17299, 17317, 17321, 17327, 17333, 17341, 17351, 17359, 17377, 17383, 17387, 17389, 17393,
143 17401, 17417, 17419, 17431, 17443, 17449, 17467, 17471, 17477, 17483, 17489, 17491, 17497, 17509, 17519, 17539,
144 17551, 17569, 17573, 17579, 17581, 17597, 17599, 17609, 17623, 17627, 17657, 17659, 17669, 17681, 17683, 17707,
145 17713, 17729, 17737, 17747, 17749, 17761, 17783, 17789, 17791, 17807, 17827, 17837, 17839, 17851, 17863, 17881,
146 17891, 17903, 17909, 17911, 17921, 17923, 17929, 17939, 17957, 17959, 17971, 17977, 17981, 17987, 17989, 18013,
147 18041, 18043, 18047, 18049, 18059, 18061, 18077, 18089, 18097, 18119, 18121, 18127, 18131, 18133, 18143, 18149,
148 18169, 18181, 18191, 18199, 18211, 18217, 18223, 18229, 18233, 18251, 18253, 18257, 18269, 18287, 18289, 18301,
149 18307, 18311, 18313, 18329, 18341, 18353, 18367, 18371, 18379, 18397, 18401, 18413, 18427, 18433, 18439, 18443,
150 18451, 18457, 18461, 18481, 18493, 18503, 18517, 18521, 18523, 18539, 18541, 18553, 18583, 18587, 18593, 18617,
151 18637, 18661, 18671, 18679, 18691, 18701, 18713, 18719, 18731, 18743, 18749, 18757, 18773, 18787, 18793, 18797,
152 18803, 18839, 18859, 18869, 18899, 18911, 18913, 18917, 18919, 18947, 18959, 18973, 18979, 19001, 19009, 19013,
153 19031, 19037, 19051, 19069, 19073, 19079, 19081, 19087, 19121, 19139, 19141, 19157, 19163, 19181, 19183, 19207,
154 19211, 19213, 19219, 19231, 19237, 19249, 19259, 19267, 19273, 19289, 19301, 19309, 19319, 19333, 19373, 19379,
155 19381, 19387, 19391, 19403, 19417, 19421, 19423, 19427, 19429, 19433, 19441, 19447, 19457, 19463, 19469, 19471,
156 19477, 19483, 19489, 19501, 19507, 19531, 19541, 19543, 19553, 19559, 19571, 19577, 19583, 19597, 19603, 19609,
157 19661, 19681, 19687, 19697, 19699, 19709, 19717, 19727, 19739, 19751, 19753, 19759, 19763, 19777, 19793, 19801,
158 19813, 19819, 19841, 19843, 19853, 19861, 19867, 19889, 19891, 19913, 19919, 19927, 19937, 19949, 19961, 19963,
159 19973, 19979, 19991, 19993, 19997, 20011, 20021, 20023, 20029, 20047, 20051, 20063, 20071, 20089, 20101, 20107,
160 20113, 20117, 20123, 20129, 20143, 20147, 20149, 20161, 20173, 20177, 20183, 20201, 20219, 20231, 20233, 20249,
161 20261, 20269, 20287, 20297, 20323, 20327, 20333, 20341, 20347, 20353, 20357, 20359, 20369, 20389, 20393, 20399,
162 20407, 20411, 20431, 20441, 20443, 20477, 20479, 20483, 20507, 20509, 20521, 20533, 20543, 20549, 20551, 20563,
163 20593, 20599, 20611, 20627, 20639, 20641, 20663, 20681, 20693, 20707, 20717, 20719, 20731, 20743, 20747, 20749,
164 20753, 20759, 20771, 20773, 20789, 20807, 20809, 20849, 20857, 20873, 20879, 20887, 20897, 20899, 20903, 20921,
165 20929, 20939, 20947, 20959, 20963, 20981, 20983, 21001, 21011, 21013, 21017, 21019, 21023, 21031, 21059, 21061,
166 21067, 21089, 21101, 21107, 21121, 21139, 21143, 21149, 21157, 21163, 21169, 21179, 21187, 21191, 21193, 21211,
167 21221, 21227, 21247, 21269, 21277, 21283, 21313, 21317, 21319, 21323, 21341, 21347, 21377, 21379, 21383, 21391,
168 21397, 21401, 21407, 21419, 21433, 21467, 21481, 21487, 21491, 21493, 21499, 21503, 21517, 21521, 21523, 21529,
169 21557, 21559, 21563, 21569, 21577, 21587, 21589, 21599, 21601, 21611, 21613, 21617, 21647, 21649, 21661, 21673,
170 21683, 21701, 21713, 21727, 21737, 21739, 21751, 21757, 21767, 21773, 21787, 21799, 21803, 21817, 21821, 21839,
171 21841, 21851, 21859, 21863, 21871, 21881, 21893, 21911, 21929, 21937, 21943, 21961, 21977, 21991, 21997, 22003,
172 22013, 22027, 22031, 22037, 22039, 22051, 22063, 22067, 22073, 22079, 22091, 22093, 22109, 22111, 22123, 22129,
173 22133, 22147, 22153, 22157, 22159, 22171, 22189, 22193, 22229, 22247, 22259, 22271, 22273, 22277, 22279, 22283,
174 22291, 22303, 22307, 22343, 22349, 22367, 22369, 22381, 22391, 22397, 22409, 22433, 22441, 22447, 22453, 22469,
175 22481, 22483, 22501, 22511, 22531, 22541, 22543, 22549, 22567, 22571, 22573, 22613, 22619, 22621, 22637, 22639,
176 22643, 22651, 22669, 22679, 22691, 22697, 22699, 22709, 22717, 22721, 22727, 22739, 22741, 22751, 22769, 22777,
177 22783, 22787, 22807, 22811, 22817, 22853, 22859, 22861, 22871, 22877, 22901, 22907, 22921, 22937, 22943, 22961,
178 22963, 22973, 22993, 23003, 23011, 23017, 23021, 23027, 23029, 23039, 23041, 23053, 23057, 23059, 23063, 23071,
179 23081, 23087, 23099, 23117, 23131, 23143, 23159, 23167, 23173, 23189, 23197, 23201, 23203, 23209, 23227, 23251,
180 23269, 23279, 23291, 23293, 23297, 23311, 23321, 23327, 23333, 23339, 23357, 23369, 23371, 23399, 23417, 23431,
181 23447, 23459, 23473, 23497, 23509, 23531, 23537, 23539, 23549, 23557, 23561, 23563, 23567, 23581, 23593, 23599,
182 23603, 23609, 23623, 23627, 23629, 23633, 23663, 23669, 23671, 23677, 23687, 23689, 23719, 23741, 23743, 23747,
183 23753, 23761, 23767, 23773, 23789, 23801, 23813, 23819, 23827, 23831, 23833, 23857, 23869, 23873, 23879, 23887,
184 23893, 23899, 23909, 23911, 23917, 23929, 23957, 23971, 23977, 23981, 23993, 24001, 24007, 24019, 24023, 24029,
185 24043, 24049, 24061, 24071, 24077, 24083, 24091, 24097, 24103, 24107, 24109, 24113, 24121, 24133, 24137, 24151,
186 24169, 24179, 24181, 24197, 24203, 24223, 24229, 24239, 24247, 24251, 24281, 24317, 24329, 24337, 24359, 24371,
187 24373, 24379, 24391, 24407, 24413, 24419, 24421, 24439, 24443, 24469, 24473, 24481, 24499, 24509, 24517, 24527,
188 24533, 24547, 24551, 24571, 24593, 24611, 24623, 24631, 24659, 24671, 24677, 24683, 24691, 24697, 24709, 24733,
189 24749, 24763, 24767, 24781, 24793, 24799, 24809, 24821, 24841, 24847, 24851, 24859, 24877, 24889, 24907, 24917,
190 24919, 24923, 24943, 24953, 24967, 24971, 24977, 24979, 24989, 25013, 25031, 25033, 25037, 25057, 25073, 25087,
191 25097, 25111, 25117, 25121, 25127, 25147, 25153, 25163, 25169, 25171, 25183, 25189, 25219, 25229, 25237, 25243,
192 25247, 25253, 25261, 25301, 25303, 25307, 25309, 25321, 25339, 25343, 25349, 25357, 25367, 25373, 25391, 25409,
193 25411, 25423, 25439, 25447, 25453, 25457, 25463, 25469, 25471, 25523, 25537, 25541, 25561, 25577, 25579, 25583,
194 25589, 25601, 25603, 25609, 25621, 25633, 25639, 25643, 25657, 25667, 25673, 25679, 25693, 25703, 25717, 25733,
195 25741, 25747, 25759, 25763, 25771, 25793, 25799, 25801, 25819, 25841, 25847, 25849, 25867, 25873, 25889, 25903,
196 25913, 25919, 25931, 25933, 25939, 25943, 25951, 25969, 25981, 25997, 25999, 26003, 26017, 26021, 26029, 26041,
197 26053, 26083, 26099, 26107, 26111, 26113, 26119, 26141, 26153, 26161, 26171, 26177, 26183, 26189, 26203, 26209,
198 26227, 26237, 26249, 26251, 26261, 26263, 26267, 26293, 26297, 26309, 26317, 26321, 26339, 26347, 26357, 26371,
199 26387, 26393, 26399, 26407, 26417, 26423, 26431, 26437, 26449, 26459, 26479, 26489, 26497, 26501, 26513, 26539,
200 26557, 26561, 26573, 26591, 26597, 26627, 26633, 26641, 26647, 26669, 26681, 26683, 26687, 26693, 26699, 26701,
201 26711, 26713, 26717, 26723, 26729, 26731, 26737, 26759, 26777, 26783, 26801, 26813, 26821, 26833, 26839, 26849,
202 26861, 26863, 26879, 26881, 26891, 26893, 26903, 26921, 26927, 26947, 26951, 26953, 26959, 26981, 26987, 26993,
203 27011, 27017, 27031, 27043, 27059, 27061, 27067, 27073, 27077, 27091, 27103, 27107, 27109, 27127, 27143, 27179,
204 27191, 27197, 27211, 27239, 27241, 27253, 27259, 27271, 27277, 27281, 27283, 27299, 27329, 27337, 27361, 27367,
205 27397, 27407, 27409, 27427, 27431, 27437, 27449, 27457, 27479, 27481, 27487, 27509, 27527, 27529, 27539, 27541,
206 27551, 27581, 27583, 27611, 27617, 27631, 27647, 27653, 27673, 27689, 27691, 27697, 27701, 27733, 27737, 27739,
207 27743, 27749, 27751, 27763, 27767, 27773, 27779, 27791, 27793, 27799, 27803, 27809, 27817, 27823, 27827, 27847,
208 27851, 27883, 27893, 27901, 27917, 27919, 27941, 27943, 27947, 27953, 27961, 27967, 27983, 27997, 28001, 28019,
209 28027, 28031, 28051, 28057, 28069, 28081, 28087, 28097, 28099, 28109, 28111, 28123, 28151, 28163, 28181, 28183,
210 28201, 28211, 28219, 28229, 28277, 28279, 28283, 28289, 28297, 28307, 28309, 28319, 28349, 28351, 28387, 28393,
211 28403, 28409, 28411, 28429, 28433, 28439, 28447, 28463, 28477, 28493, 28499, 28513, 28517, 28537, 28541, 28547,
212 28549, 28559, 28571, 28573, 28579, 28591, 28597, 28603, 28607, 28619, 28621, 28627, 28631, 28643, 28649, 28657,
213 28661, 28663, 28669, 28687, 28697, 28703, 28711, 28723, 28729, 28751, 28753, 28759, 28771, 28789, 28793, 28807,
214 28813, 28817, 28837, 28843, 28859, 28867, 28871, 28879, 28901, 28909, 28921, 28927, 28933, 28949, 28961, 28979,
215 29009, 29017, 29021, 29023, 29027, 29033, 29059, 29063, 29077, 29101, 29123, 29129, 29131, 29137, 29147, 29153,
216 29167, 29173, 29179, 29191, 29201, 29207, 29209, 29221, 29231, 29243, 29251, 29269, 29287, 29297, 29303, 29311,
217 29327, 29333, 29339, 29347, 29363, 29383, 29387, 29389, 29399, 29401, 29411, 29423, 29429, 29437, 29443, 29453,
218 29473, 29483, 29501, 29527, 29531, 29537, 29567, 29569, 29573, 29581, 29587, 29599, 29611, 29629, 29633, 29641,
219 29663, 29669, 29671, 29683, 29717, 29723, 29741, 29753, 29759, 29761, 29789, 29803, 29819, 29833, 29837, 29851,
220 29863, 29867, 29873, 29879, 29881, 29917, 29921, 29927, 29947, 29959, 29983, 29989, 30011, 30013, 30029, 30047,
221 30059, 30071, 30089, 30091, 30097, 30103, 30109, 30113, 30119, 30133, 30137, 30139, 30161, 30169, 30181, 30187,
222 30197, 30203, 30211, 30223, 30241, 30253, 30259, 30269, 30271, 30293, 30307, 30313, 30319, 30323, 30341, 30347,
223 30367, 30389, 30391, 30403, 30427, 30431, 30449, 30467, 30469, 30491, 30493, 30497, 30509, 30517, 30529, 30539,
224 30553, 30557, 30559, 30577, 30593, 30631, 30637, 30643, 30649, 30661, 30671, 30677, 30689, 30697, 30703, 30707,
225 30713, 30727, 30757, 30763, 30773, 30781, 30803, 30809, 30817, 30829, 30839, 30841, 30851, 30853, 30859, 30869,
226 30871, 30881, 30893, 30911, 30931, 30937, 30941, 30949, 30971, 30977, 30983, 31013, 31019, 31033, 31039, 31051,
227 31063, 31069, 31079, 31081, 31091, 31121, 31123, 31139, 31147, 31151, 31153, 31159, 31177, 31181, 31183, 31189,
228 31193, 31219, 31223, 31231, 31237, 31247, 31249, 31253, 31259, 31267, 31271, 31277, 31307, 31319, 31321, 31327,
229 31333, 31337, 31357, 31379, 31387, 31391, 31393, 31397, 31469, 31477, 31481, 31489, 31511, 31513, 31517, 31531,
230 31541, 31543, 31547, 31567, 31573, 31583, 31601, 31607, 31627, 31643, 31649, 31657, 31663, 31667, 31687, 31699,
231 31721, 31723, 31727, 31729, 31741, 31751, 31769, 31771, 31793, 31799, 31817, 31847, 31849, 31859, 31873, 31883,
232 31891, 31907, 31957, 31963, 31973, 31981, 31991, 32003, 32009, 32027, 32029, 32051, 32057, 32059, 32063, 32069,
233 32077, 32083, 32089, 32099, 32117, 32119, 32141, 32143, 32159, 32173, 32183, 32189, 32191, 32203, 32213, 32233,
234 32237, 32251, 32257, 32261, 32297, 32299, 32303, 32309, 32321, 32323, 32327, 32341, 32353, 32359, 32363, 32369,
235 32371, 32377, 32381, 32401, 32411, 32413, 32423, 32429, 32441, 32443, 32467, 32479, 32491, 32497, 32503, 32507,
236 32531, 32533, 32537, 32561, 32563, 32569, 32573, 32579, 32587, 32603, 32609, 32611, 32621, 32633, 32647, 32653,
237 32687, 32693, 32707, 32713, 32717, 32719, 32749, 32771, 32779, 32783, 32789, 32797, 32801, 32803, 32831, 32833,
238 32839, 32843, 32869, 32887, 32909, 32911, 32917, 32933, 32939, 32941, 32957, 32969, 32971, 32983, 32987, 32993,
239 32999, 33013, 33023, 33029, 33037, 33049, 33053, 33071, 33073, 33083, 33091, 33107, 33113, 33119, 33149, 33151,
240 33161, 33179, 33181, 33191, 33199, 33203, 33211, 33223, 33247, 33287, 33289, 33301, 33311, 33317, 33329, 33331,
241 33343, 33347, 33349, 33353, 33359, 33377, 33391, 33403, 33409, 33413, 33427, 33457, 33461, 33469, 33479, 33487,
242 33493, 33503, 33521, 33529, 33533, 33547, 33563, 33569, 33577, 33581, 33587, 33589, 33599, 33601, 33613, 33617,
243 33619, 33623, 33629, 33637, 33641, 33647, 33679, 33703, 33713, 33721, 33739, 33749, 33751, 33757, 33767, 33769,
244 33773, 33791, 33797, 33809, 33811, 33827, 33829, 33851, 33857, 33863, 33871, 33889, 33893, 33911, 33923, 33931,
245 33937, 33941, 33961, 33967, 33997, 34019, 34031, 34033, 34039, 34057, 34061, 34123, 34127, 34129, 34141, 34147,
246 34157, 34159, 34171, 34183, 34211, 34213, 34217, 34231, 34253, 34259, 34261, 34267, 34273, 34283, 34297, 34301,
247 34303, 34313, 34319, 34327, 34337, 34351, 34361, 34367, 34369, 34381, 34403, 34421, 34429, 34439, 34457, 34469,
248 34471, 34483, 34487, 34499, 34501, 34511, 34513, 34519, 34537, 34543, 34549, 34583, 34589, 34591, 34603, 34607,
249 34613, 34631, 34649, 34651, 34667, 34673, 34679, 34687, 34693, 34703, 34721, 34729, 34739, 34747, 34757, 34759,
250 34763, 34781, 34807, 34819, 34841, 34843, 34847, 34849, 34871, 34877, 34883, 34897, 34913, 34919, 34939, 34949,
251 34961, 34963, 34981, 35023, 35027, 35051, 35053, 35059, 35069, 35081, 35083, 35089, 35099, 35107, 35111, 35117,
252 35129, 35141, 35149, 35153, 35159, 35171, 35201, 35221, 35227, 35251, 35257, 35267, 35279, 35281, 35291, 35311,
253 35317, 35323, 35327, 35339, 35353, 35363, 35381, 35393, 35401, 35407, 35419, 35423, 35437, 35447, 35449, 35461,
254 35491, 35507, 35509, 35521, 35527, 35531, 35533, 35537, 35543, 35569, 35573, 35591, 35593, 35597, 35603, 35617,
255 35671, 35677, 35729, 35731, 35747, 35753, 35759, 35771, 35797, 35801, 35803, 35809, 35831, 35837, 35839, 35851,
256 35863, 35869, 35879, 35897, 35899, 35911, 35923, 35933, 35951, 35963, 35969, 35977, 35983, 35993, 35999, 36007,
257 36011, 36013, 36017, 36037, 36061, 36067, 36073, 36083, 36097, 36107, 36109, 36131, 36137, 36151, 36161, 36187,
258 36191, 36209, 36217, 36229, 36241, 36251, 36263, 36269, 36277, 36293, 36299, 36307, 36313, 36319, 36341, 36343,
259 36353, 36373, 36383, 36389, 36433, 36451, 36457, 36467, 36469, 36473, 36479, 36493, 36497, 36523, 36527, 36529,
260 36541, 36551, 36559, 36563, 36571, 36583, 36587, 36599, 36607, 36629, 36637, 36643, 36653, 36671, 36677, 36683,
261 36691, 36697, 36709, 36713, 36721, 36739, 36749, 36761, 36767, 36779, 36781, 36787, 36791, 36793, 36809, 36821,
262 36833, 36847, 36857, 36871, 36877, 36887, 36899, 36901, 36913, 36919, 36923, 36929, 36931, 36943, 36947, 36973,
263 36979, 36997, 37003, 37013, 37019, 37021, 37039, 37049, 37057, 37061, 37087, 37097, 37117, 37123, 37139, 37159,
264 37171, 37181, 37189, 37199, 37201, 37217, 37223, 37243, 37253, 37273, 37277, 37307, 37309, 37313, 37321, 37337,
265 37339, 37357, 37361, 37363, 37369, 37379, 37397, 37409, 37423, 37441, 37447, 37463, 37483, 37489, 37493, 37501,
266 37507, 37511, 37517, 37529, 37537, 37547, 37549, 37561, 37567, 37571, 37573, 37579, 37589, 37591, 37607, 37619,
267 37633, 37643, 37649, 37657, 37663, 37691, 37693, 37699, 37717, 37747, 37781, 37783, 37799, 37811, 37813, 37831,
268 37847, 37853, 37861, 37871, 37879, 37889, 37897, 37907, 37951, 37957, 37963, 37967, 37987, 37991, 37993, 37997,
269 38011, 38039, 38047, 38053, 38069, 38083, 38113, 38119, 38149, 38153, 38167, 38177, 38183, 38189, 38197, 38201,
270 38219, 38231, 38237, 38239, 38261, 38273, 38281, 38287, 38299, 38303, 38317, 38321, 38327, 38329, 38333, 38351,
271 38371, 38377, 38393, 38431, 38447, 38449, 38453, 38459, 38461, 38501, 38543, 38557, 38561, 38567, 38569, 38593,
272 38603, 38609, 38611, 38629, 38639, 38651, 38653, 38669, 38671, 38677, 38693, 38699, 38707, 38711, 38713, 38723,
273 38729, 38737, 38747, 38749, 38767, 38783, 38791, 38803, 38821, 38833, 38839, 38851, 38861, 38867, 38873, 38891,
274 38903, 38917, 38921, 38923, 38933, 38953, 38959, 38971, 38977, 38993, 39019, 39023, 39041, 39043, 39047, 39079,
275 39089, 39097, 39103, 39107, 39113, 39119, 39133, 39139, 39157, 39161, 39163, 39181, 39191, 39199, 39209, 39217,
276 39227, 39229, 39233, 39239, 39241, 39251, 39293, 39301, 39313, 39317, 39323, 39341, 39343, 39359, 39367, 39371,
277 39373, 39383, 39397, 39409, 39419, 39439, 39443, 39451, 39461, 39499, 39503, 39509, 39511, 39521, 39541, 39551,
278 39563, 39569, 39581, 39607, 39619, 39623, 39631, 39659, 39667, 39671, 39679, 39703, 39709, 39719, 39727, 39733,
279 39749, 39761, 39769, 39779, 39791, 39799, 39821, 39827, 39829, 39839, 39841, 39847, 39857, 39863, 39869, 39877,
280 39883, 39887, 39901, 39929, 39937, 39953, 39971, 39979, 39983, 39989, 40009, 40013, 40031, 40037, 40039, 40063,
281 40087, 40093, 40099, 40111, 40123, 40127, 40129, 40151, 40153, 40163, 40169, 40177, 40189, 40193, 40213, 40231,
282 40237, 40241, 40253, 40277, 40283, 40289, 40343, 40351, 40357, 40361, 40387, 40423, 40427, 40429, 40433, 40459,
283 40471, 40483, 40487, 40493, 40499, 40507, 40519, 40529, 40531, 40543, 40559, 40577, 40583, 40591, 40597, 40609,
284 40627, 40637, 40639, 40693, 40697, 40699, 40709, 40739, 40751, 40759, 40763, 40771, 40787, 40801, 40813, 40819,
285 40823, 40829, 40841, 40847, 40849, 40853, 40867, 40879, 40883, 40897, 40903, 40927, 40933, 40939, 40949, 40961,
286 40973, 40993, 41011, 41017, 41023, 41039, 41047, 41051, 41057, 41077, 41081, 41113, 41117, 41131, 41141, 41143,
287 41149, 41161, 41177, 41179, 41183, 41189, 41201, 41203, 41213, 41221, 41227, 41231, 41233, 41243, 41257, 41263,
288 41269, 41281, 41299, 41333, 41341, 41351, 41357, 41381, 41387, 41389, 41399, 41411, 41413, 41443, 41453, 41467,
289 41479, 41491, 41507, 41513, 41519, 41521, 41539, 41543, 41549, 41579, 41593, 41597, 41603, 41609, 41611, 41617,
290 41621, 41627, 41641, 41647, 41651, 41659, 41669, 41681, 41687, 41719, 41729, 41737, 41759, 41761, 41771, 41777,
291 41801, 41809, 41813, 41843, 41849, 41851, 41863, 41879, 41887, 41893, 41897, 41903, 41911, 41927, 41941, 41947,
292 41953, 41957, 41959, 41969, 41981, 41983, 41999, 42013, 42017, 42019, 42023, 42043, 42061, 42071, 42073, 42083,
293 42089, 42101, 42131, 42139, 42157, 42169, 42179, 42181, 42187, 42193, 42197, 42209, 42221, 42223, 42227, 42239,
294 42257, 42281, 42283, 42293, 42299, 42307, 42323, 42331, 42337, 42349, 42359, 42373, 42379, 42391, 42397, 42403,
295 42407, 42409, 42433, 42437, 42443, 42451, 42457, 42461, 42463, 42467, 42473, 42487, 42491, 42499, 42509, 42533,
296 42557, 42569, 42571, 42577, 42589, 42611, 42641, 42643, 42649, 42667, 42677, 42683, 42689, 42697, 42701, 42703,
297 42709, 42719, 42727, 42737, 42743, 42751, 42767, 42773, 42787, 42793, 42797, 42821, 42829, 42839, 42841, 42853,
298 42859, 42863, 42899, 42901, 42923, 42929, 42937, 42943, 42953, 42961, 42967, 42979, 42989, 43003, 43013, 43019,
299 43037, 43049, 43051, 43063, 43067, 43093, 43103, 43117, 43133, 43151, 43159, 43177, 43189, 43201, 43207, 43223,
300 43237, 43261, 43271, 43283, 43291, 43313, 43319, 43321, 43331, 43391, 43397, 43399, 43403, 43411, 43427, 43441,
301 43451, 43457, 43481, 43487, 43499, 43517, 43541, 43543, 43573, 43577, 43579, 43591, 43597, 43607, 43609, 43613,
302 43627, 43633, 43649, 43651, 43661, 43669, 43691, 43711, 43717, 43721, 43753, 43759, 43777, 43781, 43783, 43787,
303 43789, 43793, 43801, 43853, 43867, 43889, 43891, 43913, 43933, 43943, 43951, 43961, 43963, 43969, 43973, 43987,
304 43991, 43997, 44017, 44021, 44027, 44029, 44041, 44053, 44059, 44071, 44087, 44089, 44101, 44111, 44119, 44123,
305 44129, 44131, 44159, 44171, 44179, 44189, 44201, 44203, 44207, 44221, 44249, 44257, 44263, 44267, 44269, 44273,
306 44279, 44281, 44293, 44351, 44357, 44371, 44381, 44383, 44389, 44417, 44449, 44453, 44483, 44491, 44497, 44501,
307 44507, 44519, 44531, 44533, 44537, 44543, 44549, 44563, 44579, 44587, 44617, 44621, 44623, 44633, 44641, 44647,
308 44651, 44657, 44683, 44687, 44699, 44701, 44711, 44729, 44741, 44753, 44771, 44773, 44777, 44789, 44797, 44809,
309 44819, 44839, 44843, 44851, 44867, 44879, 44887, 44893, 44909, 44917, 44927, 44939, 44953, 44959, 44963, 44971,
310 44983, 44987, 45007, 45013, 45053, 45061, 45077, 45083, 45119, 45121, 45127, 45131, 45137, 45139, 45161, 45179,
311 45181, 45191, 45197, 45233, 45247, 45259, 45263, 45281, 45289, 45293, 45307, 45317, 45319, 45329, 45337, 45341,
312 45343, 45361, 45377, 45389, 45403, 45413, 45427, 45433, 45439, 45481, 45491, 45497, 45503, 45523, 45533, 45541,
313 45553, 45557, 45569, 45587, 45589, 45599, 45613, 45631, 45641, 45659, 45667, 45673, 45677, 45691, 45697, 45707,
314 45737, 45751, 45757, 45763, 45767, 45779, 45817, 45821, 45823, 45827, 45833, 45841, 45853, 45863, 45869, 45887,
315 45893, 45943, 45949, 45953, 45959, 45971, 45979, 45989, 46021, 46027, 46049, 46051, 46061, 46073, 46091, 46093,
316 46099, 46103, 46133, 46141, 46147, 46153, 46171, 46181, 46183, 46187, 46199, 46219, 46229, 46237, 46261, 46271,
317 46273, 46279, 46301, 46307, 46309, 46327, 46337, 46349, 46351, 46381, 46399, 46411, 46439, 46441, 46447, 46451,
318 46457, 46471, 46477, 46489, 46499, 46507, 46511, 46523, 46549, 46559, 46567, 46573, 46589, 46591, 46601, 46619,
319 46633, 46639, 46643, 46649, 46663, 46679, 46681, 46687, 46691, 46703, 46723, 46727, 46747, 46751, 46757, 46769,
320 46771, 46807, 46811, 46817, 46819, 46829, 46831, 46853, 46861, 46867, 46877, 46889, 46901, 46919, 46933, 46957,
321 46993, 46997, 47017, 47041, 47051, 47057, 47059, 47087, 47093, 47111, 47119, 47123, 47129, 47137, 47143, 47147,
322 47149, 47161, 47189, 47207, 47221, 47237, 47251, 47269, 47279, 47287, 47293, 47297, 47303, 47309, 47317, 47339,
323 47351, 47353, 47363, 47381, 47387, 47389, 47407, 47417, 47419, 47431, 47441, 47459, 47491, 47497, 47501, 47507,
324 47513, 47521, 47527, 47533, 47543, 47563, 47569, 47581, 47591, 47599, 47609, 47623, 47629, 47639, 47653, 47657,
325 47659, 47681, 47699, 47701, 47711, 47713, 47717, 47737, 47741, 47743, 47777, 47779, 47791, 47797, 47807, 47809,
326 47819, 47837, 47843, 47857, 47869, 47881, 47903, 47911, 47917, 47933, 47939, 47947, 47951, 47963, 47969, 47977,
327 47981, 48017, 48023, 48029, 48049, 48073, 48079, 48091, 48109, 48119, 48121, 48131, 48157, 48163, 48179, 48187,
328 48193, 48197, 48221, 48239, 48247, 48259, 48271, 48281, 48299, 48311, 48313, 48337, 48341, 48353, 48371, 48383,
329 48397, 48407, 48409, 48413, 48437, 48449, 48463, 48473, 48479, 48481, 48487, 48491, 48497, 48523, 48527, 48533,
330 48539, 48541, 48563, 48571, 48589, 48593, 48611, 48619, 48623, 48647, 48649, 48661, 48673, 48677, 48679, 48731,
331 48733, 48751, 48757, 48761, 48767, 48779, 48781, 48787, 48799, 48809, 48817, 48821, 48823, 48847, 48857, 48859,
332 48869, 48871, 48883, 48889, 48907, 48947, 48953, 48973, 48989, 48991, 49003, 49009, 49019, 49031, 49033, 49037,
333 49043, 49057, 49069, 49081, 49103, 49109, 49117, 49121, 49123, 49139, 49157, 49169, 49171, 49177, 49193, 49199,
334 49201, 49207, 49211, 49223, 49253, 49261, 49277, 49279, 49297, 49307, 49331, 49333, 49339, 49363, 49367, 49369,
335 49391, 49393, 49409, 49411, 49417, 49429, 49433, 49451, 49459, 49463, 49477, 49481, 49499, 49523, 49529, 49531,
336 49537, 49547, 49549, 49559, 49597, 49603, 49613, 49627, 49633, 49639, 49663, 49667, 49669, 49681, 49697, 49711,
337 49727, 49739, 49741, 49747, 49757, 49783, 49787, 49789, 49801, 49807, 49811, 49823, 49831, 49843, 49853, 49871,
338 49877, 49891, 49919, 49921, 49927, 49937, 49939, 49943, 49957, 49991, 49993, 49999, 50021, 50023, 50033, 50047,
339 50051, 50053, 50069, 50077, 50087, 50093, 50101, 50111, 50119, 50123, 50129, 50131, 50147, 50153, 50159, 50177,
340 50207, 50221, 50227, 50231, 50261, 50263, 50273, 50287, 50291, 50311, 50321, 50329, 50333, 50341, 50359, 50363,
341 50377, 50383, 50387, 50411, 50417, 50423, 50441, 50459, 50461, 50497, 50503, 50513, 50527, 50539, 50543, 50549,
342 50551, 50581, 50587, 50591, 50593, 50599, 50627, 50647, 50651, 50671, 50683, 50707, 50723, 50741, 50753, 50767,
343 50773, 50777, 50789, 50821, 50833, 50839, 50849, 50857, 50867, 50873, 50891, 50893, 50909, 50923, 50929, 50951,
344 50957, 50969, 50971, 50989, 50993, 51001, 51031, 51043, 51047, 51059, 51061, 51071, 51109, 51131, 51133, 51137,
345 51151, 51157, 51169, 51193, 51197, 51199, 51203, 51217, 51229, 51239, 51241, 51257, 51263, 51283, 51287, 51307,
346 51329, 51341, 51343, 51347, 51349, 51361, 51383, 51407, 51413, 51419, 51421, 51427, 51431, 51437, 51439, 51449,
347 51461, 51473, 51479, 51481, 51487, 51503, 51511, 51517, 51521, 51539, 51551, 51563, 51577, 51581, 51593, 51599,
348 51607, 51613, 51631, 51637, 51647, 51659, 51673, 51679, 51683, 51691, 51713, 51719, 51721, 51749, 51767, 51769,
349 51787, 51797, 51803, 51817, 51827, 51829, 51839, 51853, 51859, 51869, 51871, 51893, 51899, 51907, 51913, 51929,
350 51941, 51949, 51971, 51973, 51977, 51991, 52009, 52021, 52027, 52051, 52057, 52067, 52069, 52081, 52103, 52121,
351 52127, 52147, 52153, 52163, 52177, 52181, 52183, 52189, 52201, 52223, 52237, 52249, 52253, 52259, 52267, 52289,
352 52291, 52301, 52313, 52321, 52361, 52363, 52369, 52379, 52387, 52391, 52433, 52453, 52457, 52489, 52501, 52511,
353 52517, 52529, 52541, 52543, 52553, 52561, 52567, 52571, 52579, 52583, 52609, 52627, 52631, 52639, 52667, 52673,
354 52691, 52697, 52709, 52711, 52721, 52727, 52733, 52747, 52757, 52769, 52783, 52807, 52813, 52817, 52837, 52859,
355 52861, 52879, 52883, 52889, 52901, 52903, 52919, 52937, 52951, 52957, 52963, 52967, 52973, 52981, 52999, 53003,
356 53017, 53047, 53051, 53069, 53077, 53087, 53089, 53093, 53101, 53113, 53117, 53129, 53147, 53149, 53161, 53171,
357 53173, 53189, 53197, 53201, 53231, 53233, 53239, 53267, 53269, 53279, 53281, 53299, 53309, 53323, 53327, 53353,
358 53359, 53377, 53381, 53401, 53407, 53411, 53419, 53437, 53441, 53453, 53479, 53503, 53507, 53527, 53549, 53551,
359 53569, 53591, 53593, 53597, 53609, 53611, 53617, 53623, 53629, 53633, 53639, 53653, 53657, 53681, 53693, 53699,
360 53717, 53719, 53731, 53759, 53773, 53777, 53783, 53791, 53813, 53819, 53831, 53849, 53857, 53861, 53881, 53887,
361 53891, 53897, 53899, 53917, 53923, 53927, 53939, 53951, 53959, 53987, 53993, 54001, 54011, 54013, 54037, 54049,
362 54059, 54083, 54091, 54101, 54121, 54133, 54139, 54151, 54163, 54167, 54181, 54193, 54217, 54251, 54269, 54277,
363 54287, 54293, 54311, 54319, 54323, 54331, 54347, 54361, 54367, 54371, 54377, 54401, 54403, 54409, 54413, 54419,
364 54421, 54437, 54443, 54449, 54469, 54493, 54497, 54499, 54503, 54517, 54521, 54539, 54541, 54547, 54559, 54563,
365 54577, 54581, 54583, 54601, 54617, 54623, 54629, 54631, 54647, 54667, 54673, 54679, 54709, 54713, 54721, 54727,
366 54751, 54767, 54773, 54779, 54787, 54799, 54829, 54833, 54851, 54869, 54877, 54881, 54907, 54917, 54919, 54941,
367 54949, 54959, 54973, 54979, 54983, 55001, 55009, 55021, 55049, 55051, 55057, 55061, 55073, 55079, 55103, 55109,
368 55117, 55127, 55147, 55163, 55171, 55201, 55207, 55213, 55217, 55219, 55229, 55243, 55249, 55259, 55291, 55313,
369 55331, 55333, 55337, 55339, 55343, 55351, 55373, 55381, 55399, 55411, 55439, 55441, 55457, 55469, 55487, 55501,
370 55511, 55529, 55541, 55547, 55579, 55589, 55603, 55609, 55619, 55621, 55631, 55633, 55639, 55661, 55663, 55667,
371 55673, 55681, 55691, 55697, 55711, 55717, 55721, 55733, 55763, 55787, 55793, 55799, 55807, 55813, 55817, 55819,
372 55823, 55829, 55837, 55843, 55849, 55871, 55889, 55897, 55901, 55903, 55921, 55927, 55931, 55933, 55949, 55967,
373 55987, 55997, 56003, 56009, 56039, 56041, 56053, 56081, 56087, 56093, 56099, 56101, 56113, 56123, 56131, 56149,
374 56167, 56171, 56179, 56197, 56207, 56209, 56237, 56239, 56249, 56263, 56267, 56269, 56299, 56311, 56333, 56359,
375 56369, 56377, 56383, 56393, 56401, 56417, 56431, 56437, 56443, 56453, 56467, 56473, 56477, 56479, 56489, 56501,
376 56503, 56509, 56519, 56527, 56531, 56533, 56543, 56569, 56591, 56597, 56599, 56611, 56629, 56633, 56659, 56663,
377 56671, 56681, 56687, 56701, 56711, 56713, 56731, 56737, 56747, 56767, 56773, 56779, 56783, 56807, 56809, 56813,
378 56821, 56827, 56843, 56857, 56873, 56891, 56893, 56897, 56909, 56911, 56921, 56923, 56929, 56941, 56951, 56957,
379 56963, 56983, 56989, 56993, 56999, 57037, 57041, 57047, 57059, 57073, 57077, 57089, 57097, 57107, 57119, 57131,
380 57139, 57143, 57149, 57163, 57173, 57179, 57191, 57193, 57203, 57221, 57223, 57241, 57251, 57259, 57269, 57271,
381 57283, 57287, 57301, 57329, 57331, 57347, 57349, 57367, 57373, 57383, 57389, 57397, 57413, 57427, 57457, 57467,
382 57487, 57493, 57503, 57527, 57529, 57557, 57559, 57571, 57587, 57593, 57601, 57637, 57641, 57649, 57653, 57667,
383 57679, 57689, 57697, 57709, 57713, 57719, 57727, 57731, 57737, 57751, 57773, 57781, 57787, 57791, 57793, 57803,
384 57809, 57829, 57839, 57847, 57853, 57859, 57881, 57899, 57901, 57917, 57923, 57943, 57947, 57973, 57977, 57991,
385 58013, 58027, 58031, 58043, 58049, 58057, 58061, 58067, 58073, 58099, 58109, 58111, 58129, 58147, 58151, 58153,
386 58169, 58171, 58189, 58193, 58199, 58207, 58211, 58217, 58229, 58231, 58237, 58243, 58271, 58309, 58313, 58321,
387 58337, 58363, 58367, 58369, 58379, 58391, 58393, 58403, 58411, 58417, 58427, 58439, 58441, 58451, 58453, 58477,
388 58481, 58511, 58537, 58543, 58549, 58567, 58573, 58579, 58601, 58603, 58613, 58631, 58657, 58661, 58679, 58687,
389 58693, 58699, 58711, 58727, 58733, 58741, 58757, 58763, 58771, 58787, 58789, 58831, 58889, 58897, 58901, 58907,
390 58909, 58913, 58921, 58937, 58943, 58963, 58967, 58979, 58991, 58997, 59009, 59011, 59021, 59023, 59029, 59051,
391 59053, 59063, 59069, 59077, 59083, 59093, 59107, 59113, 59119, 59123, 59141, 59149, 59159, 59167, 59183, 59197,
392 59207, 59209, 59219, 59221, 59233, 59239, 59243, 59263, 59273, 59281, 59333, 59341, 59351, 59357, 59359, 59369,
393 59377, 59387, 59393, 59399, 59407, 59417, 59419, 59441, 59443, 59447, 59453, 59467, 59471, 59473, 59497, 59509,
394 59513, 59539, 59557, 59561, 59567, 59581, 59611, 59617, 59621, 59627, 59629, 59651, 59659, 59663, 59669, 59671,
395 59693, 59699, 59707, 59723, 59729, 59743, 59747, 59753, 59771, 59779, 59791, 59797, 59809, 59833, 59863, 59879,
396 59887, 59921, 59929, 59951, 59957, 59971, 59981, 59999, 60013, 60017, 60029, 60037, 60041, 60077, 60083, 60089,
397 60091, 60101, 60103, 60107, 60127, 60133, 60139, 60149, 60161, 60167, 60169, 60209, 60217, 60223, 60251, 60257,
398 60259, 60271, 60289, 60293, 60317, 60331, 60337, 60343, 60353, 60373, 60383, 60397, 60413, 60427, 60443, 60449,
399 60457, 60493, 60497, 60509, 60521, 60527, 60539, 60589, 60601, 60607, 60611, 60617, 60623, 60631, 60637, 60647,
400 60649, 60659, 60661, 60679, 60689, 60703, 60719, 60727, 60733, 60737, 60757, 60761, 60763, 60773, 60779, 60793,
401 60811, 60821, 60859, 60869, 60887, 60889, 60899, 60901, 60913, 60917, 60919, 60923, 60937, 60943, 60953, 60961,
402 61001, 61007, 61027, 61031, 61043, 61051, 61057, 61091, 61099, 61121, 61129, 61141, 61151, 61153, 61169, 61211,
403 61223, 61231, 61253, 61261, 61283, 61291, 61297, 61331, 61333, 61339, 61343, 61357, 61363, 61379, 61381, 61403,
404 61409, 61417, 61441, 61463, 61469, 61471, 61483, 61487, 61493, 61507, 61511, 61519, 61543, 61547, 61553, 61559,
405 61561, 61583, 61603, 61609, 61613, 61627, 61631, 61637, 61643, 61651, 61657, 61667, 61673, 61681, 61687, 61703,
406 61717, 61723, 61729, 61751, 61757, 61781, 61813, 61819, 61837, 61843, 61861, 61871, 61879, 61909, 61927, 61933,
407 61949, 61961, 61967, 61979, 61981, 61987, 61991, 62003, 62011, 62017, 62039, 62047, 62053, 62057, 62071, 62081,
408 62099, 62119, 62129, 62131, 62137, 62141, 62143, 62171, 62189, 62191, 62201, 62207, 62213, 62219, 62233, 62273,
409 62297, 62299, 62303, 62311, 62323, 62327, 62347, 62351, 62383, 62401, 62417, 62423, 62459, 62467, 62473, 62477,
410 62483, 62497, 62501, 62507, 62533, 62539, 62549, 62563, 62581, 62591, 62597, 62603, 62617, 62627, 62633, 62639,
411 62653, 62659, 62683, 62687, 62701, 62723, 62731, 62743, 62753, 62761, 62773, 62791, 62801, 62819, 62827, 62851,
412 62861, 62869, 62873, 62897, 62903, 62921, 62927, 62929, 62939, 62969, 62971, 62981, 62983, 62987, 62989, 63029,
413 63031, 63059, 63067, 63073, 63079, 63097, 63103, 63113, 63127, 63131, 63149, 63179, 63197, 63199, 63211, 63241,
414 63247, 63277, 63281, 63299, 63311, 63313, 63317, 63331, 63337, 63347, 63353, 63361, 63367, 63377, 63389, 63391,
415 63397, 63409, 63419, 63421, 63439, 63443, 63463, 63467, 63473, 63487, 63493, 63499, 63521, 63527, 63533, 63541,
416 63559, 63577, 63587, 63589, 63599, 63601, 63607, 63611, 63617, 63629, 63647, 63649, 63659, 63667, 63671, 63689,
417 63691, 63697, 63703, 63709, 63719, 63727, 63737, 63743, 63761, 63773, 63781, 63793, 63799, 63803, 63809, 63823,
418 63839, 63841, 63853, 63857, 63863, 63901, 63907, 63913, 63929, 63949, 63977, 63997, 64007, 64013, 64019, 64033,
419 64037, 64063, 64067, 64081, 64091, 64109, 64123, 64151, 64153, 64157, 64171, 64187, 64189, 64217, 64223, 64231,
420 64237, 64271, 64279, 64283, 64301, 64303, 64319, 64327, 64333, 64373, 64381, 64399, 64403, 64433, 64439, 64451,
421 64453, 64483, 64489, 64499, 64513, 64553, 64567, 64577, 64579, 64591, 64601, 64609, 64613, 64621, 64627, 64633,
422 64661, 64663, 64667, 64679, 64693, 64709, 64717, 64747, 64763, 64781, 64783, 64793, 64811, 64817, 64849, 64853,
423 64871, 64877, 64879, 64891, 64901, 64919, 64921, 64927, 64937, 64951, 64969, 64997, 65003, 65011, 65027, 65029,
424 65033, 65053, 65063, 65071, 65089, 65099, 65101, 65111, 65119, 65123, 65129, 65141, 65147, 65167, 65171, 65173,
425 65179, 65183, 65203, 65213, 65239, 65257, 65267, 65269, 65287, 65293, 65309, 65323, 65327, 65353, 65357, 65371,
426 65381, 65393, 65407, 65413, 65419, 65423, 65437, 65447, 65449, 65479, 65497, 65519, 65521, 0};

Referenced by random_prime().

◆ SHA256_K

uint32_t Botan::SHA256_K[64]
inlineconstexpr
Initial value:
= {
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
}

Definition at line 19 of file sha2_32_f.h.

19 {
20 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
21 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
22 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
23 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
24 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
25 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
26 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
27 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2,
28};

Referenced by Botan::SHA_256::compress_digest(), Botan::SHA_256::compress_digest_armv8(), Botan::SHA_256::compress_digest_x86(), sha2_32_mb_compress_x16(), and sha2_32_mb_compress_x8().

◆ SHA512_K

uint64_t Botan::SHA512_K[80]
inlineconstexpr
Initial value:
= {
0x428A2F98D728AE22, 0x7137449123EF65CD, 0xB5C0FBCFEC4D3B2F, 0xE9B5DBA58189DBBC, 0x3956C25BF348B538,
0x59F111F1B605D019, 0x923F82A4AF194F9B, 0xAB1C5ED5DA6D8118, 0xD807AA98A3030242, 0x12835B0145706FBE,
0x243185BE4EE4B28C, 0x550C7DC3D5FFB4E2, 0x72BE5D74F27B896F, 0x80DEB1FE3B1696B1, 0x9BDC06A725C71235,
0xC19BF174CF692694, 0xE49B69C19EF14AD2, 0xEFBE4786384F25E3, 0x0FC19DC68B8CD5B5, 0x240CA1CC77AC9C65,
0x2DE92C6F592B0275, 0x4A7484AA6EA6E483, 0x5CB0A9DCBD41FBD4, 0x76F988DA831153B5, 0x983E5152EE66DFAB,
0xA831C66D2DB43210, 0xB00327C898FB213F, 0xBF597FC7BEEF0EE4, 0xC6E00BF33DA88FC2, 0xD5A79147930AA725,
0x06CA6351E003826F, 0x142929670A0E6E70, 0x27B70A8546D22FFC, 0x2E1B21385C26C926, 0x4D2C6DFC5AC42AED,
0x53380D139D95B3DF, 0x650A73548BAF63DE, 0x766A0ABB3C77B2A8, 0x81C2C92E47EDAEE6, 0x92722C851482353B,
0xA2BFE8A14CF10364, 0xA81A664BBC423001, 0xC24B8B70D0F89791, 0xC76C51A30654BE30, 0xD192E819D6EF5218,
0xD69906245565A910, 0xF40E35855771202A, 0x106AA07032BBD1B8, 0x19A4C116B8D2D0C8, 0x1E376C085141AB53,
0x2748774CDF8EEB99, 0x34B0BCB5E19B48A8, 0x391C0CB3C5C95A63, 0x4ED8AA4AE3418ACB, 0x5B9CCA4F7763E373,
0x682E6FF3D6B2B8A3, 0x748F82EE5DEFB2FC, 0x78A5636F43172F60, 0x84C87814A1F0AB72, 0x8CC702081A6439EC,
0x90BEFFFA23631E28, 0xA4506CEBDE82BDE9, 0xBEF9A3F7B2C67915, 0xC67178F2E372532B, 0xCA273ECEEA26619C,
0xD186B8C721C0C207, 0xEADA7DD6CDE0EB1E, 0xF57D4F7FEE6ED178, 0x06F067AA72176FBA, 0x0A637DC5A2C898A6,
0x113F9804BEF90DAE, 0x1B710B35131C471B, 0x28DB77F523047D84, 0x32CAAB7B40C72493, 0x3C9EBE0A15C9BEBC,
0x431D67C49C100D4C, 0x4CC5D4BECB3E42B6, 0x597F299CFC657E2A, 0x5FCB6FAB3AD6FAEC, 0x6C44198C4A475817,
}

Definition at line 19 of file sha2_64_f.h.

19 {
20 0x428A2F98D728AE22, 0x7137449123EF65CD, 0xB5C0FBCFEC4D3B2F, 0xE9B5DBA58189DBBC, 0x3956C25BF348B538,
21 0x59F111F1B605D019, 0x923F82A4AF194F9B, 0xAB1C5ED5DA6D8118, 0xD807AA98A3030242, 0x12835B0145706FBE,
22 0x243185BE4EE4B28C, 0x550C7DC3D5FFB4E2, 0x72BE5D74F27B896F, 0x80DEB1FE3B1696B1, 0x9BDC06A725C71235,
23 0xC19BF174CF692694, 0xE49B69C19EF14AD2, 0xEFBE4786384F25E3, 0x0FC19DC68B8CD5B5, 0x240CA1CC77AC9C65,
24 0x2DE92C6F592B0275, 0x4A7484AA6EA6E483, 0x5CB0A9DCBD41FBD4, 0x76F988DA831153B5, 0x983E5152EE66DFAB,
25 0xA831C66D2DB43210, 0xB00327C898FB213F, 0xBF597FC7BEEF0EE4, 0xC6E00BF33DA88FC2, 0xD5A79147930AA725,
26 0x06CA6351E003826F, 0x142929670A0E6E70, 0x27B70A8546D22FFC, 0x2E1B21385C26C926, 0x4D2C6DFC5AC42AED,
27 0x53380D139D95B3DF, 0x650A73548BAF63DE, 0x766A0ABB3C77B2A8, 0x81C2C92E47EDAEE6, 0x92722C851482353B,
28 0xA2BFE8A14CF10364, 0xA81A664BBC423001, 0xC24B8B70D0F89791, 0xC76C51A30654BE30, 0xD192E819D6EF5218,
29 0xD69906245565A910, 0xF40E35855771202A, 0x106AA07032BBD1B8, 0x19A4C116B8D2D0C8, 0x1E376C085141AB53,
30 0x2748774CDF8EEB99, 0x34B0BCB5E19B48A8, 0x391C0CB3C5C95A63, 0x4ED8AA4AE3418ACB, 0x5B9CCA4F7763E373,
31 0x682E6FF3D6B2B8A3, 0x748F82EE5DEFB2FC, 0x78A5636F43172F60, 0x84C87814A1F0AB72, 0x8CC702081A6439EC,
32 0x90BEFFFA23631E28, 0xA4506CEBDE82BDE9, 0xBEF9A3F7B2C67915, 0xC67178F2E372532B, 0xCA273ECEEA26619C,
33 0xD186B8C721C0C207, 0xEADA7DD6CDE0EB1E, 0xF57D4F7FEE6ED178, 0x06F067AA72176FBA, 0x0A637DC5A2C898A6,
34 0x113F9804BEF90DAE, 0x1B710B35131C471B, 0x28DB77F523047D84, 0x32CAAB7B40C72493, 0x3C9EBE0A15C9BEBC,
35 0x431D67C49C100D4C, 0x4CC5D4BECB3E42B6, 0x597F299CFC657E2A, 0x5FCB6FAB3AD6FAEC, 0x6C44198C4A475817,
36};

Referenced by Botan::SHA_512::compress_digest(), sha2_64_mb_compress_x4(), and sha2_64_mb_compress_x8().

◆ STREEBOG_C

uint64_t Botan::STREEBOG_C[12][8]
constexpr
Initial value:
= {
{0xb1085bda1ecadae9, 0xebcb2f81c0657c1f, 0x2f6a76432e45d016, 0x714eb88d7585c4fc,
0x4b7ce09192676901, 0xa2422a08a460d315, 0x05767436cc744d23, 0xdd806559f2a64507},
{0x6fa3b58aa99d2f1a, 0x4fe39d460f70b5d7, 0xf3feea720a232b98, 0x61d55e0f16b50131,
0x9ab5176b12d69958, 0x5cb561c2db0aa7ca, 0x55dda21bd7cbcd56, 0xe679047021b19bb7},
{0xf574dcac2bce2fc7, 0x0a39fc286a3d8435, 0x06f15e5f529c1f8b, 0xf2ea7514b1297b7b,
0xd3e20fe490359eb1, 0xc1c93a376062db09, 0xc2b6f443867adb31, 0x991e96f50aba0ab2},
{0xef1fdfb3e81566d2, 0xf948e1a05d71e4dd, 0x488e857e335c3c7d, 0x9d721cad685e353f,
0xa9d72c82ed03d675, 0xd8b71333935203be, 0x3453eaa193e837f1, 0x220cbebc84e3d12e},
{0x4bea6bacad474799, 0x9a3f410c6ca92363, 0x7f151c1f1686104a, 0x359e35d7800fffbd,
0xbfcd1747253af5a3, 0xdfff00b723271a16, 0x7a56a27ea9ea63f5, 0x601758fd7c6cfe57},
{0xae4faeae1d3ad3d9, 0x6fa4c33b7a3039c0, 0x2d66c4f95142a46c, 0x187f9ab49af08ec6,
0xcffaa6b71c9ab7b4, 0x0af21f66c2bec6b6, 0xbf71c57236904f35, 0xfa68407a46647d6e},
{0xf4c70e16eeaac5ec, 0x51ac86febf240954, 0x399ec6c7e6bf87c9, 0xd3473e33197a93c9,
0x0992abc52d822c37, 0x06476983284a0504, 0x3517454ca23c4af3, 0x8886564d3a14d493},
{0x9b1f5b424d93c9a7, 0x03e7aa020c6e4141, 0x4eb7f8719c36de1e, 0x89b4443b4ddbc49a,
0xf4892bcb929b0690, 0x69d18d2bd1a5c42f, 0x36acc2355951a8d9, 0xa47f0dd4bf02e71e},
{0x378f5a541631229b, 0x944c9ad8ec165fde, 0x3a7d3a1b25894224, 0x3cd955b7e00d0984,
0x800a440bdbb2ceb1, 0x7b2b8a9aa6079c54, 0x0e38dc92cb1f2a60, 0x7261445183235adb},
{0xabbedea680056f52, 0x382ae548b2e4f3f3, 0x8941e71cff8a78db, 0x1fffe18a1b336103,
0x9fe76702af69334b, 0x7a1e6c303b7652f4, 0x3698fad1153bb6c3, 0x74b4c7fb98459ced},
{0x7bcd9ed0efc889fb, 0x3002c6cd635afe94, 0xd8fa6bbbebab0761, 0x2001802114846679,
0x8a1d71efea48b9ca, 0xefbacd1d7d476e98, 0xdea2594ac06fd85d, 0x6bcaa4cd81f32d1b},
{0x378ee767f11631ba, 0xd21380b00449b17a, 0xcda43c32bcdf1d77, 0xf82012d430219f9b,
0x5d80ef9d1891cc86, 0xe71da4aa88e12852, 0xfaf417d5d9b21b99, 0x48bc924af11bd720},
}

Definition at line 44 of file streebog_const.h.

44 {
45 {0xb1085bda1ecadae9, 0xebcb2f81c0657c1f, 0x2f6a76432e45d016, 0x714eb88d7585c4fc,
46 0x4b7ce09192676901, 0xa2422a08a460d315, 0x05767436cc744d23, 0xdd806559f2a64507},
47 {0x6fa3b58aa99d2f1a, 0x4fe39d460f70b5d7, 0xf3feea720a232b98, 0x61d55e0f16b50131,
48 0x9ab5176b12d69958, 0x5cb561c2db0aa7ca, 0x55dda21bd7cbcd56, 0xe679047021b19bb7},
49 {0xf574dcac2bce2fc7, 0x0a39fc286a3d8435, 0x06f15e5f529c1f8b, 0xf2ea7514b1297b7b,
50 0xd3e20fe490359eb1, 0xc1c93a376062db09, 0xc2b6f443867adb31, 0x991e96f50aba0ab2},
51 {0xef1fdfb3e81566d2, 0xf948e1a05d71e4dd, 0x488e857e335c3c7d, 0x9d721cad685e353f,
52 0xa9d72c82ed03d675, 0xd8b71333935203be, 0x3453eaa193e837f1, 0x220cbebc84e3d12e},
53 {0x4bea6bacad474799, 0x9a3f410c6ca92363, 0x7f151c1f1686104a, 0x359e35d7800fffbd,
54 0xbfcd1747253af5a3, 0xdfff00b723271a16, 0x7a56a27ea9ea63f5, 0x601758fd7c6cfe57},
55 {0xae4faeae1d3ad3d9, 0x6fa4c33b7a3039c0, 0x2d66c4f95142a46c, 0x187f9ab49af08ec6,
56 0xcffaa6b71c9ab7b4, 0x0af21f66c2bec6b6, 0xbf71c57236904f35, 0xfa68407a46647d6e},
57 {0xf4c70e16eeaac5ec, 0x51ac86febf240954, 0x399ec6c7e6bf87c9, 0xd3473e33197a93c9,
58 0x0992abc52d822c37, 0x06476983284a0504, 0x3517454ca23c4af3, 0x8886564d3a14d493},
59 {0x9b1f5b424d93c9a7, 0x03e7aa020c6e4141, 0x4eb7f8719c36de1e, 0x89b4443b4ddbc49a,
60 0xf4892bcb929b0690, 0x69d18d2bd1a5c42f, 0x36acc2355951a8d9, 0xa47f0dd4bf02e71e},
61 {0x378f5a541631229b, 0x944c9ad8ec165fde, 0x3a7d3a1b25894224, 0x3cd955b7e00d0984,
62 0x800a440bdbb2ceb1, 0x7b2b8a9aa6079c54, 0x0e38dc92cb1f2a60, 0x7261445183235adb},
63 {0xabbedea680056f52, 0x382ae548b2e4f3f3, 0x8941e71cff8a78db, 0x1fffe18a1b336103,
64 0x9fe76702af69334b, 0x7a1e6c303b7652f4, 0x3698fad1153bb6c3, 0x74b4c7fb98459ced},
65 {0x7bcd9ed0efc889fb, 0x3002c6cd635afe94, 0xd8fa6bbbebab0761, 0x2001802114846679,
66 0x8a1d71efea48b9ca, 0xefbacd1d7d476e98, 0xdea2594ac06fd85d, 0x6bcaa4cd81f32d1b},
67 {0x378ee767f11631ba, 0xd21380b00449b17a, 0xcda43c32bcdf1d77, 0xf82012d430219f9b,
68 0x5d80ef9d1891cc86, 0xe71da4aa88e12852, 0xfaf417d5d9b21b99, 0x48bc924af11bd720},
69};

Referenced by Botan::Streebog::compress_64().

◆ STREEBOG_L

uint64_t Botan::STREEBOG_L[8]
constexpr
Initial value:
= {
0x641c314b2b8ee083,
0xa48b474f9ef5dc18,
0xf97d86d98a327728,
0x5b068c651810a89e,
0x0321658cba93c138,
0xaccc9ca9328a8950,
0x46b60f011a83988e,
0x83478b07b2468764,
}

Definition at line 32 of file streebog_const.h.

32 {
33 0x641c314b2b8ee083,
34 0xa48b474f9ef5dc18,
35 0xf97d86d98a327728,
36 0x5b068c651810a89e,
37 0x0321658cba93c138,
38 0xaccc9ca9328a8950,
39 0x46b60f011a83988e,
40 0x83478b07b2468764,
41};

◆ STREEBOG_S

const constexpr uint8_t Botan::STREEBOG_S[256]
constexpr
Initial value:
= {
252, 238, 221, 17, 207, 110, 49, 22, 251, 196, 250, 218, 35, 197, 4, 77, 233, 119, 240, 219, 147, 46,
153, 186, 23, 54, 241, 187, 20, 205, 95, 193, 249, 24, 101, 90, 226, 92, 239, 33, 129, 28, 60, 66,
139, 1, 142, 79, 5, 132, 2, 174, 227, 106, 143, 160, 6, 11, 237, 152, 127, 212, 211, 31, 235, 52,
44, 81, 234, 200, 72, 171, 242, 42, 104, 162, 253, 58, 206, 204, 181, 112, 14, 86, 8, 12, 118, 18,
191, 114, 19, 71, 156, 183, 93, 135, 21, 161, 150, 41, 16, 123, 154, 199, 243, 145, 120, 111, 157, 158,
178, 177, 50, 117, 25, 61, 255, 53, 138, 126, 109, 84, 198, 128, 195, 189, 13, 87, 223, 245, 36, 169,
62, 168, 67, 201, 215, 121, 214, 246, 124, 34, 185, 3, 224, 15, 236, 222, 122, 148, 176, 188, 220, 232,
40, 80, 78, 51, 10, 74, 167, 151, 96, 115, 30, 0, 98, 68, 26, 184, 56, 130, 100, 159, 38, 65,
173, 69, 70, 146, 39, 94, 85, 47, 140, 163, 165, 125, 105, 213, 149, 59, 7, 88, 179, 64, 134, 172,
29, 247, 48, 55, 107, 228, 136, 217, 231, 137, 225, 27, 131, 73, 76, 63, 248, 254, 141, 83, 170, 144,
202, 216, 133, 97, 32, 113, 103, 164, 45, 43, 9, 91, 203, 155, 37, 208, 190, 229, 108, 82, 89, 166,
116, 210, 230, 244, 180, 192, 209, 102, 175, 194, 57, 75, 99, 182,
}

Definition at line 16 of file streebog_const.h.

16 {
17 252, 238, 221, 17, 207, 110, 49, 22, 251, 196, 250, 218, 35, 197, 4, 77, 233, 119, 240, 219, 147, 46,
18 153, 186, 23, 54, 241, 187, 20, 205, 95, 193, 249, 24, 101, 90, 226, 92, 239, 33, 129, 28, 60, 66,
19 139, 1, 142, 79, 5, 132, 2, 174, 227, 106, 143, 160, 6, 11, 237, 152, 127, 212, 211, 31, 235, 52,
20 44, 81, 234, 200, 72, 171, 242, 42, 104, 162, 253, 58, 206, 204, 181, 112, 14, 86, 8, 12, 118, 18,
21 191, 114, 19, 71, 156, 183, 93, 135, 21, 161, 150, 41, 16, 123, 154, 199, 243, 145, 120, 111, 157, 158,
22 178, 177, 50, 117, 25, 61, 255, 53, 138, 126, 109, 84, 198, 128, 195, 189, 13, 87, 223, 245, 36, 169,
23 62, 168, 67, 201, 215, 121, 214, 246, 124, 34, 185, 3, 224, 15, 236, 222, 122, 148, 176, 188, 220, 232,
24 40, 80, 78, 51, 10, 74, 167, 151, 96, 115, 30, 0, 98, 68, 26, 184, 56, 130, 100, 159, 38, 65,
25 173, 69, 70, 146, 39, 94, 85, 47, 140, 163, 165, 125, 105, 213, 149, 59, 7, 88, 179, 64, 134, 172,
26 29, 247, 48, 55, 107, 228, 136, 217, 231, 137, 225, 27, 131, 73, 76, 63, 248, 254, 141, 83, 170, 144,
27 202, 216, 133, 97, 32, 113, 103, 164, 45, 43, 9, 91, 203, 155, 37, 208, 190, 229, 108, 82, 89, 166,
28 116, 210, 230, 244, 180, 192, 209, 102, 175, 194, 57, 75, 99, 182,
29};

◆ WORDS_448

◆ X448_LEN