Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1233)

Delta Between Two Patch Sets: src/pkg/crypto/rsa/emsa_test.go

Issue 9438043: code review 9438043: rsa: Implementation of RSASSA-PSS signature algorithm a...
Left Patch Set: diff -r 1abed5873071 https://code.google.com/p/go Created 10 years, 10 months ago
Right Patch Set: diff -r 1abed5873071 https://code.google.com/p/go Created 10 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/crypto/rsa/pss.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package rsa 1 package rsa
2 2
3 import ( 3 import (
4 "bytes"
4 "crypto/sha1" 5 "crypto/sha1"
5 "fmt"
6 "math/big"
7 "testing" 6 "testing"
8 ) 7 )
9 8
10 func printBytes(name string, buf []byte) {
11 fmt.Printf("%v:\n", name)
12 for _, d := range buf {
13 fmt.Printf("%x, ", d)
14 }
15 fmt.Printf("\n")
16 }
17
18 func compareBytes(a, b []byte) bool {
19 if len(a) != len(b) {
20 return false
21 }
22 for i, e := range a {
23 if b[i] != e {
24 return false
25 }
26 }
27 return true
28 }
29
30 // Test vector from RSA lab: ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2- 1-vec.zip
31 func TestEMSAPSS(t *testing.T) { 9 func TestEMSAPSS(t *testing.T) {
10 // Test vector in file pss-int.txt from: ftp://ftp.rsasecurity.com/pub/p kcs/pkcs-1/pkcs-1v2-1-vec.zip
32 msg := []byte{0x85, 0x9e, 0xef, 0x2f, 0xd7, 0x8a, 0xca, 0x00, 0x30, 0x8b , 0xdc, 0x47, 0x11, 0x93, 0xbf, 0x55, 0xbf, 0x9d, 0x78, 0xdb, 0x8f, 0x8a, 0x67, 0x2b, 0x48, 0x46, 0x34, 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7, 0xa2, 0xc4, 0x3b, 0xad, 0x54, 0x6f, 0xbe, 0x8c, 0xfe, 0xbc} 13 em := []byte{0x66, 0xe4, 0x67, 0x2e, 0x83, 0x6a, 0xd1, 0x21, 0xba, 0x24, 0x4b, 0xed, 0x65, 0x76, 0xb8, 0x67, 0xd9, 0xa4, 0x47, 0xc2, 0x8a, 0x6e, 0x66, 0 xa5, 0xb8, 0x7d, 0xee, 0x7f, 0xbc, 0x7e, 0x65, 0xaf, 0x50, 0x57, 0xf8, 0x6f, 0xa e, 0x89, 0x84, 0xd9, 0xba, 0x7f, 0x96, 0x9a, 0xd6, 0xfe, 0x02, 0xa4, 0xd7, 0x5f, 0x74, 0x45, 0xfe, 0xfd, 0xd8, 0x5b, 0x6d, 0x3a, 0x47, 0x7c, 0x28, 0xd2, 0x4b, 0 xa1, 0xe3, 0x75, 0x6f, 0x79, 0x2d, 0xd1, 0xdc, 0xe8, 0xca, 0x94, 0x44, 0x0e, 0xc b, 0x52, 0x79, 0xec, 0xd3, 0x18, 0x3a, 0x31, 0x1f, 0xc8, 0x96, 0xda, 0x1c, 0xb3, 0x93, 0x11, 0xaf, 0x37, 0xea, 0x4a, 0x75, 0xe2, 0x4b, 0xdb, 0xfd, 0x5c, 0x1d, 0 xa0, 0xde, 0x7c, 0xec, 0xdf, 0x1a, 0x89, 0x6f, 0x9d, 0x8b, 0xc8, 0x16, 0xd9, 0x7 c, 0xd7, 0xa2, 0xc4, 0x3b, 0xad, 0x54, 0x6f, 0xbe, 0x8c, 0xfe, 0xbc}
35 14
36 hash := sha1.New() 15 hash := sha1.New()
37 hashed := make([]byte, hash.Size()) 16 hashed := make([]byte, hash.Size())
38 17
39 hash.Write(msg) 18 hash.Write(msg)
40 hashed = hash.Sum(hashed[:0]) 19 hashed = hash.Sum(hashed[:0])
41 20
42 encoded, err := emsaPSSEncode(hashed, 1023, salt, sha1.New()) 21 encoded, err := emsaPSSEncode(hashed, 1023, salt, sha1.New())
43 if err != nil { 22 if err != nil {
44 t.Errorf("Error: %v\n", err) 23 t.Errorf("Error: %v\n", err)
45 } 24 }
46 » if !compareBytes(encoded, em) { 25 » if !bytes.Equal(encoded, em) {
47 t.Errorf("Bad encoding") 26 t.Errorf("Bad encoding")
48 } 27 }
49 28
50 err = emsaPSSVerify(hashed, encoded, 1023, len(salt), sha1.New()) 29 err = emsaPSSVerify(hashed, encoded, 1023, len(salt), sha1.New())
51 if err != nil { 30 if err != nil {
52 t.Errorf("Bad verification") 31 t.Errorf("Bad verification")
53 } 32 }
54 } 33 }
55
56 func fromBase16(base10 string) *big.Int {
57 i := new(big.Int)
58 i.SetString(base10, 16)
59 return i
60 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b