rsa_ut.cpp 897 B

12345678910111213141516171819202122232425262728
  1. #include "rsa.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <library/cpp/openssl/big_integer/big_integer.h>
  4. #include <util/system/byteorder.h>
  5. using namespace NOpenSsl;
  6. using namespace NOpenSsl::NRsa;
  7. Y_UNIT_TEST_SUITE(Rsa) {
  8. Y_UNIT_TEST(Encrypt) {
  9. // example from Ru.Wikipedia
  10. const auto originData = TBigInteger::FromULong(111111);
  11. const auto n = TBigInteger::FromULong(3);
  12. const auto e = TBigInteger::FromULong(9173503);
  13. // check key reuse
  14. for (size_t i = 0; i < 10; ++i) {
  15. UNIT_ASSERT_VALUES_EQUAL(TBigInteger::FromULong(4051753), TPublicKey(n, e).EncryptNoPad(originData));
  16. }
  17. UNIT_ASSERT_VALUES_EQUAL(originData, TBigInteger::FromULong(111111));
  18. UNIT_ASSERT_VALUES_EQUAL(n, TBigInteger::FromULong(3));
  19. UNIT_ASSERT_VALUES_EQUAL(e, TBigInteger::FromULong(9173503));
  20. }
  21. }