• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5134090420

31 May 2023 03:12PM UTC coverage: 91.721% (-0.3%) from 91.995%
5134090420

push

github

randombit
Merge GH #3565 Disable noisy/pointless pylint warnings

76048 of 82912 relevant lines covered (91.72%)

11755290.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/src/lib/pubkey/keypair/keypair.cpp
1
/*
2
* Keypair Checks
3
* (C) 1999-2010 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/keypair.h>
9

10
#include <botan/pubkey.h>
11
#include <botan/rng.h>
12

13
namespace Botan::KeyPair {
14

15
/*
16
* Check an encryption key pair for consistency
17
*/
18
bool encryption_consistency_check(RandomNumberGenerator& rng,
3✔
19
                                  const Private_Key& private_key,
20
                                  const Public_Key& public_key,
21
                                  std::string_view padding) {
22
   PK_Encryptor_EME encryptor(public_key, rng, padding);
3✔
23
   PK_Decryptor_EME decryptor(private_key, rng, padding);
3✔
24

25
   /*
26
   Weird corner case, if the key is too small to encrypt anything at
27
   all. This can happen with very small RSA keys with PSS
28
   */
29
   if(encryptor.maximum_input_size() == 0) {
3✔
30
      return true;
31
   }
32

33
   std::vector<uint8_t> plaintext;
3✔
34
   rng.random_vec(plaintext, encryptor.maximum_input_size() - 1);
3✔
35

36
   std::vector<uint8_t> ciphertext = encryptor.encrypt(plaintext, rng);
3✔
37
   if(ciphertext == plaintext) {
3✔
38
      return false;
39
   }
40

41
   std::vector<uint8_t> decrypted = unlock(decryptor.decrypt(ciphertext));
3✔
42

43
   return (plaintext == decrypted);
3✔
44
}
9✔
45

46
/*
47
* Check a signature key pair for consistency
48
*/
49
bool signature_consistency_check(RandomNumberGenerator& rng,
28✔
50
                                 const Private_Key& private_key,
51
                                 const Public_Key& public_key,
52
                                 std::string_view padding) {
53
   PK_Signer signer(private_key, rng, padding);
28✔
54
   PK_Verifier verifier(public_key, padding);
28✔
55

56
   std::vector<uint8_t> message(32);
28✔
57
   rng.randomize(message.data(), message.size());
28✔
58

59
   std::vector<uint8_t> signature;
28✔
60

61
   try {
28✔
62
      signature = signer.sign_message(message, rng);
56✔
63
   } catch(Encoding_Error&) {
×
64
      return false;
×
65
   }
×
66

67
   if(!verifier.verify_message(message, signature)) {
28✔
68
      return false;
69
   }
70

71
   // Now try to check a corrupt signature, ensure it does not succeed
72
   ++signature[0];
28✔
73

74
   if(verifier.verify_message(message, signature)) {
28✔
75
      return false;
×
76
   }
77

78
   return true;
79
}
56✔
80

81
}  // namespace Botan::KeyPair
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc