31 #ifndef _SCC_CRYPTO_RSA_H
32 #define _SCC_CRYPTO_RSA_H
40 namespace scc::crypto {
83 m_n = std::move(other.m_n);
84 m_e = std::move(other.m_e);
119 return m_n == o.m_n && m_e == o.m_e;
124 return m_n != o.m_n || m_e != o.m_e;
146 std::string
str(
unsigned = 8)
const;
154 return ((
width()+7)&~7)/8;
199 m_n = std::move(other.m_n);
200 m_e = std::move(other.m_e);
201 m_d = std::move(other.m_d);
202 m_p = std::move(other.m_p);
203 m_q = std::move(other.m_q);
204 m_ep = std::move(other.m_ep);
205 m_eq = std::move(other.m_eq);
206 m_qinv = std::move(other.m_qinv);
218 m_qinv = other.m_qinv;
247 return m_n == o.m_n && m_e == o.m_e && m_d == o.m_d && m_p == o.m_p && m_q == o.m_q && m_ep == o.m_ep && m_eq == o.m_eq && m_qinv == o.m_qinv;
252 return m_n != o.m_n || m_e != o.m_e || m_d != o.m_d || m_p != o.m_p || m_q != o.m_q || m_ep != o.m_ep || m_eq != o.m_eq || m_qinv != o.m_qinv;
262 std::string
str(
unsigned = 8)
const;
322 struct RsaOaepEncryptCtx;
330 std::unique_ptr<RsaOaepEncryptCtx> m_ctx;
361 void encrypt(
const void*,
int,
void*,
int,
const void* =
nullptr,
int = 0);
364 struct RsaOaepDecryptCtx;
374 std::unique_ptr<RsaOaepDecryptCtx> m_ctx;
405 int decrypt(
void*,
int,
const void*,
int,
const void* =
nullptr,
int = 0);
450 static void sign(
const void*,
int,
void*,
int,
const RsaPrivateKey&, PssSignature::HashType,
int = 0);
451 static void sign(
const void* loc,
int len, std::vector<char>& sig,
const RsaPrivateKey& key, PssSignature::HashType hash,
int salt_len = 0)
453 sig.resize(
size(key));
454 sign(loc, len, sig.data(), sig.size(), key, hash, salt_len);
469 static bool verify(
const void* loc,
int len,
const std::vector<char>& sig,
const RsaPublicKey& key, PssSignature::HashType hash)
471 return verify(loc, len, sig.data(), sig.size(), key, hash);
515 static void sign(
const void* loc,
int len, std::vector<char>& sig,
const RsaPrivateKey& key, PkcsSignature::HashType hash)
517 sig.resize(
size(key));
518 sign(loc, len, sig.data(), sig.size(), key, hash);
520 static void sign(
const void* loc,
int len, std::vector<uint8_t>& sig,
const RsaPrivateKey& key, PkcsSignature::HashType hash)
522 sig.resize(
size(key));
523 sign(loc, len, sig.data(), sig.size(), key, hash);
537 static bool verify(
const void*,
int,
const void*,
int,
const RsaPublicKey&, PkcsSignature::HashType);
538 static bool verify(
const void* loc,
int len,
const std::vector<char>& sig,
const RsaPublicKey& key, PkcsSignature::HashType hash)
540 return verify(loc, len, sig.data(), sig.size(), key, hash);
PKCS #1 version 1.5 digital signature.
static void sign(const void *, int, void *, int, const RsaPrivateKey &, PkcsSignature::HashType)
Sign the signature using a private key.
static int size(const RsaPublicKey &k)
Size of signature in bytes.
static bool verify(const void *, int, const void *, int, const RsaPublicKey &, PkcsSignature::HashType)
Verify the signature using a public key.
RSASSA-PSS https://tools.ietf.org/html/rfc8017#section-8.1 Notes on use in x.509: https://tools....
static bool verify(const void *, int, const void *, int, const RsaPublicKey &, PssSignature::HashType)
Verify the signature using a public key.
static int size(const RsaPublicKey &k)
Size of signature in bytes.
static void sign(const void *, int, void *, int, const RsaPrivateKey &, PssSignature::HashType, int=0)
Sign the signature using a private key.
int decrypt(void *, int, const void *, int, const void *=nullptr, int=0)
Decrypt a message.
int cipher_size() const
Cipher text length in bytes.
int max_msg_size() const
The maximum allowable plain text message length in bytes.
RsaOaepDecrypt(RsaPrivateKey &, Hash::Algorithm=Hash::sha1_type)
Construct an RSA decryptor.
int cipher_size() const
Cipher text size in bytes.
RsaOaepEncrypt(RsaPublicKey &, Hash::Algorithm=Hash::sha1_type)
Construct an RSA encryptor.
int max_msg_size() const
The maximum allowable plain text size in bytes.
void encrypt(const void *, int, void *, int, const void *=nullptr, int=0)
Encrypt a message.
bool validate(const RsaPublicKey &) const
Validate a public key with the private key.
std::string dump() const
Dump a string with full values.
void clear()
Clear and erase all data.
bool validate() const
Validate with my public key.
std::string str(unsigned=8) const
Output with formatted values.
void generate(int)
Generate a private key.
RsaPublicKey pub_key() const
Export the public key.
int width() const
Bit width of the key.
std::string dump() const
Output with full values.
int width_bytes() const
Width in bytes of this key.
std::string str(unsigned=8) const
Output with formatted values.
void clear()
Clear and erase all data.
One-way hashing and message digests.