-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrand_test.go
99 lines (91 loc) · 3.42 KB
/
rand_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (C) 2015-2019 Virgil Security Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* (1) Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* (3) Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*/
package phe
import (
"bytes"
"crypto/rand"
"io"
)
var randBytes = []byte{
0xfc, 0x9e, 0x1d, 0x89, 0xfa, 0x8b, 0x15, 0xe3,
0x91, 0xf6, 0x2b, 0x3d, 0xe3, 0x57, 0xb0, 0xf5,
0x6f, 0xe4, 0xde, 0xc5, 0x4a, 0x00, 0x8c, 0x75,
0x56, 0xc4, 0x77, 0xbc, 0x96, 0x79, 0xf8, 0x3d,
0x80, 0x39, 0x05, 0x31, 0x49, 0x44, 0x70, 0xbe,
0x0b, 0x29, 0x65, 0x01, 0x58, 0x6b, 0xfc, 0xd9,
0xe1, 0x31, 0xc3, 0x9e, 0x2d, 0xec, 0xc7, 0x53,
0xd4, 0xf2, 0x5f, 0xef, 0xd2, 0x28, 0x1e, 0xea,
0xe0, 0x92, 0x7d, 0x0e, 0xd0, 0x57, 0x2e, 0x7f,
0xe7, 0x7b, 0x60, 0x93, 0x15, 0xbc, 0x86, 0x5e,
0xd4, 0x38, 0x92, 0xcd, 0x6c, 0xda, 0xf5, 0x65,
0x18, 0x1a, 0x3d, 0xf9, 0x2b, 0x13, 0x80, 0xdc,
0xc4, 0x08, 0x93, 0xc8, 0xdf, 0x19, 0x7b, 0x6b,
0x8f, 0x74, 0x8f, 0x39, 0x23, 0xa1, 0x8a, 0x6d,
0xd4, 0xdd, 0xb5, 0xc3, 0x01, 0x66, 0xa9, 0x5a,
0xb8, 0xbc, 0x14, 0xde, 0x83, 0x26, 0xdb, 0x32,
0xf3, 0x1d, 0xa8, 0xef, 0x0b, 0xdd, 0x38, 0x5f,
0x83, 0xb3, 0x6c, 0xf8, 0x89, 0x48, 0xc3, 0xee,
0xb3, 0x97, 0x4d, 0x04, 0x08, 0x12, 0x53, 0xf5,
0x60, 0x44, 0x67, 0x91, 0xc1, 0x9e, 0x03, 0xab,
0x4b, 0x70, 0x0b, 0xcb, 0x4e, 0x03, 0x81, 0x7d,
0x40, 0x96, 0xa2, 0x60, 0x5a, 0x80, 0xb2, 0x23,
0x6d, 0x62, 0x3c, 0x5a, 0x5e, 0xd2, 0x45, 0xdb,
0x36, 0x56, 0xda, 0xb9, 0x2e, 0x6e, 0xe1, 0xe6,
0x10, 0x27, 0x97, 0x3b, 0xbc, 0x2e, 0x04, 0x8d,
0x21, 0xce, 0x4c, 0xf0, 0x29, 0x03, 0x7e, 0x17,
0x0c, 0x34, 0x81, 0x8d, 0xaa, 0x25, 0x33, 0xe6,
0xf8, 0x77, 0xe1, 0x59, 0x65, 0x89, 0x16, 0xa2,
}
func MockRandom() {
/*buf := make([]byte, 96)
rand.Read(buf)
for i := 0; i < len(buf); i++ {
fmt.Printf("0x%02x, ", buf[i])
if (i+1)%8 == 0 {
fmt.Println()
}
}
fmt.Println()*/
r, ok := randReader.(*bytes.Reader) //reuse reader if possible
if ok {
r.Seek(0, io.SeekStart)
} else {
randReader = bytes.NewReader(randBytes)
}
}
func EndMock() {
randReader = rand.Reader
}