mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: replace []byte with []u8
This commit is contained in:
@@ -5,14 +5,14 @@ module hmac
|
||||
import crypto.internal.subtle
|
||||
|
||||
const (
|
||||
ipad = []byte{len: 256, init: 0x36} // TODO is 256 enough??
|
||||
opad = []byte{len: 256, init: 0x5C}
|
||||
npad = []byte{len: 256, init: 0}
|
||||
ipad = []u8{len: 256, init: 0x36} // TODO is 256 enough??
|
||||
opad = []u8{len: 256, init: 0x5C}
|
||||
npad = []u8{len: 256, init: 0}
|
||||
)
|
||||
|
||||
// new returns a HMAC byte array, depending on the hash algorithm used.
|
||||
pub fn new(key []byte, data []byte, hash_func fn ([]byte) []byte, blocksize int) []byte {
|
||||
mut b_key := []byte{}
|
||||
pub fn new(key []u8, data []u8, hash_func fn ([]u8) []u8, blocksize int) []u8 {
|
||||
mut b_key := []u8{}
|
||||
if key.len <= blocksize {
|
||||
b_key = key.clone() // TODO: remove .clone() once https://github.com/vlang/v/issues/6604 gets fixed
|
||||
} else {
|
||||
@@ -21,13 +21,13 @@ pub fn new(key []byte, data []byte, hash_func fn ([]byte) []byte, blocksize int)
|
||||
if b_key.len < blocksize {
|
||||
b_key << hmac.npad[..blocksize - b_key.len]
|
||||
}
|
||||
mut inner := []byte{}
|
||||
mut inner := []u8{}
|
||||
for i, b in hmac.ipad[..blocksize] {
|
||||
inner << b_key[i] ^ b
|
||||
}
|
||||
inner << data
|
||||
inner_hash := hash_func(inner)
|
||||
mut outer := []byte{cap: b_key.len}
|
||||
mut outer := []u8{cap: b_key.len}
|
||||
for i, b in hmac.opad[..blocksize] {
|
||||
outer << b_key[i] ^ b
|
||||
}
|
||||
@@ -39,6 +39,6 @@ pub fn new(key []byte, data []byte, hash_func fn ([]byte) []byte, blocksize int)
|
||||
// equal compares 2 MACs for equality, without leaking timing info.
|
||||
// Note: if the lengths of the 2 MACs are different, probably a completely different
|
||||
// hash function was used to generate them => no useful timing information.
|
||||
pub fn equal(mac1 []byte, mac2 []byte) bool {
|
||||
pub fn equal(mac1 []u8, mac2 []u8) bool {
|
||||
return subtle.constant_time_compare(mac1, mac2) == 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user