1
0
mirror of https://github.com/henrydcase/nobs.git synced 2024-11-26 00:51:22 +00:00
This commit is contained in:
Henry Case 2018-06-23 16:48:54 +01:00
parent 8cf7cfdc8d
commit 4b06c1b314
5 changed files with 876 additions and 799 deletions

View File

@ -243,4 +243,3 @@ func (d *digest) compress(input []byte, blocks int) {
H = d.h[7]
}
}

View File

@ -88,11 +88,15 @@ func (d *digest) Sum(in []byte) []byte {
dc.Write(in)
idx := int(dc.len & uint64(dc.BlockSize()-1))
for i:=idx+1; i<len(dc.b); i++ {dc.b[i] = 0}
for i := idx + 1; i < len(dc.b); i++ {
dc.b[i] = 0
}
dc.b[idx] = 0x80
if idx >= 56 {
dc.compress(dc.b[:], 1)
for i:=range (dc.b) {dc.b[i] = 0}
for i := range dc.b {
dc.b[i] = 0
}
}
// add total bits

53
rand/ctr_drbg.go Normal file
View File

@ -0,0 +1,53 @@
import rand
import (
"crypto/aes"
"crypto/cipher"
)
// Constants below correspond to AES-256, which is currently
// the only block cipher supported.
const {
Blocklen = 16
Keylen = 32
}
type CtrDrbg struct {
v uint
keylen uint // OZAPTF: is it needed?
counter uint
strength uint
resistance bool
}
func (c *CtrDrbg) update(data []byte) {
}
func New() *CtrDrbg {
c = new(CtrDrbg)
c.key = make([]byte, 0, Keylen)
c.v = make([]byte, 0, Blocklen)
// Security strength for AES-256 as per SP800-57, 5.6.1
c.strength = 256
return c
}
func (c *CtrDrbg) Init(entropy []byte, personalization []byte, strength uint) bool {
if len(entropy) < (c.strength/8) {
return nil
}
// does enropyt needs to have some minimal length?
seed := make([]byte, 0, c.strength / 8)
c.update(seed)
c.counter = 1
return c
}
func (c *CtrDrbg) Update() {}
func (c *CtrDrbg) Read(b []byte) (n int, err error) {
}

21
rand/ctr_drbg_test.go Normal file
View File

@ -0,0 +1,21 @@
import rand
import (
"testing"
"fmt"
"io"
"os"
"crypto/aes"
"crypto/cipher"
)
func TestNominal(t* testing.T) {
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
stream := cipher.NewCTR(block, iv)
stream.XORKeyStream(pt, ct)
}