aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/rw
diff options
context:
space:
mode:
Diffstat (limited to 'src/pubkey/rw')
-rw-r--r--src/pubkey/rw/rw.cpp23
-rw-r--r--src/pubkey/rw/rw.h18
2 files changed, 40 insertions, 1 deletions
diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp
index de50313d2..85b10a69d 100644
--- a/src/pubkey/rw/rw.cpp
+++ b/src/pubkey/rw/rw.cpp
@@ -156,4 +156,27 @@ SecureVector<byte> RW_Signature_Operation::sign(const byte msg[],
return BigInt::encode_1363(r, n.bytes());
}
+SecureVector<byte>
+RW_Verification_Operation::verify_mr(const byte msg[], u32bit msg_len)
+ {
+ BigInt m(msg, msg_len);
+
+ if((m > (n >> 1)) || m.is_negative())
+ throw Invalid_Argument("RW signature verification: m > n / 2 || m < 0");
+
+ BigInt r = powermod_e_n(m);
+ if(r % 16 == 12)
+ return BigInt::encode(r);
+ if(r % 8 == 6)
+ return BigInt::encode(2*r);
+
+ r = n - r;
+ if(r % 16 == 12)
+ return BigInt::encode(r);
+ if(r % 8 == 6)
+ return BigInt::encode(2*r);
+
+ throw Invalid_Argument("RW signature verification: Invalid signature");
+ }
+
}
diff --git a/src/pubkey/rw/rw.h b/src/pubkey/rw/rw.h
index a46cb5bb3..66dfd289e 100644
--- a/src/pubkey/rw/rw.h
+++ b/src/pubkey/rw/rw.h
@@ -84,7 +84,23 @@ class BOTAN_DLL RW_Signature_Operation : public PK_Ops::Signature_Operation
Fixed_Exponent_Power_Mod powermod_d1_p, powermod_d2_q;
Modular_Reducer mod_p;
- u32bit n_bits;
+ };
+
+class BOTAN_DLL RW_Verification_Operation : public PK_Ops::Verification
+ {
+ public:
+ RW_Verification_Operation(const RW_PublicKey& rw) :
+ n(rw.get_n()), powermod_e_n(rw.get_e(), rw.get_n())
+ {}
+
+ u32bit max_input_bits() const { return (n.bits() - 1); }
+ bool with_recovery() const { return true; }
+
+ SecureVector<byte> verify_mr(const byte msg[], u32bit msg_len);
+
+ private:
+ const BigInt& n;
+ Fixed_Exponent_Power_Mod powermod_e_n;
};
}