~push-gopher/golang/tip

« back to all changes in this revision

Viewing changes to src/pkg/crypto/elliptic/elliptic_test.go

  • Committer: Push Gopher
  • Author(s): Mikio Hara
  • Date: 2013-07-22 11:08:58 UTC
  • Revision ID: push-gopher@niemeyer.net-20130722110858-qu0mq7ulldmjybbt
net: remove unnecessary bit masking

R=dave
CC=golang-dev
https://codereview.appspot.com/11537044
HG=17349:5c948e69f885

Show diffs side-by-side

added added

removed removed

Lines of Context:
322
322
        }
323
323
}
324
324
 
 
325
func TestP256BaseMult(t *testing.T) {
 
326
        p256 := P256()
 
327
        p256Generic := p256.Params()
 
328
 
 
329
        scalars := make([]*big.Int, 0, len(p224BaseMultTests)+1)
 
330
        for _, e := range p224BaseMultTests {
 
331
                k, _ := new(big.Int).SetString(e.k, 10)
 
332
                scalars = append(scalars, k)
 
333
        }
 
334
        k := new(big.Int).SetInt64(1)
 
335
        k.Lsh(k, 500)
 
336
        scalars = append(scalars, k)
 
337
 
 
338
        for i, k := range scalars {
 
339
                x, y := p256.ScalarBaseMult(k.Bytes())
 
340
                x2, y2 := p256Generic.ScalarBaseMult(k.Bytes())
 
341
                if x.Cmp(x2) != 0 || y.Cmp(y2) != 0 {
 
342
                        t.Errorf("#%d: got (%x, %x), want (%x, %x)", i, x, y, x2, y2)
 
343
                }
 
344
 
 
345
                if testing.Short() && i > 5 {
 
346
                        break
 
347
                }
 
348
        }
 
349
}
 
350
 
 
351
func TestP256Mult(t *testing.T) {
 
352
        p256 := P256()
 
353
        p256Generic := p256.Params()
 
354
 
 
355
        for i, e := range p224BaseMultTests {
 
356
                x, _ := new(big.Int).SetString(e.x, 16)
 
357
                y, _ := new(big.Int).SetString(e.y, 16)
 
358
                k, _ := new(big.Int).SetString(e.k, 10)
 
359
 
 
360
                xx, yy := p256.ScalarMult(x, y, k.Bytes())
 
361
                xx2, yy2 := p256Generic.ScalarMult(x, y, k.Bytes())
 
362
                if xx.Cmp(xx2) != 0 || yy.Cmp(yy2) != 0 {
 
363
                        t.Errorf("#%d: got (%x, %x), want (%x, %x)", i, xx, yy, xx2, yy2)
 
364
                }
 
365
                if testing.Short() && i > 5 {
 
366
                        break
 
367
                }
 
368
        }
 
369
}
 
370
 
325
371
func TestInfinity(t *testing.T) {
326
372
        tests := []struct {
327
373
                name  string
371
417
        }
372
418
}
373
419
 
 
420
func BenchmarkBaseMultP256(b *testing.B) {
 
421
        b.ResetTimer()
 
422
        p256 := P256()
 
423
        e := p224BaseMultTests[25]
 
424
        k, _ := new(big.Int).SetString(e.k, 10)
 
425
        b.StartTimer()
 
426
        for i := 0; i < b.N; i++ {
 
427
                p256.ScalarBaseMult(k.Bytes())
 
428
        }
 
429
}
 
430
 
374
431
func TestMarshal(t *testing.T) {
375
432
        p224 := P224()
376
433
        _, x, y, err := GenerateKey(p224, rand.Reader)