| 126 | } |
| 127 | |
| 128 | bool SignatureValidate(PK_Signer &priv, PK_Verifier &pub, bool thorough = false) |
| 129 | { |
| 130 | bool pass = true, fail; |
| 131 | |
| 132 | fail = !pub.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2) || !priv.GetMaterial().Validate(GlobalRNG(), thorough ? 3 : 2); |
| 133 | pass = pass && !fail; |
| 134 | |
| 135 | cout << (fail ? "FAILED " : "passed "); |
| 136 | cout << "signature key validation\n"; |
| 137 | |
| 138 | const byte *message = (byte *)"test message"; |
| 139 | const int messageLen = 12; |
| 140 | |
| 141 | SecByteBlock signature(priv.MaxSignatureLength()); |
| 142 | size_t signatureLength = priv.SignMessage(GlobalRNG(), message, messageLen, signature); |
| 143 | fail = !pub.VerifyMessage(message, messageLen, signature, signatureLength); |
| 144 | pass = pass && !fail; |
| 145 | |
| 146 | cout << (fail ? "FAILED " : "passed "); |
| 147 | cout << "signature and verification\n"; |
| 148 | |
| 149 | ++signature[0]; |
| 150 | fail = pub.VerifyMessage(message, messageLen, signature, signatureLength); |
| 151 | pass = pass && !fail; |
| 152 | |
| 153 | cout << (fail ? "FAILED " : "passed "); |
| 154 | cout << "checking invalid signature" << endl; |
| 155 | |
| 156 | if (priv.MaxRecoverableLength() > 0) |
| 157 | { |
| 158 | signatureLength = priv.SignMessageWithRecovery(GlobalRNG(), message, messageLen, NULL, 0, signature); |
| 159 | SecByteBlock recovered(priv.MaxRecoverableLengthFromSignatureLength(signatureLength)); |
| 160 | DecodingResult result = pub.RecoverMessage(recovered, NULL, 0, signature, signatureLength); |
| 161 | fail = !(result.isValidCoding && result.messageLength == messageLen && memcmp(recovered, message, messageLen) == 0); |
| 162 | pass = pass && !fail; |
| 163 | |
| 164 | cout << (fail ? "FAILED " : "passed "); |
| 165 | cout << "signature and verification with recovery" << endl; |
| 166 | |
| 167 | ++signature[0]; |
| 168 | result = pub.RecoverMessage(recovered, NULL, 0, signature, signatureLength); |
| 169 | fail = result.isValidCoding; |
| 170 | pass = pass && !fail; |
| 171 | |
| 172 | cout << (fail ? "FAILED " : "passed "); |
| 173 | cout << "recovery with invalid signature" << endl; |
| 174 | } |
| 175 | |
| 176 | return pass; |
| 177 | } |
| 178 | |
| 179 | bool CryptoSystemValidate(PK_Decryptor &priv, PK_Encryptor &pub, bool thorough = false) |
| 180 | { |
no test coverage detected