bn_mod and bn_mulmod tests

This commit is contained in:
Quinn Slack 2011-04-19 15:09:25 -07:00
parent e6cc1dd6a1
commit de23a4016c
2 changed files with 74 additions and 0 deletions

View File

@ -1,3 +1,48 @@
new sjcl.test.TestCase("Bignum modular reduction test", function (cb) {
if (!sjcl.bn) {
this.unimplemented();
cb && cb();
return;
}
var a, N, r;
for (i=0; i < sjcl.test.vector.bn_mod.length; i++) {
tv = sjcl.test.vector.bn_mod[i];
try {
a = new sjcl.bn(tv.a);
N = new sjcl.bn(tv.N);
r = a.mod(N);
this.require(r.equals(new sjcl.bn(tv.r)));
} catch(e) {
this.fail(e);
}
}
cb && cb();
});
new sjcl.test.TestCase("Bignum modular multiplication test", function (cb) {
if (!sjcl.bn) {
this.unimplemented();
cb && cb();
return;
}
var a, b, N, r;
for(var j=0;j<10;j++)for (i=0; i < sjcl.test.vector.bn_mulmod.length; i++) {
tv = sjcl.test.vector.bn_mulmod[i];
try {
a = new sjcl.bn(tv.a);
b = new sjcl.bn(tv.b);
N = new sjcl.bn(tv.N);
r = a.mulmod(b, N);
this.require(r.equals(new sjcl.bn(tv.r)));
} catch(e) {
this.fail(e);
}
}
cb && cb();
});
new sjcl.test.TestCase("Bignum modular exponentiation test", function (cb) {
if (!sjcl.bn) {
this.unimplemented();

View File

@ -1,3 +1,32 @@
sjcl.test.vector.bn_mod = [
{
a: "cfb9caac51a13eb13592d47863e463b306547683070424a7c7a41302e30453c2f5f6f2c432a267d2d72746c534d6c233c5c6740776e5c473592d4786377d745c534f2d502427612249266a45382a6f512e527d475577484f277e7a4ce62c7919c0b34b9f125124c574bac9738edb0998bfa8f5b8076c5266ae06e1b9121303d7ff8f0380a24526474d592a7d5e69f125124c574bac9738ed77d745c534f2d502427612249266a45382a6f512e527d4755560144ced0a078454a727d24db5d77484f27b0998bfa8f5b8076c5266ae06e1b9121303d7ff8f0380a24526474d592a7d5e682b2358377d745c534f2d502427612249266a45382a6f512e527d4755560144ced0a078454a727d24db5d77484f277e7b3d28256d71482d2a287d666b3ac7053b02c6543592d47863b6a0541cfa603219b694bec483592d478630",
N: "c3219b694b6a0541cfa60c46a0541cfa60c4c574bac9738edb0998bfa8f5b8076c5266ae06e1b9121303d7ff8f0380a2f51de2fdc93bba83b4c4f49e2D3383B4813D692C6E0E0D5D8E250B98BE48E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D498254b6afa60c4835920541cfa60c4c4f49e2D3383B4813D692C855c8a7d64e9",
r: "3c3312d60b052287f92b61bc1e890a3f43f46f302086fc19d7555059f957607981f89d7\
25b775c70c47e940a874e143efec01558c9cbe5f15df716d812c61cef1a2c6561ee999\
0b5db8e54827a16018fee6c111c9a8e66897f849ccd9114639ab086f8ecfa558b58555\
47b1eb110e245f51598bc98486af1813423877189e66a84cd7ead55"
}
]
sjcl.test.vector.bn_mulmod = [
{
a: "94B7555AABE9127CC58CCF4993DB6CF84D16C1244021612e464d6e2f4c724f2b3e275a43385a5a6d4c7441284648362a4526474d592a7d5e682b2358377d745c534f2d502427612249266a45382a6f512e527d475577484f277e7b3d28256d71482d2a287d666b52247027",
b: "70424648242f4273612a524e4a44717b655b487b395d2f407d4c7141503e33442a657637257968345237677d6e736f5f24546b642a23283e463b306547683070424a7c7a41302e30453c2f5f6f2c432a267d2d72746c534d6c233c5c6740776e5c4725562029623d7a673d",
N: "EEAF0AB9ADB38D8775FF3C0B9EA27496EA81D3383B4813D692C6E0E0D5D8E250B98BE48E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D4982559B297BCF1885C529F566660E57EC68EDBC3C05726CC02FD4CBF4976EAA9AFD5138FE8376435B9FC61D2FC0EB06E3",
r: "266bd21de6da4ce62c7919c0b34b9f125124c574bac9738edb0998bfa8f5b8076c5266ae06e1b9121303d7ff8f0380a2f51de2fdc93bba83b4c4f49e2ddc65c24a8e2ecbac374e49181792aeeada8fc5438073187b2cf3d63f93d560144ced0a078454a727d24db5d09e56"
},
{
a: "94B7555AABE9127CC58CCF4993DB6CF84D16C1244021612e464d6e2f4c724f2b3e275a43385a5a6d4c7441284648362a4526474d592a7d5e682b2358377d745c534f2d502427612249266a45382a6f512e527d475577484f277e7b3d28256d71482d2a287d666b52247027",
b: "70424648242f42364d5635424967654d212a2e4532656123234b3822524f58762e75374d22252f324865406f43386a5d3d435f66315a7e6b6b20277978244f5856626a4f5c796f374c3373612a524e4a44717b655b487b395d2f407d4c7141503e33442a657637257968345237677d6e736f5f24546b642a23283e463b306547683070424a7c7a41302e30453c2f5f6f2c432a267d2d72746c534d6c233c5c6740776e5c4725562029623d7a673d",
N: "EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C9C256576D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE48E495C1D6089DAD15DC7D7B46154D6B6CE8EF4AD69B15D4982559B297BCF1885C529F566660E57EC68EDBC3C05726CC02FD4CBF4976EAA9AFD5138FE8376435B9FC61D2FC0EB06E3",
r: "4701ff9bffd27e43a071e0a4c09b22945af95c8d81fda91e1fcbf2c6a54fc9d3f824ec\
2dc88b88ba455c206965c03dbcb19c5e1826435de032abeac7a576f176a3a037455f0e\
7f9681755eb6e7ee91a4d58fc75b6db59563e6b4fb69efec1ccc53b7a0003b6c0be278\
cb9f8075d4bb6eef64015f09749db233e27bf3a1b48ba7"
}
]
sjcl.test.vector.bn_powermod = [
{
g: 2,