OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package rsa | 5 package rsa |
6 | 6 |
7 import ( | 7 import ( |
8 "big" | 8 "big" |
9 "bytes" | 9 "bytes" |
10 "crypto/rand" | 10 "crypto/rand" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 n.SetString(test.modulus, 16) | 59 n.SetString(test.modulus, 16) |
60 public := PublicKey{n, test.e} | 60 public := PublicKey{n, test.e} |
61 | 61 |
62 for j, message := range test.msgs { | 62 for j, message := range test.msgs { |
63 randomSource := bytes.NewBuffer(message.seed) | 63 randomSource := bytes.NewBuffer(message.seed) |
64 out, err := EncryptOAEP(sha1, randomSource, &public, mes
sage.in, nil) | 64 out, err := EncryptOAEP(sha1, randomSource, &public, mes
sage.in, nil) |
65 if err != nil { | 65 if err != nil { |
66 t.Errorf("#%d,%d error: %s", i, j, err) | 66 t.Errorf("#%d,%d error: %s", i, j, err) |
67 } | 67 } |
68 if bytes.Compare(out, message.out) != 0 { | 68 if bytes.Compare(out, message.out) != 0 { |
69 » » » » t.Errorf("#%d,%d bad result: %s (want %s)", i, j
, out, message.out) | 69 » » » » t.Errorf("#%d,%d bad result: %x (want %x)", i, j
, out, message.out) |
70 } | 70 } |
71 } | 71 } |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 func TestDecryptOAEP(t *testing.T) { | 75 func TestDecryptOAEP(t *testing.T) { |
76 random := rand.Reader | 76 random := rand.Reader |
77 | 77 |
78 sha1 := sha1.New() | 78 sha1 := sha1.New() |
79 n := new(big.Int) | 79 n := new(big.Int) |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 0x5e, 0x7f, 0x16, 0x64, 0x61, 0x82, 0xfd
, 0xb4, 0x64, | 241 0x5e, 0x7f, 0x16, 0x64, 0x61, 0x82, 0xfd
, 0xb4, 0x64, |
242 0x73, 0x9b, 0x68, 0xab, 0x5d, 0xaf, 0xf0
, 0xe6, 0x3e, | 242 0x73, 0x9b, 0x68, 0xab, 0x5d, 0xaf, 0xf0
, 0xe6, 0x3e, |
243 0x95, 0x52, 0x01, 0x68, 0x24, 0xf0, 0x54
, 0xbf, 0x4d, | 243 0x95, 0x52, 0x01, 0x68, 0x24, 0xf0, 0x54
, 0xbf, 0x4d, |
244 0x3c, 0x8c, 0x90, 0xa9, 0x7b, 0xb6, 0xb6
, 0x55, 0x32, | 244 0x3c, 0x8c, 0x90, 0xa9, 0x7b, 0xb6, 0xb6
, 0x55, 0x32, |
245 0x84, 0xeb, 0x42, 0x9f, 0xcc, | 245 0x84, 0xeb, 0x42, 0x9f, 0xcc, |
246 }, | 246 }, |
247 }, | 247 }, |
248 }, | 248 }, |
249 }, | 249 }, |
250 } | 250 } |
OLD | NEW |