1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: byte => u8

This commit is contained in:
Alexander Medvednikov
2022-04-15 14:58:56 +03:00
parent b49d873217
commit d4a0d6f73c
221 changed files with 1365 additions and 1365 deletions

View File

@ -58,10 +58,10 @@ fn encrypt_block_generic(xk []u32, mut dst []byte, src []byte) {
mut t2 := u32(0)
mut t3 := u32(0)
for _ in 0 .. nr {
t0 = xk[k + 0] ^ te0[byte(s0 >> 24)] ^ te1[byte(s1 >> 16)] ^ te2[byte(s2 >> 8)] ^ u32(te3[byte(s3)])
t1 = xk[k + 1] ^ te0[byte(s1 >> 24)] ^ te1[byte(s2 >> 16)] ^ te2[byte(s3 >> 8)] ^ u32(te3[byte(s0)])
t2 = xk[k + 2] ^ te0[byte(s2 >> 24)] ^ te1[byte(s3 >> 16)] ^ te2[byte(s0 >> 8)] ^ u32(te3[byte(s1)])
t3 = xk[k + 3] ^ te0[byte(s3 >> 24)] ^ te1[byte(s0 >> 16)] ^ te2[byte(s1 >> 8)] ^ u32(te3[byte(s2)])
t0 = xk[k + 0] ^ te0[u8(s0 >> 24)] ^ te1[u8(s1 >> 16)] ^ te2[u8(s2 >> 8)] ^ u32(te3[u8(s3)])
t1 = xk[k + 1] ^ te0[u8(s1 >> 24)] ^ te1[u8(s2 >> 16)] ^ te2[u8(s3 >> 8)] ^ u32(te3[u8(s0)])
t2 = xk[k + 2] ^ te0[u8(s2 >> 24)] ^ te1[u8(s3 >> 16)] ^ te2[u8(s0 >> 8)] ^ u32(te3[u8(s1)])
t3 = xk[k + 3] ^ te0[u8(s3 >> 24)] ^ te1[u8(s0 >> 16)] ^ te2[u8(s1 >> 8)] ^ u32(te3[u8(s2)])
k += 4
s0 = t0
s1 = t1
@ -105,10 +105,10 @@ fn decrypt_block_generic(xk []u32, mut dst []byte, src []byte) {
mut t2 := u32(0)
mut t3 := u32(0)
for _ in 0 .. nr {
t0 = xk[k + 0] ^ td0[byte(s0 >> 24)] ^ td1[byte(s3 >> 16)] ^ td2[byte(s2 >> 8)] ^ u32(td3[byte(s1)])
t1 = xk[k + 1] ^ td0[byte(s1 >> 24)] ^ td1[byte(s0 >> 16)] ^ td2[byte(s3 >> 8)] ^ u32(td3[byte(s2)])
t2 = xk[k + 2] ^ td0[byte(s2 >> 24)] ^ td1[byte(s1 >> 16)] ^ td2[byte(s0 >> 8)] ^ u32(td3[byte(s3)])
t3 = xk[k + 3] ^ td0[byte(s3 >> 24)] ^ td1[byte(s2 >> 16)] ^ td2[byte(s1 >> 8)] ^ u32(td3[byte(s0)])
t0 = xk[k + 0] ^ td0[u8(s0 >> 24)] ^ td1[u8(s3 >> 16)] ^ td2[u8(s2 >> 8)] ^ u32(td3[u8(s1)])
t1 = xk[k + 1] ^ td0[u8(s1 >> 24)] ^ td1[u8(s0 >> 16)] ^ td2[u8(s3 >> 8)] ^ u32(td3[u8(s2)])
t2 = xk[k + 2] ^ td0[u8(s2 >> 24)] ^ td1[u8(s1 >> 16)] ^ td2[u8(s0 >> 8)] ^ u32(td3[u8(s3)])
t3 = xk[k + 3] ^ td0[u8(s3 >> 24)] ^ td1[u8(s2 >> 16)] ^ td2[u8(s1 >> 8)] ^ u32(td3[u8(s0)])
k += 4
s0 = t0
s1 = t1

View File

@ -29,7 +29,7 @@ const (
// Powers of x mod poly in GF(2).
const (
pow_x = [
byte(0x01),
u8(0x01),
0x02,
0x04,
0x08,
@ -51,7 +51,7 @@ const (
// FIPS-197 Figure 7. S-box substitution values in hexadecimal format.
const (
s_box0 = [
byte(0x63), 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
u8(0x63), 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
@ -73,7 +73,7 @@ const (
// FIPS-197 Figure 14. Inverse S-box substitution values in hexadecimal format.
const (
s_box1 = [
byte(0x52), 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
u8(0x52), 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,

View File

@ -27,13 +27,13 @@ mut:
minor string
}
const magic_cipher_data = [byte(0x4f), 0x72, 0x70, 0x68, 0x65, 0x61, 0x6e, 0x42, 0x65, 0x68, 0x6f,
const magic_cipher_data = [u8(0x4f), 0x72, 0x70, 0x68, 0x65, 0x61, 0x6e, 0x42, 0x65, 0x68, 0x6f,
0x6c, 0x64, 0x65, 0x72, 0x53, 0x63, 0x72, 0x79, 0x44, 0x6f, 0x75, 0x62, 0x74]
// generate_from_password return a bcrypt string from Hashed struct.
pub fn generate_from_password(password []byte, cost int) ?string {
mut p := new_from_password(password, cost) or { return error('Error: $err') }
x := p.hash_byte()
x := p.hash_u8()
return x.bytestr()
}
@ -52,7 +52,7 @@ pub fn compare_hash_and_password(password []byte, hashed_password []byte) ? {
minor: p.minor
}
if p.hash_byte() != other_p.hash_byte() {
if p.hash_u8() != other_p.hash_u8() {
return error('mismatched hash and password')
}
}
@ -140,7 +140,7 @@ fn expensive_blowfish_setup(key []byte, cost u32, salt []byte) ?&blowfish.Blowfi
}
// hash_byte converts the hash value to a byte array.
fn (mut h Hashed) hash_byte() []byte {
fn (mut h Hashed) hash_u8() []byte {
mut arr := []byte{len: 65, init: 0}
arr[0] = `$`
arr[1] = h.major[0]

View File

@ -89,38 +89,38 @@ fn setup_tables(l u32, r u32, mut bf Blowfish) []u32 {
mut xl := l
mut xr := r
xl ^= bf.p[0]
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
(bf.s[3][byte(xl)] ^ bf.p[1])
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
(bf.s[3][byte(xr)] ^ bf.p[2])
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
(bf.s[3][byte(xl)] ^ bf.p[3])
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
(bf.s[3][byte(xr)] ^ bf.p[4])
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
(bf.s[3][byte(xl)] ^ bf.p[5])
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
(bf.s[3][byte(xr)] ^ bf.p[6])
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
(bf.s[3][byte(xl)] ^ bf.p[7])
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
(bf.s[3][byte(xr)] ^ bf.p[8])
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
(bf.s[3][byte(xl)] ^ bf.p[9])
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
(bf.s[3][byte(xr)] ^ bf.p[10])
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
(bf.s[3][byte(xl)] ^ bf.p[11])
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
(bf.s[3][byte(xr)] ^ bf.p[12])
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
(bf.s[3][byte(xl)] ^ bf.p[13])
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
(bf.s[3][byte(xr)] ^ bf.p[14])
xr ^= ((bf.s[0][byte(xl >> 24)] + bf.s[1][byte(xl >> 16)]) ^ bf.s[2][byte(xl >> 8)]) +
(bf.s[3][byte(xl)] ^ bf.p[15])
xl ^= ((bf.s[0][byte(xr >> 24)] + bf.s[1][byte(xr >> 16)]) ^ bf.s[2][byte(xr >> 8)]) +
(bf.s[3][byte(xr)] ^ bf.p[16])
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
(bf.s[3][u8(xl)] ^ bf.p[1])
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
(bf.s[3][u8(xr)] ^ bf.p[2])
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
(bf.s[3][u8(xl)] ^ bf.p[3])
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
(bf.s[3][u8(xr)] ^ bf.p[4])
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
(bf.s[3][u8(xl)] ^ bf.p[5])
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
(bf.s[3][u8(xr)] ^ bf.p[6])
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
(bf.s[3][u8(xl)] ^ bf.p[7])
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
(bf.s[3][u8(xr)] ^ bf.p[8])
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
(bf.s[3][u8(xl)] ^ bf.p[9])
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
(bf.s[3][u8(xr)] ^ bf.p[10])
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
(bf.s[3][u8(xl)] ^ bf.p[11])
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
(bf.s[3][u8(xr)] ^ bf.p[12])
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
(bf.s[3][u8(xl)] ^ bf.p[13])
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
(bf.s[3][u8(xr)] ^ bf.p[14])
xr ^= ((bf.s[0][u8(xl >> 24)] + bf.s[1][u8(xl >> 16)]) ^ bf.s[2][u8(xl >> 8)]) +
(bf.s[3][u8(xl)] ^ bf.p[15])
xl ^= ((bf.s[0][u8(xr >> 24)] + bf.s[1][u8(xr >> 16)]) ^ bf.s[2][u8(xr >> 8)]) +
(bf.s[3][u8(xr)] ^ bf.p[16])
xr ^= bf.p[17]
res := [xl, xr]
return res

View File

@ -40,6 +40,6 @@ pub fn (mut bf Blowfish) encrypt(mut dst []byte, src []byte) {
l := u32(src[0]) << 24 | u32(src[1]) << 16 | u32(src[2]) << 8 | u32(src[3])
r := u32(src[4]) << 24 | u32(src[5]) << 16 | u32(src[6]) << 8 | u32(src[7])
arr := setup_tables(l, r, mut bf)
dst[0], dst[1], dst[2], dst[3] = byte(arr[0] >> 24), byte(arr[0] >> 16), byte(arr[0] >> 8), byte(arr[0])
dst[4], dst[5], dst[6], dst[7] = byte(arr[1] >> 24), byte(arr[1] >> 16), byte(arr[1] >> 8), byte(arr[1])
dst[0], dst[1], dst[2], dst[3] = u8(arr[0] >> 24), u8(arr[0] >> 16), u8(arr[0] >> 8), u8(arr[0])
dst[4], dst[5], dst[6], dst[7] = u8(arr[1] >> 24), u8(arr[1] >> 16), u8(arr[1] >> 8), u8(arr[1])
}

View File

@ -10,35 +10,35 @@
module des
// Used to perform an initial permutation of a 64-bit input block.
// const initial_permutation = [byte(6), 14, 22, 30, 38, 46, 54, 62, 4, 12, 20, 28, 36, 44, 52, 60,
// const initial_permutation = [u8(6), 14, 22, 30, 38, 46, 54, 62, 4, 12, 20, 28, 36, 44, 52, 60,
// 2, 10, 18, 26, 34, 42, 50, 58, 0, 8, 16, 24, 32, 40, 48, 56, 7, 15, 23, 31, 39, 47, 55, 63,
// 5, 13, 21, 29, 37, 45, 53, 61, 3, 11, 19, 27, 35, 43, 51, 59, 1, 9, 17, 25, 33, 41, 49, 57]
// // Used to perform a final permutation of a 4-bit preoutput block. This is the
// // inverse of initialPermutation
// const final_permutation = [byte(24), 56, 16, 48, 8, 40, 0, 32, 25, 57, 17, 49, 9, 41, 1, 33, 26,
// const final_permutation = [u8(24), 56, 16, 48, 8, 40, 0, 32, 25, 57, 17, 49, 9, 41, 1, 33, 26,
// 58, 18, 50, 10, 42, 2, 34, 27, 59, 19, 51, 11, 43, 3, 35, 28, 60, 20, 52, 12, 44, 4, 36, 29,
// 61, 21, 53, 13, 45, 5, 37, 30, 62, 22, 54, 14, 46, 6, 38, 31, 63, 23, 55, 15, 47, 7, 39]
// // Used to expand an input block of 32 bits, producing an output block of 48
// // bits.
// const expansion_function = [byte(0), 31, 30, 29, 28, 27, 28, 27, 26, 25, 24, 23, 24, 23, 22, 21,
// const expansion_function = [u8(0), 31, 30, 29, 28, 27, 28, 27, 26, 25, 24, 23, 24, 23, 22, 21,
// 20, 19, 20, 19, 18, 17, 16, 15, 16, 15, 14, 13, 12, 11, 12, 11, 10, 9, 8, 7, 8, 7, 6, 5, 4,
// 3, 4, 3, 2, 1, 0, 31]
// // Yields a 32-bit output from a 32-bit input
// const permutation_function = [byte(16), 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22,
// const permutation_function = [u8(16), 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22,
// 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7]
// Used in the key schedule to select 56 bits
// from a 64-bit input.
const permuted_choice1 = [byte(7), 15, 23, 31, 39, 47, 55, 63, 6, 14, 22, 30, 38, 46, 54, 62, 5,
const permuted_choice1 = [u8(7), 15, 23, 31, 39, 47, 55, 63, 6, 14, 22, 30, 38, 46, 54, 62, 5,
13, 21, 29, 37, 45, 53, 61, 4, 12, 20, 28, 1, 9, 17, 25, 33, 41, 49, 57, 2, 10, 18, 26, 34,
42, 50, 58, 3, 11, 19, 27, 35, 43, 51, 59, 36, 44, 52, 60]
// Used in the key schedule to produce each subkey by selecting 48 bits from
// the 56-bit input
const permuted_choice2 = [byte(42), 39, 45, 32, 55, 51, 53, 28, 41, 50, 35, 46, 33, 37, 44, 52,
const permuted_choice2 = [u8(42), 39, 45, 32, 55, 51, 53, 28, 41, 50, 35, 46, 33, 37, 44, 52,
30, 48, 40, 49, 29, 36, 43, 54, 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22,
3, 10, 14, 6, 20, 27, 24]

View File

@ -63,13 +63,13 @@ fn test_malleability() ? {
// https://tools.ietf.org/html/rfc8032#section-5.1.7 adds an additional test
// that s be in [0, order). This prevents someone from adding a multiple of
// order to s and obtaining a second valid signature for the same message.
msg := [byte(0x54), 0x65, 0x73, 0x74]
sig := [byte(0x7c), 0x38, 0xe0, 0x26, 0xf2, 0x9e, 0x14, 0xaa, 0xbd, 0x05, 0x9a, 0x0f, 0x2d,
msg := [u8(0x54), 0x65, 0x73, 0x74]
sig := [u8(0x7c), 0x38, 0xe0, 0x26, 0xf2, 0x9e, 0x14, 0xaa, 0xbd, 0x05, 0x9a, 0x0f, 0x2d,
0xb8, 0xb0, 0xcd, 0x78, 0x30, 0x40, 0x60, 0x9a, 0x8b, 0xe6, 0x84, 0xdb, 0x12, 0xf8, 0x2a,
0x27, 0x77, 0x4a, 0xb0, 0x67, 0x65, 0x4b, 0xce, 0x38, 0x32, 0xc2, 0xd7, 0x6f, 0x8f, 0x6f,
0x5d, 0xaf, 0xc0, 0x8d, 0x93, 0x39, 0xd4, 0xee, 0xf6, 0x76, 0x57, 0x33, 0x36, 0xa5, 0xc5,
0x1e, 0xb6, 0xf9, 0x46, 0xb3, 0x1d]
publickey := [byte(0x7d), 0x4d, 0x0e, 0x7f, 0x61, 0x53, 0xa6, 0x9b, 0x62, 0x42, 0xb5, 0x22,
publickey := [u8(0x7d), 0x4d, 0x0e, 0x7f, 0x61, 0x53, 0xa6, 0x9b, 0x62, 0x42, 0xb5, 0x22,
0xab, 0xbe, 0xe6, 0x85, 0xfd, 0xa4, 0x42, 0x0f, 0x88, 0x34, 0xb1, 0x08, 0xc3, 0xbd, 0xae,
0x36, 0x9e, 0xf5, 0x49, 0xfa]
// verify should fail on provided bytes

View File

@ -237,12 +237,12 @@ fn test_set_bytes_from_dalek_test_vectors() ? {
mut tests := [
FeRTTest{
fe: Element{358744748052810, 1691584618240980, 977650209285361, 1429865912637724, 560044844278676}
b: [byte(74), 209, 69, 197, 70, 70, 161, 222, 56, 226, 229, 19, 112, 60, 25, 92, 187,
b: [u8(74), 209, 69, 197, 70, 70, 161, 222, 56, 226, 229, 19, 112, 60, 25, 92, 187,
74, 222, 56, 50, 153, 51, 233, 40, 74, 57, 6, 160, 185, 213, 31]
},
FeRTTest{
fe: Element{84926274344903, 473620666599931, 365590438845504, 1028470286882429, 2146499180330972}
b: [byte(199), 23, 106, 112, 61, 77, 216, 79, 186, 60, 11, 118, 13, 16, 103, 15, 42,
b: [u8(199), 23, 106, 112, 61, 77, 216, 79, 186, 60, 11, 118, 13, 16, 103, 15, 42,
32, 83, 250, 44, 57, 204, 198, 78, 199, 253, 119, 146, 172, 3, 122]
},
]

View File

@ -90,7 +90,7 @@ fn fn_cofactor(mut data []byte) bool {
mut sc := Scalar{
s: [32]byte{}
}
sc.s[0] = byte(0x08)
sc.s[0] = u8(0x08)
s.multiply(s, sc)
mut pp := Point{}
pp.scalar_base_mult(mut s)

View File

@ -2,12 +2,12 @@ module edwards25519
const (
// d is a constant in the curve equation.
d_bytes = [byte(0xa3), 0x78, 0x59, 0x13, 0xca, 0x4d, 0xeb, 0x75, 0xab, 0xd8, 0x41, 0x41,
d_bytes = [u8(0xa3), 0x78, 0x59, 0x13, 0xca, 0x4d, 0xeb, 0x75, 0xab, 0xd8, 0x41, 0x41,
0x4d, 0x0a, 0x70, 0x00, 0x98, 0xe8, 0x79, 0x77, 0x79, 0x40, 0xc7, 0x8c, 0x73, 0xfe, 0x6f,
0x2b, 0xee, 0x6c, 0x03, 0x52]
id_bytes = [byte(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
id_bytes = [u8(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0]
gen_bytes = [byte(0x58), 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
gen_bytes = [u8(0x58), 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66, 0x66]
d_const = d_const_generate() or { panic(err) }
@ -220,8 +220,8 @@ fn (mut v Point) bytes_generic(mut buf [32]byte) []byte {
mut out := copy_field_element(mut buf, mut y)
unsafe {
// out[31] |= byte(x.is_negative() << 7) //original one
out[31] |= byte(x.is_negative() * 128) // x << 7 == x * 2^7
// out[31] |= u8(x.is_negative() << 7) //original one
out[31] |= u8(x.is_negative() * 128) // x << 7 == x * 2^7
}
return out
}

View File

@ -23,17 +23,17 @@ mut:
pub const (
sc_zero = Scalar{
s: [byte(0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
s: [u8(0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0]!
}
sc_one = Scalar{
s: [byte(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
s: [u8(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0]!
}
sc_minus_one = Scalar{
s: [byte(236), 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0,
s: [u8(236), 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16]!
}
)
@ -613,38 +613,38 @@ fn sc_mul_add(mut s [32]byte, a [32]byte, b [32]byte, c [32]byte) {
s11 += carry[10]
s10 -= carry[10] * 2097152
s[0] = byte(s0 >> 0)
s[1] = byte(s0 >> 8)
s[2] = byte((s0 >> 16) | (s1 * 32))
s[3] = byte(s1 >> 3)
s[4] = byte(s1 >> 11)
s[5] = byte((s1 >> 19) | (s2 * 4))
s[6] = byte(s2 >> 6)
s[7] = byte((s2 >> 14) | (s3 * 128))
s[8] = byte(s3 >> 1)
s[9] = byte(s3 >> 9)
s[10] = byte((s3 >> 17) | (s4 * 16))
s[11] = byte(s4 >> 4)
s[12] = byte(s4 >> 12)
s[13] = byte((s4 >> 20) | (s5 * 2))
s[14] = byte(s5 >> 7)
s[15] = byte((s5 >> 15) | (s6 * 64))
s[16] = byte(s6 >> 2)
s[17] = byte(s6 >> 10)
s[18] = byte((s6 >> 18) | (s7 * 8))
s[19] = byte(s7 >> 5)
s[20] = byte(s7 >> 13)
s[21] = byte(s8 >> 0)
s[22] = byte(s8 >> 8)
s[23] = byte((s8 >> 16) | (s9 * 32))
s[24] = byte(s9 >> 3)
s[25] = byte(s9 >> 11)
s[26] = byte((s9 >> 19) | (s10 * 4))
s[27] = byte(s10 >> 6)
s[28] = byte((s10 >> 14) | (s11 * 128))
s[29] = byte(s11 >> 1)
s[30] = byte(s11 >> 9)
s[31] = byte(s11 >> 17)
s[0] = u8(s0 >> 0)
s[1] = u8(s0 >> 8)
s[2] = u8((s0 >> 16) | (s1 * 32))
s[3] = u8(s1 >> 3)
s[4] = u8(s1 >> 11)
s[5] = u8((s1 >> 19) | (s2 * 4))
s[6] = u8(s2 >> 6)
s[7] = u8((s2 >> 14) | (s3 * 128))
s[8] = u8(s3 >> 1)
s[9] = u8(s3 >> 9)
s[10] = u8((s3 >> 17) | (s4 * 16))
s[11] = u8(s4 >> 4)
s[12] = u8(s4 >> 12)
s[13] = u8((s4 >> 20) | (s5 * 2))
s[14] = u8(s5 >> 7)
s[15] = u8((s5 >> 15) | (s6 * 64))
s[16] = u8(s6 >> 2)
s[17] = u8(s6 >> 10)
s[18] = u8((s6 >> 18) | (s7 * 8))
s[19] = u8(s7 >> 5)
s[20] = u8(s7 >> 13)
s[21] = u8(s8 >> 0)
s[22] = u8(s8 >> 8)
s[23] = u8((s8 >> 16) | (s9 * 32))
s[24] = u8(s9 >> 3)
s[25] = u8(s9 >> 11)
s[26] = u8((s9 >> 19) | (s10 * 4))
s[27] = u8(s10 >> 6)
s[28] = u8((s10 >> 14) | (s11 * 128))
s[29] = u8(s11 >> 1)
s[30] = u8(s11 >> 9)
s[31] = u8(s11 >> 17)
}
// Input:
@ -940,38 +940,38 @@ fn sc_reduce(mut out [32]byte, mut s []byte) {
s11 += carry[10]
s10 -= carry[10] * 2097152
out[0] = byte(s0 >> 0)
out[1] = byte(s0 >> 8)
out[2] = byte((s0 >> 16) | (s1 * 32))
out[3] = byte(s1 >> 3)
out[4] = byte(s1 >> 11)
out[5] = byte((s1 >> 19) | (s2 * 4))
out[6] = byte(s2 >> 6)
out[7] = byte((s2 >> 14) | (s3 * 128))
out[8] = byte(s3 >> 1)
out[9] = byte(s3 >> 9)
out[10] = byte((s3 >> 17) | (s4 * 16))
out[11] = byte(s4 >> 4)
out[12] = byte(s4 >> 12)
out[13] = byte((s4 >> 20) | (s5 * 2))
out[14] = byte(s5 >> 7)
out[15] = byte((s5 >> 15) | (s6 * 64))
out[16] = byte(s6 >> 2)
out[17] = byte(s6 >> 10)
out[18] = byte((s6 >> 18) | (s7 * 8))
out[19] = byte(s7 >> 5)
out[20] = byte(s7 >> 13)
out[21] = byte(s8 >> 0)
out[22] = byte(s8 >> 8)
out[23] = byte((s8 >> 16) | (s9 * 32))
out[24] = byte(s9 >> 3)
out[25] = byte(s9 >> 11)
out[26] = byte((s9 >> 19) | (s10 * 4))
out[27] = byte(s10 >> 6)
out[28] = byte((s10 >> 14) | (s11 * 128))
out[29] = byte(s11 >> 1)
out[30] = byte(s11 >> 9)
out[31] = byte(s11 >> 17)
out[0] = u8(s0 >> 0)
out[1] = u8(s0 >> 8)
out[2] = u8((s0 >> 16) | (s1 * 32))
out[3] = u8(s1 >> 3)
out[4] = u8(s1 >> 11)
out[5] = u8((s1 >> 19) | (s2 * 4))
out[6] = u8(s2 >> 6)
out[7] = u8((s2 >> 14) | (s3 * 128))
out[8] = u8(s3 >> 1)
out[9] = u8(s3 >> 9)
out[10] = u8((s3 >> 17) | (s4 * 16))
out[11] = u8(s4 >> 4)
out[12] = u8(s4 >> 12)
out[13] = u8((s4 >> 20) | (s5 * 2))
out[14] = u8(s5 >> 7)
out[15] = u8((s5 >> 15) | (s6 * 64))
out[16] = u8(s6 >> 2)
out[17] = u8(s6 >> 10)
out[18] = u8((s6 >> 18) | (s7 * 8))
out[19] = u8(s7 >> 5)
out[20] = u8(s7 >> 13)
out[21] = u8(s8 >> 0)
out[22] = u8(s8 >> 8)
out[23] = u8((s8 >> 16) | (s9 * 32))
out[24] = u8(s9 >> 3)
out[25] = u8(s9 >> 11)
out[26] = u8((s9 >> 19) | (s10 * 4))
out[27] = u8(s10 >> 6)
out[28] = u8((s10 >> 14) | (s11 * 128))
out[29] = u8(s11 >> 1)
out[30] = u8(s11 >> 9)
out[31] = u8(s11 >> 17)
}
// non_adjacent_form computes a width-w non-adjacent form for this scalar.

View File

@ -22,7 +22,7 @@ fn test_scalar_equal() {
fn test_scalar_non_adjacent_form() {
mut s := Scalar{
s: [byte(0x1a), 0x0e, 0x97, 0x8a, 0x90, 0xf6, 0x62, 0x2d, 0x37, 0x47, 0x02, 0x3f, 0x8a,
s: [u8(0x1a), 0x0e, 0x97, 0x8a, 0x90, 0xf6, 0x62, 0x2d, 0x37, 0x47, 0x02, 0x3f, 0x8a,
0xd8, 0x26, 0x4d, 0xa7, 0x58, 0xaa, 0x1b, 0x88, 0xe0, 0x40, 0xd1, 0x58, 0x9e, 0x7b,
0x7f, 0x23, 0x76, 0xef, 0x09]!
}
@ -101,7 +101,7 @@ fn test_scalar_set_canonical_bytes_round_trip() ? {
const (
sc_error = Scalar{
s: [32]byte{init: (byte(-1))}
s: [32]byte{init: (u8(-1))}
}
)

View File

@ -1,9 +1,9 @@
module edwards25519
const (
dalek_scalar = Scalar{[byte(219), 106, 114, 9, 174, 249, 155, 89, 69, 203, 201, 93, 92, 116,
dalek_scalar = Scalar{[u8(219), 106, 114, 9, 174, 249, 155, 89, 69, 203, 201, 93, 92, 116,
234, 187, 78, 115, 103, 172, 182, 98, 62, 103, 187, 136, 13, 100, 248, 110, 12, 4]!}
dsc_basepoint = [byte(0xf4), 0xef, 0x7c, 0xa, 0x34, 0x55, 0x7b, 0x9f, 0x72, 0x3b, 0xb6, 0x1e,
dsc_basepoint = [u8(0xf4), 0xef, 0x7c, 0xa, 0x34, 0x55, 0x7b, 0x9f, 0x72, 0x3b, 0xb6, 0x1e,
0xf9, 0x46, 0x9, 0x91, 0x1c, 0xb9, 0xc0, 0x6c, 0x17, 0x28, 0x2d, 0x8b, 0x43, 0x2b, 0x5,
0x18, 0x6a, 0x54, 0x3e, 0x48]
)
@ -24,7 +24,7 @@ fn test_scalar_mult_small_scalars() {
assert i.equal(p) == 1
assert check_on_curve(p) == true
z = Scalar{[byte(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
z = Scalar{[u8(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0]!}
p.scalar_mult(mut z, b)

View File

@ -88,12 +88,12 @@ fn (mut v NafLookupTable8) from_p3(q Point) {
fn (mut v ProjLookupTable) select_into(mut dest ProjectiveCached, x i8) {
// Compute xabs = |x|
xmask := x >> 7
xabs := byte((x + xmask) ^ xmask)
xabs := u8((x + xmask) ^ xmask)
dest.zero()
for j := 1; j <= 8; j++ {
// Set dest = j*Q if |x| = j
cond := subtle.constant_time_byte_eq(xabs, byte(j))
cond := subtle.constant_time_byte_eq(xabs, u8(j))
dest.selected(&v.points[j - 1], dest, cond)
}
// Now dest = |x|*Q, conditionally negate to get x*Q
@ -104,12 +104,12 @@ fn (mut v ProjLookupTable) select_into(mut dest ProjectiveCached, x i8) {
fn (mut v AffineLookupTable) select_into(mut dest AffineCached, x i8) {
// Compute xabs = |x|
xmask := x >> 7
xabs := byte((x + xmask) ^ xmask)
xabs := u8((x + xmask) ^ xmask)
dest.zero()
for j := 1; j <= 8; j++ {
// Set dest = j*Q if |x| = j
cond := subtle.constant_time_byte_eq(xabs, byte(j))
cond := subtle.constant_time_byte_eq(xabs, u8(j))
dest.selected(v.points[j - 1], dest, cond)
}
// Now dest = |x|*Q, conditionally negate to get x*Q

View File

@ -21,21 +21,21 @@ import crypto.sha512
// import crypto.blake2b_512
const (
keys = [
[byte(0xb), 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb],
[u8(0xb), 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb, 0xb],
'Jefe'.bytes(),
[byte(0xAA), 0xAA, 0xAA, 0x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 0xDD, 0xDD, 0xDD, 0xDD],
[byte(0xcd), 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
[u8(0xcd), 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd],

View File

@ -23,7 +23,7 @@ pub fn constant_time_compare(x []byte, y []byte) int {
if x.len != y.len {
return 0
}
mut v := byte(0)
mut v := u8(0)
for i in 0 .. x.len {
v |= x[i] ^ y[i]
}
@ -37,8 +37,8 @@ pub fn constant_time_copy(v int, mut x []byte, y []byte) {
if x.len != y.len {
panic('subtle: arrays have different lengths')
}
xmask := byte(v - 1)
ymask := byte(~(v - 1))
xmask := u8(v - 1)
ymask := u8(~(v - 1))
for i := 0; i < x.len; i++ {
x[i] = x[i] & xmask | y[i] & ymask
}

View File

@ -35,20 +35,20 @@ fn test_constant_time_select() {
}
fn test_constant_time_compare() {
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3]) == 1
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 9]) == 0
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2, 3, 4]) == 0
assert constant_time_compare([byte(1), 2, 3], [byte(1), 2]) == 0
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 3]) == 1
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 9]) == 0
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2, 3, 4]) == 0
assert constant_time_compare([u8(1), 2, 3], [u8(1), 2]) == 0
}
fn test_constant_time_copy() {
y := [byte(3), 4, 5]
mut x := [byte(0), 0, 0]
y := [u8(3), 4, 5]
mut x := [u8(0), 0, 0]
constant_time_copy(0, mut x, y)
assert x == [byte(0), 0, 0]
assert x == [u8(0), 0, 0]
constant_time_copy(1, mut x, y)
assert x == y
assert x == [byte(3), 4, 5]
assert x == [u8(3), 4, 5]
}
fn test_constant_time_less_or_eq() {

View File

@ -21,7 +21,7 @@ pub fn int_u64(max u64) ?u64 {
mut n := u64(0)
for {
mut bytes := read(k) ?
bytes[0] &= byte(int(u64(1) << b) - 1)
bytes[0] &= u8(int(u64(1) << b) - 1)
x := bytes_to_u64(bytes)
n = x[0]
// NOTE: maybe until we have bigint could do it another way?

View File

@ -32,9 +32,9 @@ pub fn new_cipher(key []byte) ?Cipher {
for i in 0 .. 256 {
c.s[i] = u32(i)
}
mut j := byte(0)
mut j := u8(0)
for i in 0 .. 256 {
j += byte(c.s[i]) + key[i % key.len]
j += u8(c.s[i]) + key[i % key.len]
tmp := c.s[i]
c.s[i] = c.s[j]
c.s[j] = tmp
@ -66,13 +66,13 @@ pub fn (mut c Cipher) xor_key_stream(mut dst []byte, mut src []byte) {
mut i := c.i
mut j := c.j
for k, v in src {
i += byte(1)
i += u8(1)
x := c.s[i]
j += byte(x)
j += u8(x)
y := c.s[j]
c.s[i] = y
c.s[j] = x
dst[k] = v ^ byte(c.s[byte(x + y)])
dst[k] = v ^ u8(c.s[u8(x + y)])
}
c.i = i
c.j = j