mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:52:45 +00:00 
			
		
		
		
	LibCrypto: Yet more ByteBuffer::wrap() removal. Not much left now!
This commit is contained in:
		
							parent
							
								
									497f1fd472
								
							
						
					
					
						commit
						a8dbfc3398
					
				
					 4 changed files with 14 additions and 14 deletions
				
			
		|  | @ -52,8 +52,8 @@ public: | ||||||
|     virtual void encrypt(ReadonlyBytes in, ByteBuffer& out) = 0; |     virtual void encrypt(ReadonlyBytes in, ByteBuffer& out) = 0; | ||||||
|     virtual void decrypt(ReadonlyBytes in, ByteBuffer& out) = 0; |     virtual void decrypt(ReadonlyBytes in, ByteBuffer& out) = 0; | ||||||
| 
 | 
 | ||||||
|     virtual void sign(ReadonlyBytes in, ByteBuffer& out) = 0; |     virtual void sign(ReadonlyBytes in, Bytes& out) = 0; | ||||||
|     virtual void verify(ReadonlyBytes in, ByteBuffer& out) = 0; |     virtual void verify(ReadonlyBytes in, Bytes& out) = 0; | ||||||
| 
 | 
 | ||||||
|     virtual String class_name() const = 0; |     virtual String class_name() const = 0; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -149,7 +149,7 @@ void RSA::decrypt(ReadonlyBytes in, ByteBuffer& out) | ||||||
|     out = out.slice(out.size() - aligned_size, aligned_size); |     out = out.slice(out.size() - aligned_size, aligned_size); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void RSA::sign(ReadonlyBytes in, ByteBuffer& out) | void RSA::sign(ReadonlyBytes in, Bytes& out) | ||||||
| { | { | ||||||
|     auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size()); |     auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size()); | ||||||
|     auto exp = NumberTheory::ModularPower(in_integer, m_private_key.private_exponent(), m_private_key.modulus()); |     auto exp = NumberTheory::ModularPower(in_integer, m_private_key.private_exponent(), m_private_key.modulus()); | ||||||
|  | @ -157,7 +157,7 @@ void RSA::sign(ReadonlyBytes in, ByteBuffer& out) | ||||||
|     out = out.slice(out.size() - size, size); |     out = out.slice(out.size() - size, size); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void RSA::verify(ReadonlyBytes in, ByteBuffer& out) | void RSA::verify(ReadonlyBytes in, Bytes& out) | ||||||
| { | { | ||||||
|     auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size()); |     auto in_integer = UnsignedBigInteger::import_data(in.data(), in.size()); | ||||||
|     auto exp = NumberTheory::ModularPower(in_integer, m_public_key.public_exponent(), m_public_key.modulus()); |     auto exp = NumberTheory::ModularPower(in_integer, m_public_key.public_exponent(), m_public_key.modulus()); | ||||||
|  | @ -198,7 +198,7 @@ void RSA::import_public_key(ReadonlyBytes bytes, bool pem) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| template<typename HashFunction> | template<typename HashFunction> | ||||||
| void RSA_EMSA_PSS<HashFunction>::sign(ReadonlyBytes in, ByteBuffer& out) | void RSA_EMSA_PSS<HashFunction>::sign(ReadonlyBytes in, Bytes& out) | ||||||
| { | { | ||||||
|     // -- encode via EMSA_PSS
 |     // -- encode via EMSA_PSS
 | ||||||
|     auto mod_bits = m_rsa.private_key().modulus().trimmed_length() * sizeof(u32) * 8; |     auto mod_bits = m_rsa.private_key().modulus().trimmed_length() * sizeof(u32) * 8; | ||||||
|  | @ -219,7 +219,7 @@ VerificationConsistency RSA_EMSA_PSS<HashFunction>::verify(ReadonlyBytes in) | ||||||
|         return VerificationConsistency::Inconsistent; |         return VerificationConsistency::Inconsistent; | ||||||
| 
 | 
 | ||||||
|     u8 EM[mod_bytes]; |     u8 EM[mod_bytes]; | ||||||
|     auto EM_buf = ByteBuffer::wrap(EM, mod_bytes); |     auto EM_buf = Bytes { EM, mod_bytes }; | ||||||
| 
 | 
 | ||||||
|     // -- verify via RSA
 |     // -- verify via RSA
 | ||||||
|     m_rsa.verify(in, EM_buf); |     m_rsa.verify(in, EM_buf); | ||||||
|  | @ -317,11 +317,11 @@ void RSA_PKCS1_EME::decrypt(ReadonlyBytes in, ByteBuffer& out) | ||||||
|     out = out.slice(offset, out.size() - offset); |     out = out.slice(offset, out.size() - offset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void RSA_PKCS1_EME::sign(ReadonlyBytes, ByteBuffer&) | void RSA_PKCS1_EME::sign(ReadonlyBytes, Bytes&) | ||||||
| { | { | ||||||
|     dbg() << "FIXME: RSA_PKCS_EME::sign"; |     dbg() << "FIXME: RSA_PKCS_EME::sign"; | ||||||
| } | } | ||||||
| void RSA_PKCS1_EME::verify(ReadonlyBytes, ByteBuffer&) | void RSA_PKCS1_EME::verify(ReadonlyBytes, Bytes&) | ||||||
| { | { | ||||||
|     dbg() << "FIXME: RSA_PKCS_EME::verify"; |     dbg() << "FIXME: RSA_PKCS_EME::verify"; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -181,8 +181,8 @@ public: | ||||||
|     virtual void encrypt(ReadonlyBytes in, ByteBuffer& out) override; |     virtual void encrypt(ReadonlyBytes in, ByteBuffer& out) override; | ||||||
|     virtual void decrypt(ReadonlyBytes in, ByteBuffer& out) override; |     virtual void decrypt(ReadonlyBytes in, ByteBuffer& out) override; | ||||||
| 
 | 
 | ||||||
|     virtual void sign(ReadonlyBytes in, ByteBuffer& out) override; |     virtual void sign(ReadonlyBytes in, Bytes& out) override; | ||||||
|     virtual void verify(ReadonlyBytes in, ByteBuffer& out) override; |     virtual void verify(ReadonlyBytes in, Bytes& out) override; | ||||||
| 
 | 
 | ||||||
|     virtual String class_name() const override { return "RSA"; } |     virtual String class_name() const override { return "RSA"; } | ||||||
| 
 | 
 | ||||||
|  | @ -203,7 +203,7 @@ public: | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void sign(ReadonlyBytes in, ByteBuffer& out); |     void sign(ReadonlyBytes in, Bytes& out); | ||||||
|     VerificationConsistency verify(ReadonlyBytes in); |     VerificationConsistency verify(ReadonlyBytes in); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  | @ -225,8 +225,8 @@ public: | ||||||
|     virtual void encrypt(ReadonlyBytes in, ByteBuffer& out) override; |     virtual void encrypt(ReadonlyBytes in, ByteBuffer& out) override; | ||||||
|     virtual void decrypt(ReadonlyBytes in, ByteBuffer& out) override; |     virtual void decrypt(ReadonlyBytes in, ByteBuffer& out) override; | ||||||
| 
 | 
 | ||||||
|     virtual void sign(ReadonlyBytes, ByteBuffer&) override; |     virtual void sign(ReadonlyBytes, Bytes&) override; | ||||||
|     virtual void verify(ReadonlyBytes, ByteBuffer&) override; |     virtual void verify(ReadonlyBytes, Bytes&) override; | ||||||
| 
 | 
 | ||||||
|     virtual String class_name() const override { return "RSA_PKCS1-EME"; } |     virtual String class_name() const override { return "RSA_PKCS1-EME"; } | ||||||
|     virtual size_t output_size() const override { return m_public_key.length(); } |     virtual size_t output_size() const override { return m_public_key.length(); } | ||||||
|  |  | ||||||
|  | @ -700,7 +700,7 @@ static void aes_cbc_test_encrypt() | ||||||
|             0xd6, 0xa0, 0x46 |             0xd6, 0xa0, 0x46 | ||||||
|         }; |         }; | ||||||
|         u8 key[] { 0x0a, 0x8c, 0x5b, 0x0d, 0x8a, 0x68, 0x43, 0xf7, 0xaf, 0xc0, 0xe3, 0x4e, 0x4b, 0x43, 0xaa, 0x28, 0x69, 0x9b, 0x6f, 0xe7, 0x24, 0x82, 0x1c, 0x71, 0x86, 0xf6, 0x2b, 0x87, 0xd6, 0x8b, 0x8f, 0xf1 }; |         u8 key[] { 0x0a, 0x8c, 0x5b, 0x0d, 0x8a, 0x68, 0x43, 0xf7, 0xaf, 0xc0, 0xe3, 0x4e, 0x4b, 0x43, 0xaa, 0x28, 0x69, 0x9b, 0x6f, 0xe7, 0x24, 0x82, 0x1c, 0x71, 0x86, 0xf6, 0x2b, 0x87, 0xd6, 0x8b, 0x8f, 0xf1 }; | ||||||
|         Crypto::Cipher::AESCipher::CBCMode cipher(ByteBuffer::wrap(key, 32), 256, Crypto::Cipher::Intent::Encryption); |         Crypto::Cipher::AESCipher::CBCMode cipher(ReadonlyBytes { key, sizeof(key) }, 256, Crypto::Cipher::Intent::Encryption); | ||||||
|         test_it(cipher, result); |         test_it(cipher, result); | ||||||
|     } |     } | ||||||
|     // TODO: Test non-CMS padding options
 |     // TODO: Test non-CMS padding options
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling