package rsa
import (
- "bytes";
- "crypto/sha1";
- big "gmp";
- "os";
- "testing";
- "testing/quick";
+ "bytes";
+ "crypto/sha1";
+ big "gmp";
+ "os";
+ "testing";
)
func TestKeyGeneration(t *testing.T) {
}
}
-type TestConstantTimeCompareStruct struct {
- a, b []byte;
- out int;
-}
-
-var testConstandTimeCompareData = []TestConstantTimeCompareStruct{
- TestConstantTimeCompareStruct{[]byte{}, []byte{}, 1},
- TestConstantTimeCompareStruct{[]byte{0x11}, []byte{0x11}, 1},
- TestConstantTimeCompareStruct{[]byte{0x12}, []byte{0x11}, 0},
-}
-
-func TestConstantTimeCompare(t *testing.T) {
- for i, test := range testConstandTimeCompareData {
- if r := constantTimeCompare(test.a, test.b); r != test.out {
- t.Errorf("#%d bad result (got %x, want %x)", i, r, test.out);
- }
- }
-}
-
-type TestConstantTimeByteEqStruct struct {
- a, b uint8;
- out int;
-}
-
-var testConstandTimeByteEqData = []TestConstantTimeByteEqStruct{
- TestConstantTimeByteEqStruct{0, 0, 1},
- TestConstantTimeByteEqStruct{0, 1, 0},
- TestConstantTimeByteEqStruct{1, 0, 0},
- TestConstantTimeByteEqStruct{0xff, 0xff, 1},
- TestConstantTimeByteEqStruct{0xff, 0xfe, 0},
-}
-
-func ByteEq(a, b uint8) int {
- if a == b {
- return 1;
- }
- return 0;
-}
-
-func TestConstantTimeByteEq(t *testing.T) {
- for i, test := range testConstandTimeByteEqData {
- if r := constantTimeByteEq(test.a, test.b); r != test.out {
- t.Errorf("#%d bad result (got %x, want %x)", i, r, test.out);
- }
- }
- err := quick.CheckEqual(constantTimeByteEq, ByteEq, nil);
- if err != nil {
- t.Error(err);
- }
-}
-
-func Eq(a, b int32) int {
- if a == b {
- return 1;
- }
- return 0;
-}
-
-func TestConstantTimeEq(t *testing.T) {
- err := quick.CheckEqual(constantTimeEq, Eq, nil);
- if err != nil {
- t.Error(err);
- }
-}
-
-func Copy(v int, x, y []byte) []byte {
- if len(x) > len(y) {
- x = x[0:len(y)];
- } else {
- y = y[0:len(x)];
- }
- if v == 1 {
- bytes.Copy(x, y);
- }
- return x;
-}
-
-func constantTimeCopyWrapper(v int, x, y []byte) []byte {
- if len(x) > len(y) {
- x = x[0:len(y)];
- } else {
- y = y[0:len(x)];
- }
- v &= 1;
- constantTimeCopy(v, x, y);
- return x;
-}
-
-func TestConstantTimeCopy(t *testing.T) {
- err := quick.CheckEqual(constantTimeCopyWrapper, Copy, nil);
- if err != nil {
- t.Error(err);
- }
-}
-
// testEncryptOAEPData contains a subset of the vectors from RSA's "Test vectors for RSA-OAEP".
var testEncryptOAEPData = []testEncryptOAEPStruct{
// Key 1
65537,
"056b04216fe5f354ac77250a4b6b0c8525a85c59b0bd80c56450a22d5f438e596a333aa875e291dd43f48cb88b9d5fc0d499f9fcd1c397f9afc070cd9e398c8d19e61db7c7410a6b2675dfbf5d345b804d201add502d5ce2dfcb091ce9997bbebe57306f383e4d588103f036f7e85d1934d152a323e4a8db451d6f4a5b1b0f102cc150e02feee2b88dea4ad4c1baccb24d84072d14e1d24a6771f7408ee30564fb86d4393a34bcf0b788501d193303f13a2284b001f0f649eaf79328d4ac5c430ab4414920a9460ed1b7bc40ec653e876d09abc509ae45b525190116a0c26101848298509c1c3bf3a483e7274054e15e97075036e989f60932807b5257751e79",
[]testEncryptOAEPMessage{
- // Example 10.1
- testEncryptOAEPMessage{
- []byte{0x8b, 0xba, 0x6b, 0xf8, 0x2a, 0x6c, 0x0f, 0x86,
- 0xd5, 0xf1, 0x75, 0x6e, 0x97, 0x95, 0x68, 0x70, 0xb0,
- 0x89, 0x53, 0xb0, 0x6b, 0x4e, 0xb2, 0x05, 0xbc, 0x16,
- 0x94, 0xee,
- },
- []byte{0x47, 0xe1, 0xab, 0x71, 0x19, 0xfe, 0xe5, 0x6c,
- 0x95, 0xee, 0x5e, 0xaa, 0xd8, 0x6f, 0x40, 0xd0, 0xaa,
- 0x63, 0xbd, 0x33,
- },
- []byte{0x53, 0xea, 0x5d, 0xc0, 0x8c, 0xd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