OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [crypto/] [elliptic/] [p224_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2012 The Go Authors.  All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package elliptic
6
 
7
import (
8
        "math/big"
9
        "testing"
10
)
11
 
12
var toFromBigTests = []string{
13
        "0",
14
        "1",
15
        "23",
16
        "b70e0cb46bb4bf7f321390b94a03c1d356c01122343280d6105c1d21",
17
        "706a46d476dcb76798e6046d89474788d164c18032d268fd10704fa6",
18
}
19
 
20
func p224AlternativeToBig(in *p224FieldElement) *big.Int {
21
        ret := new(big.Int)
22
        tmp := new(big.Int)
23
 
24
        for i := uint(0); i < 8; i++ {
25
                tmp.SetInt64(int64(in[i]))
26
                tmp.Lsh(tmp, 28*i)
27
                ret.Add(ret, tmp)
28
        }
29
        ret.Mod(ret, p224.P)
30
        return ret
31
}
32
 
33
func TestToFromBig(t *testing.T) {
34
        for i, test := range toFromBigTests {
35
                n, _ := new(big.Int).SetString(test, 16)
36
                var x p224FieldElement
37
                p224FromBig(&x, n)
38
                m := p224ToBig(&x)
39
                if n.Cmp(m) != 0 {
40
                        t.Errorf("#%d: %x != %x", i, n, m)
41
                }
42
                q := p224AlternativeToBig(&x)
43
                if n.Cmp(q) != 0 {
44
                        t.Errorf("#%d: %x != %x (alternative)", i, n, m)
45
                }
46
        }
47
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.