| 1 | #cxx . . $ `<file>/mlspp/lib/hpke/src/rsa.h`/pragma once |
| 2 | |
| 3 | #include <hpke/digest.h>cxx . . $ `<file>/mlspp/lib/hpke/include/hpke/digest.h`/ |
| 4 | #include <hpke/hpke.h>cxx . . $ `<file>/mlspp/lib/hpke/include/hpke/hpke.h`/ |
| 5 | #include <hpke/signature.h>cxx . . $ `<file>/mlspp/lib/hpke/include/hpke/signature.h`/ |
| 6 | |
| 7 | #include "openssl_common.h"cxx . . $ `<file>/mlspp/lib/hpke/src/openssl_common.h`/ |
| 8 | #include <openssl/evp.h> |
| 9 | #include <openssl/rsa.h> |
| 10 | |
| 11 | namespace mlsppcxx . . $ mlspp/::hpkecxx . . $ mlspp/hpke/ { |
| 12 | |
| 13 | // XXX(RLB): There is a lot of code in RSASignature that is duplicated in |
| 14 | // EVPGroup. I have allowed this duplication rather than factoring it out |
| 15 | // because I would like to be able to cleanly remove RSA later. |
| 16 | struct RSASignaturecxx . . $ mlspp/hpke/RSASignature# : public Signaturecxx . . $ mlspp/hpke/Signature# |
| 17 | { |
| 18 | struct PublicKeycxx . . $ mlspp/hpke/RSASignature#PublicKey# : public Signaturecxx . . $ mlspp/hpke/Signature#::PublicKeycxx . . $ mlspp/hpke/Signature#PublicKey# |
| 19 | { |
| 20 | explicit PublicKeycxx . . $ mlspp/hpke/RSASignature#PublicKey#PublicKey(a36cc1e96a19ea9b).(EVP_PKEY* pkey_in) |
| 21 | : pkeycxx . . $ std/unique_ptr#unique_ptr(301a195fca954409).(pkey_in, typed_deletecxx . . $ mlspp/hpke/typed_delete(ebd0a1552f8ce24f).<EVP_PKEY>) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | ~cxx . . $ mlspp/hpke/RSASignature#PublicKey#`~PublicKey`(ced63f7c635d850d).PublicKeycxx . . $ mlspp/hpke/RSASignature#PublicKey#() override = default; |
| 26 | |
| 27 | typed_unique_ptrcxx . . $ mlspp/hpke/typed_unique_ptr#<EVP_PKEY> pkeycxx . . $ mlspp/hpke/RSASignature#PublicKey#pkey.; |
| 28 | }; |
| 29 | |
| 30 | struct PrivateKeycxx . . $ mlspp/hpke/RSASignature#PrivateKey# : public Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey# |
| 31 | { |
| 32 | explicit PrivateKeycxx . . $ mlspp/hpke/RSASignature#PrivateKey#PrivateKey(a36cc1e96a19ea9b).(EVP_PKEY* pkey_in) |
| 33 | : pkeycxx . . $ std/unique_ptr#unique_ptr(301a195fca954409).(pkey_in, typed_deletecxx . . $ mlspp/hpke/typed_delete(ebd0a1552f8ce24f).<EVP_PKEY>) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | ~cxx . . $ mlspp/hpke/RSASignature#PrivateKey#`~PrivateKey`(ced63f7c635d850d).PrivateKeycxx . . $ mlspp/hpke/RSASignature#PrivateKey#() override = default; |
| 38 | |
| 39 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Signaturecxx . . $ mlspp/hpke/Signature#::PublicKeycxx . . $ mlspp/hpke/Signature#PublicKey#> public_keycxx . . $ mlspp/hpke/RSASignature#PrivateKey#public_key(cad5d51d56ce4928).() const override |
| 40 | { |
| 41 | if (1 != EVP_PKEY_up_ref(pkeycxx . . $ mlspp/hpke/RSASignature#PrivateKey#pkey..getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).())) { |
| 42 | throw openssl_errorcxx . . $ mlspp/hpke/openssl_error(d6ab8afd00dfc651).(); |
| 43 | } |
| 44 | return stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<PublicKeycxx . . $ mlspp/hpke/RSASignature#PublicKey#>(pkeycxx . . $ mlspp/hpke/RSASignature#PrivateKey#pkey..getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).()); |
| 45 | } |
| 46 | |
| 47 | typed_unique_ptrcxx . . $ mlspp/hpke/typed_unique_ptr#<EVP_PKEY> pkeycxx . . $ mlspp/hpke/RSASignature#PrivateKey#pkey.; |
| 48 | }; |
| 49 | |
| 50 | explicit RSASignaturecxx . . $ mlspp/hpke/RSASignature#RSASignature(d9440e2b4bfeadf0).(Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID# digest) |
| 51 | : Signaturecxx . . $ mlspp/hpke/Signature#(digest_to_sigcxx . . $ mlspp/hpke/RSASignature#digest_to_sig(2a00588ea9a0b069).(digest)) |
| 52 | , mdcxx . . $ mlspp/hpke/RSASignature#md.(digest_to_mdcxx . . $ mlspp/hpke/RSASignature#digest_to_md(1f8ed912f6c8613e).(digest)) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey#> generate_key_paircxx . . $ mlspp/hpke/RSASignature#generate_key_pair(8d27edcb683c805).() const override; |
| 57 | |
| 58 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey#> derive_key_paircxx . . $ mlspp/hpke/RSASignature#derive_key_pair(5746faca826a5ccd).( |
| 59 | const bytescxx . . $ mlspp/bytes_ns/bytes#& /*ikm*/) const override; |
| 60 | |
| 61 | static stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey#> generate_key_paircxx . . $ mlspp/hpke/RSASignature#generate_key_pair(d159d62625d1ec8f).(size_tcxx . . $ size_t# bits); |
| 62 | |
| 63 | // TODO(rlb): Implement derive() with sizes |
| 64 | |
| 65 | bytescxx . . $ mlspp/bytes_ns/bytes# serializecxx . . $ mlspp/hpke/RSASignature#serialize(85b79100656811f8).(const Signaturecxx . . $ mlspp/hpke/Signature#::PublicKeycxx . . $ mlspp/hpke/Signature#PublicKey#& pk) const override; |
| 66 | |
| 67 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Signaturecxx . . $ mlspp/hpke/Signature#::PublicKeycxx . . $ mlspp/hpke/Signature#PublicKey#> deserializecxx . . $ mlspp/hpke/RSASignature#deserialize(321ec828a61140d).( |
| 68 | const bytescxx . . $ mlspp/bytes_ns/bytes#& enc) const override; |
| 69 | |
| 70 | bytescxx . . $ mlspp/bytes_ns/bytes# serialize_privatecxx . . $ mlspp/hpke/RSASignature#serialize_private(46640a7490dcfaec).(const Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey#& sk) const override; |
| 71 | |
| 72 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey#> deserialize_privatecxx . . $ mlspp/hpke/RSASignature#deserialize_private(5746faca826a5ccd).( |
| 73 | const bytescxx . . $ mlspp/bytes_ns/bytes#& skm) const override; |
| 74 | |
| 75 | bytescxx . . $ mlspp/bytes_ns/bytes# signcxx . . $ mlspp/hpke/RSASignature#sign(4ebbf3240e588aaf).(const bytescxx . . $ mlspp/bytes_ns/bytes#& data, const Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey#& sk) const override; |
| 76 | |
| 77 | bool verifycxx . . $ mlspp/hpke/RSASignature#verify(c2ebb5c61451baa6).(const bytescxx . . $ mlspp/bytes_ns/bytes#& data, |
| 78 | const bytescxx . . $ mlspp/bytes_ns/bytes#& sig, |
| 79 | const Signaturecxx . . $ mlspp/hpke/Signature#::PublicKeycxx . . $ mlspp/hpke/Signature#PublicKey#& pk) const override; |
| 80 | |
| 81 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey#> import_jwk_privatecxx . . $ mlspp/hpke/RSASignature#import_jwk_private(8828a0bfc3408e3c).( |
| 82 | const stdcxx . . $ std/::stringcxx . . $ std/string#& json_str) const override; |
| 83 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Signaturecxx . . $ mlspp/hpke/Signature#::PublicKeycxx . . $ mlspp/hpke/Signature#PublicKey#> import_jwkcxx . . $ mlspp/hpke/RSASignature#import_jwk(a53063c3da59064e).( |
| 84 | const stdcxx . . $ std/::stringcxx . . $ std/string#& json_str) const override; |
| 85 | stdcxx . . $ std/::stringcxx . . $ std/string# export_jwk_privatecxx . . $ mlspp/hpke/RSASignature#export_jwk_private(9eb010d7f7e5c82e).( |
| 86 | const Signaturecxx . . $ mlspp/hpke/Signature#::PrivateKeycxx . . $ mlspp/hpke/Signature#PrivateKey#& sk) const override; |
| 87 | stdcxx . . $ std/::stringcxx . . $ std/string# export_jwkcxx . . $ mlspp/hpke/RSASignature#export_jwk(f9fdd4f558be28e4).(const Signaturecxx . . $ mlspp/hpke/Signature#::PublicKeycxx . . $ mlspp/hpke/Signature#PublicKey#& pk) const override; |
| 88 | |
| 89 | private: |
| 90 | const EVP_MD* mdcxx . . $ mlspp/hpke/RSASignature#md.; |
| 91 | |
| 92 | static const EVP_MD* digest_to_mdcxx . . $ mlspp/hpke/RSASignature#digest_to_md(1f8ed912f6c8613e).(Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID# digest); |
| 93 | |
| 94 | static Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID# digest_to_sigcxx . . $ mlspp/hpke/RSASignature#digest_to_sig(2a00588ea9a0b069).(Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID# digest); |
| 95 | }; |
| 96 | |
| 97 | } // namespace mlspp::hpke |