aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/rw/rw.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-05 01:09:28 +0000
committerlloyd <[email protected]>2010-03-05 01:09:28 +0000
commit1c7dbb21d19702872379421e6ae44a15caf67da2 (patch)
treebd4ee9e01f8cfd9631655d0e0b0991d49c0a7e8e /src/pubkey/rw/rw.cpp
parent78b5b103291ee668185dc71d138a50e8e7e54808 (diff)
Add signature generation operation classes. Remove sign() from
PK_Signing_Key, though for the moment the class remains because there are a few pieces of code that use it to detect if signatures are supported, or for passing to functions in look_pk
Diffstat (limited to 'src/pubkey/rw/rw.cpp')
-rw-r--r--src/pubkey/rw/rw.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp
index 72fa29afa..de50313d2 100644
--- a/src/pubkey/rw/rw.cpp
+++ b/src/pubkey/rw/rw.cpp
@@ -123,4 +123,37 @@ bool RW_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const
return true;
}
+RW_Signature_Operation::RW_Signature_Operation(const RW_PrivateKey& rw) :
+ q(rw.get_q()),
+ c(rw.get_c()),
+ n(rw.get_n()),
+ powermod_d1_p(rw.get_d1(), rw.get_p()),
+ powermod_d2_q(rw.get_d2(), rw.get_q()),
+ mod_p(rw.get_p())
+ {
+ }
+
+SecureVector<byte> RW_Signature_Operation::sign(const byte msg[],
+ u32bit msg_len,
+ RandomNumberGenerator&)
+ {
+ BigInt i(msg, msg_len);
+
+ if(i >= n || i % 16 != 12)
+ throw Invalid_Argument("Rabin-Williams: invalid input");
+
+ if(jacobi(i, n) != 1)
+ i >>= 1;
+
+ BigInt j1 = powermod_d1_p(i);
+ BigInt j2 = powermod_d2_q(i);
+ j1 = mod_p.reduce(sub_mul(j1, j2, c));
+
+ BigInt r = mul_add(j1, q, j2);
+
+ r = std::min(r, n - r);
+
+ return BigInt::encode_1363(r, n.bytes());
+ }
+
}