Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed possible race condition and improved rng #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions kyber_1024/kyber_1024_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import(

func Test_kyber1024(t *testing.T){
var curpos,temp_len uint
kyber_ops.Set_test_rand()
data,err:=os.ReadFile("kyber1024-kat.rsp")
if err!=nil{
t.Fatal(err)
Expand Down Expand Up @@ -54,6 +55,7 @@ func Test_kyber1024(t *testing.T){

func Test_kyber1024_90s(t *testing.T){
var curpos,temp_len uint
kyber_ops.Set_test_rand()
data,err:=os.ReadFile("kyber1024_90s-kat.rsp")
if err!=nil{
t.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions kyber_512/kyber_512_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import(

func Test_kyber512(t *testing.T){
var curpos,temp_len uint
kyber_ops.Set_test_rand()
data,err:=os.ReadFile("kyber512-kat.rsp")
if err!=nil{
t.Fatal(err)
Expand Down Expand Up @@ -54,6 +55,7 @@ func Test_kyber512(t *testing.T){

func Test_kyber512_90s(t *testing.T){
var curpos,temp_len uint
kyber_ops.Set_test_rand()
data,err:=os.ReadFile("kyber512_90s-kat.rsp")
if err!=nil{
t.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions kyber_768/kyber_768_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import(

func Test_kyber_768(t *testing.T){
var curpos,temp_len uint
kyber_ops.Set_test_rand()
data,err:=os.ReadFile("kyber768-kat.rsp")
if err!=nil{
t.Fatal(err)
Expand Down Expand Up @@ -54,6 +55,7 @@ func Test_kyber_768(t *testing.T){

func Test_kyber_768_90s(t *testing.T){
var curpos,temp_len uint
kyber_ops.Set_test_rand()
data,err:=os.ReadFile("kyber768_90s-kat.rsp")
if err!=nil{
t.Fatal(err)
Expand Down
17 changes: 10 additions & 7 deletions kyber_ops/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func Init_Seed(str string)(err error){
}

var rng rng_info
var test_rand bool=false

func Set_test_rand(){
test_rand=true
}

func init_rng(seed *[48]byte){
rng.iv=[16]byte{}
Expand All @@ -50,6 +55,10 @@ func init_rng(seed *[48]byte){
}

func Read_RNG(rand_data []byte){
if !test_rand{
rand.Read(rand_data)
return
}
cipher,_:=aes.NewCipher(rng.key[:])
length:=len(rand_data)
for cur:=0;cur<length;cur+=16{
Expand Down Expand Up @@ -79,12 +88,6 @@ func update_rng(addion *[48]byte){
}
}

func init(){
var bytes48 [48]byte
rand.Read(bytes48[:])
init_rng(&bytes48)
}

func CBD2(B *[128]byte,f *[256]int16){
const b101=0x55555555
var(
Expand Down Expand Up @@ -318,7 +321,7 @@ func CSUBQ_vec[v vec](f v){
}

func aes_count(iv *[16]byte){
for i:=15;i>0;i--{
for i:=15;i>=0;i--{
iv[i]++
if iv[i]>0{
break
Expand Down