Add RSA test.
This commit is contained in:
parent
7d1e5bca55
commit
03bb56ae96
@ -104,6 +104,7 @@ size_t RSA::encrypt(unsigned char *from, size_t from_len, size_t max_from_len, u
|
|||||||
CHECK(chunks * 256 <= to_len);
|
CHECK(chunks * 256 <= to_len);
|
||||||
Random::secure_bytes(from + from_len, pad);
|
Random::secure_bytes(from + from_len, pad);
|
||||||
|
|
||||||
|
size_t result = chunks * 256;
|
||||||
BigNumContext ctx;
|
BigNumContext ctx;
|
||||||
BigNum y;
|
BigNum y;
|
||||||
while (chunks-- > 0) {
|
while (chunks-- > 0) {
|
||||||
@ -112,7 +113,7 @@ size_t RSA::encrypt(unsigned char *from, size_t from_len, size_t max_from_len, u
|
|||||||
MutableSlice(to, 256).copy_from(y.to_binary(256));
|
MutableSlice(to, 256).copy_from(y.to_binary(256));
|
||||||
to += 256;
|
to += 256;
|
||||||
}
|
}
|
||||||
return chunks * 256;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSA::decrypt_signature(Slice from, MutableSlice to) const {
|
void RSA::decrypt_signature(Slice from, MutableSlice to) const {
|
||||||
|
@ -711,3 +711,22 @@ TEST(Mtproto, TlsTransport) {
|
|||||||
}
|
}
|
||||||
sched.finish();
|
sched.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Mtproto, RSA) {
|
||||||
|
auto pem = td::Slice(
|
||||||
|
"-----BEGIN RSA PUBLIC KEY-----\n"
|
||||||
|
"MIIBCgKCAQEAr4v4wxMDXIaMOh8bayF/NyoYdpcysn5EbjTIOZC0RkgzsRj3SGlu\n"
|
||||||
|
"52QSz+ysO41dQAjpFLgxPVJoOlxXokaOq827IfW0bGCm0doT5hxtedu9UCQKbE8j\n"
|
||||||
|
"lDOk+kWMXHPZFJKWRgKgTu9hcB3y3Vk+JFfLpq3d5ZB48B4bcwrRQnzkx5GhWOFX\n"
|
||||||
|
"x73ZgjO93eoQ2b/lDyXxK4B4IS+hZhjzezPZTI5upTRbs5ljlApsddsHrKk6jJNj\n"
|
||||||
|
"8Ygs/ps8e6ct82jLXbnndC9s8HjEvDvBPH9IPjv5JUlmHMBFZ5vFQIfbpo0u0+1P\n"
|
||||||
|
"n6bkEi5o7/ifoyVv2pAZTRwppTz0EuXD8QIDAQAB\n"
|
||||||
|
"-----END RSA PUBLIC KEY-----");
|
||||||
|
auto rsa = RSA::from_pem_public_key(pem).move_as_ok();
|
||||||
|
ASSERT_EQ(-7596991558377038078, rsa.get_fingerprint());
|
||||||
|
ASSERT_EQ(256u, rsa.size());
|
||||||
|
|
||||||
|
string s(255, '\0');
|
||||||
|
string to(256, '\0');
|
||||||
|
ASSERT_EQ(256u, rsa.encrypt(MutableSlice(s).ubegin(), 10, 255, MutableSlice(to).ubegin(), 256));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user