mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: handle fixed []u8
This commit is contained in:
parent
1c6f63ac0a
commit
78cb6e2b41
@ -89,11 +89,11 @@ fn is_on_curve(x Element, y Element, z Element, t Element) bool {
|
|||||||
pub fn (mut v Point) bytes_montgomery() []u8 {
|
pub fn (mut v Point) bytes_montgomery() []u8 {
|
||||||
// This function is outlined to make the allocations inline in the caller
|
// This function is outlined to make the allocations inline in the caller
|
||||||
// rather than happen on the heap.
|
// rather than happen on the heap.
|
||||||
mut buf := [32]byte{}
|
mut buf := [32]u8{}
|
||||||
return v.bytes_montgomery_generic(mut buf)
|
return v.bytes_montgomery_generic(mut buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut v Point) bytes_montgomery_generic(mut buf [32]byte) []u8 {
|
fn (mut v Point) bytes_montgomery_generic(mut buf [32]u8) []u8 {
|
||||||
check_initialized(v)
|
check_initialized(v)
|
||||||
|
|
||||||
// RFC 7748, Section 4.1 provides the bilinear map to calculate the
|
// RFC 7748, Section 4.1 provides the bilinear map to calculate the
|
||||||
|
@ -23,7 +23,7 @@ fn testsuite_begin() {
|
|||||||
//
|
//
|
||||||
// Disabled curve25519 not available yet, but maybe can use own curve25519
|
// Disabled curve25519 not available yet, but maybe can use own curve25519
|
||||||
/*
|
/*
|
||||||
fn fn_mon(scalar [32]byte) bool {
|
fn fn_mon(scalar [32]u8) bool {
|
||||||
mut s := new_scalar().set_bytes_with_clamping(scalar[..])
|
mut s := new_scalar().set_bytes_with_clamping(scalar[..])
|
||||||
p := (&Point{}).scalar_base_mult(s)
|
p := (&Point{}).scalar_base_mult(s)
|
||||||
got := p.bytes_montgomery()
|
got := p.bytes_montgomery()
|
||||||
@ -32,7 +32,7 @@ fn fn_mon(scalar [32]byte) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_bytes_montgomery() {
|
fn test_bytes_montgomery() {
|
||||||
/* f := fn(scalar [32]byte) bool {
|
/* f := fn(scalar [32]u8) bool {
|
||||||
s := new_scalar().set_bytes_with_clamping(scalar[..])
|
s := new_scalar().set_bytes_with_clamping(scalar[..])
|
||||||
p := (&Point{}).scalar_base_mult(s)
|
p := (&Point{}).scalar_base_mult(s)
|
||||||
got := p.bytes_montgomery()
|
got := p.bytes_montgomery()
|
||||||
@ -88,7 +88,7 @@ fn fn_cofactor(mut data []u8) bool {
|
|||||||
|
|
||||||
// 8 * p == (8 * s) * B
|
// 8 * p == (8 * s) * B
|
||||||
mut sc := Scalar{
|
mut sc := Scalar{
|
||||||
s: [32]byte{}
|
s: [32]u8{}
|
||||||
}
|
}
|
||||||
sc.s[0] = u8(0x08)
|
sc.s[0] = u8(0x08)
|
||||||
s.multiply(s, sc)
|
s.multiply(s, sc)
|
||||||
|
@ -204,11 +204,11 @@ fn (mut v AffineCached) zero() AffineCached {
|
|||||||
pub fn (mut v Point) bytes() []u8 {
|
pub fn (mut v Point) bytes() []u8 {
|
||||||
// This function is outlined to make the allocations inline in the caller
|
// This function is outlined to make the allocations inline in the caller
|
||||||
// rather than happen on the heap.
|
// rather than happen on the heap.
|
||||||
mut buf := [32]byte{}
|
mut buf := [32]u8{}
|
||||||
return v.bytes_generic(mut buf)
|
return v.bytes_generic(mut buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut v Point) bytes_generic(mut buf [32]byte) []u8 {
|
fn (mut v Point) bytes_generic(mut buf [32]u8) []u8 {
|
||||||
check_initialized(v)
|
check_initialized(v)
|
||||||
|
|
||||||
mut zinv := Element{}
|
mut zinv := Element{}
|
||||||
@ -226,7 +226,7 @@ fn (mut v Point) bytes_generic(mut buf [32]byte) []u8 {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_field_element(mut buf [32]byte, mut v Element) []u8 {
|
fn copy_field_element(mut buf [32]u8, mut v Element) []u8 {
|
||||||
// this fail in test
|
// this fail in test
|
||||||
/*
|
/*
|
||||||
copy(mut buf[..], v.bytes())
|
copy(mut buf[..], v.bytes())
|
||||||
|
@ -18,7 +18,7 @@ struct Scalar {
|
|||||||
mut:
|
mut:
|
||||||
// s is the Scalar value in little-endian. The value is always reduced
|
// s is the Scalar value in little-endian. The value is always reduced
|
||||||
// between operations.
|
// between operations.
|
||||||
s [32]byte
|
s [32]u8
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
@ -210,7 +210,7 @@ fn load4(inp []u8) i64 {
|
|||||||
// Output:
|
// Output:
|
||||||
// s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
|
// s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
|
||||||
// where l = 2^252 + 27742317777372353535851937790883648493.
|
// where l = 2^252 + 27742317777372353535851937790883648493.
|
||||||
fn sc_mul_add(mut s [32]byte, a [32]byte, b [32]byte, c [32]byte) {
|
fn sc_mul_add(mut s [32]u8, a [32]u8, b [32]u8, c [32]u8) {
|
||||||
a0 := 2097151 & load3(a[..])
|
a0 := 2097151 & load3(a[..])
|
||||||
a1 := 2097151 & (load4(a[2..]) >> 5)
|
a1 := 2097151 & (load4(a[2..]) >> 5)
|
||||||
a2 := 2097151 & (load3(a[5..]) >> 2)
|
a2 := 2097151 & (load3(a[5..]) >> 2)
|
||||||
@ -653,7 +653,7 @@ fn sc_mul_add(mut s [32]byte, a [32]byte, b [32]byte, c [32]byte) {
|
|||||||
// Output:
|
// Output:
|
||||||
// s[0]+256*s[1]+...+256^31*s[31] = s mod l
|
// s[0]+256*s[1]+...+256^31*s[31] = s mod l
|
||||||
// where l = 2^252 + 27742317777372353535851937790883648493.
|
// where l = 2^252 + 27742317777372353535851937790883648493.
|
||||||
fn sc_reduce(mut out [32]byte, mut s []u8) {
|
fn sc_reduce(mut out [32]u8, mut s []u8) {
|
||||||
assert out.len == 32
|
assert out.len == 32
|
||||||
assert s.len == 64
|
assert s.len == 64
|
||||||
mut s0 := 2097151 & load3(s[..])
|
mut s0 := 2097151 & load3(s[..])
|
||||||
|
@ -101,7 +101,7 @@ fn test_scalar_set_canonical_bytes_round_trip() ? {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
sc_error = Scalar{
|
sc_error = Scalar{
|
||||||
s: [32]byte{init: (u8(-1))}
|
s: [32]u8{init: (u8(-1))}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ pub fn (mut d Digest) checksum() []u8 {
|
|||||||
// 8 bytes representing the message length in bits.
|
// 8 bytes representing the message length in bits.
|
||||||
//
|
//
|
||||||
// 1 byte end marker :: 0-63 padding bytes :: 8 byte length
|
// 1 byte end marker :: 0-63 padding bytes :: 8 byte length
|
||||||
// tmp := [1 + 63 + 8]byte{0x80}
|
// tmp := [1 + 63 + 8]u8{0x80}
|
||||||
mut tmp := []u8{len: (1 + 63 + 8)}
|
mut tmp := []u8{len: (1 + 63 + 8)}
|
||||||
tmp[0] = 0x80
|
tmp[0] = 0x80
|
||||||
pad := ((55 - d.len) % 64) // calculate number of padding bytes
|
pad := ((55 - d.len) % 64) // calculate number of padding bytes
|
||||||
|
@ -81,7 +81,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
|
|||||||
/*
|
/*
|
||||||
// Legacy version
|
// Legacy version
|
||||||
// max u64 18446744073709551615 => 20 byte
|
// max u64 18446744073709551615 => 20 byte
|
||||||
mut buf := [32]byte{}
|
mut buf := [32]u8{}
|
||||||
mut i := 20
|
mut i := 20
|
||||||
mut d1 := d
|
mut d1 := d
|
||||||
for i >= (21 - n_char) {
|
for i >= (21 - n_char) {
|
||||||
|
@ -1407,7 +1407,7 @@ pub fn (mut t Table) complete_interface_check() {
|
|||||||
//
|
//
|
||||||
// `128 > [16]u8`
|
// `128 > [16]u8`
|
||||||
//
|
//
|
||||||
// `608 > [76]byte`
|
// `608 > [76]u8`
|
||||||
pub fn (mut t Table) bitsize_to_type(bit_size int) Type {
|
pub fn (mut t Table) bitsize_to_type(bit_size int) Type {
|
||||||
match bit_size {
|
match bit_size {
|
||||||
8 {
|
8 {
|
||||||
|
@ -950,7 +950,7 @@ pub mut:
|
|||||||
pub struct ArrayFixed {
|
pub struct ArrayFixed {
|
||||||
pub:
|
pub:
|
||||||
size int
|
size int
|
||||||
size_expr Expr // used by fmt for e.g. ´[my_const]byte´
|
size_expr Expr // used by fmt for e.g. ´[my_const]u8´
|
||||||
pub mut:
|
pub mut:
|
||||||
elem_type Type
|
elem_type Type
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
|
|||||||
}
|
}
|
||||||
node.elem_type = elem_type
|
node.elem_type = elem_type
|
||||||
} else if node.is_fixed && node.exprs.len == 1 && node.elem_type != ast.void_type {
|
} else if node.is_fixed && node.exprs.len == 1 && node.elem_type != ast.void_type {
|
||||||
// [50]byte
|
// [50]u8
|
||||||
mut fixed_size := i64(0)
|
mut fixed_size := i64(0)
|
||||||
init_expr := node.exprs[0]
|
init_expr := node.exprs[0]
|
||||||
c.expr(init_expr)
|
c.expr(init_expr)
|
||||||
|
@ -1578,7 +1578,7 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) {
|
|||||||
f.indent--
|
f.indent--
|
||||||
}
|
}
|
||||||
f.write(']')
|
f.write(']')
|
||||||
// `[100]byte`
|
// `[100]u8`
|
||||||
if node.is_fixed {
|
if node.is_fixed {
|
||||||
if node.has_val {
|
if node.has_val {
|
||||||
f.write('!')
|
f.write('!')
|
||||||
|
@ -2119,7 +2119,7 @@ fn (mut g JsGen) gen_array_init_expr(it ast.ArrayInit) {
|
|||||||
g.expr(it.len_expr)
|
g.expr(it.len_expr)
|
||||||
g.write(')')
|
g.write(')')
|
||||||
} else if it.is_fixed && it.exprs.len == 1 {
|
} else if it.is_fixed && it.exprs.len == 1 {
|
||||||
// [100]byte codegen
|
// [100]u8 codegen
|
||||||
t1 := g.new_tmp_var()
|
t1 := g.new_tmp_var()
|
||||||
t2 := g.new_tmp_var()
|
t2 := g.new_tmp_var()
|
||||||
g.writeln('(function() {')
|
g.writeln('(function() {')
|
||||||
|
@ -43,7 +43,7 @@ fn (mut p Parser) array_init() ast.ArrayInit {
|
|||||||
}
|
}
|
||||||
last_pos = p.tok.pos()
|
last_pos = p.tok.pos()
|
||||||
} else {
|
} else {
|
||||||
// [1,2,3] or [const]byte
|
// [1,2,3] or [const]u8
|
||||||
old_inside_array_lit := p.inside_array_lit
|
old_inside_array_lit := p.inside_array_lit
|
||||||
p.inside_array_lit = true
|
p.inside_array_lit = true
|
||||||
pre_cmnts = p.eat_comments()
|
pre_cmnts = p.eat_comments()
|
||||||
@ -66,7 +66,7 @@ fn (mut p Parser) array_init() ast.ArrayInit {
|
|||||||
last_pos = p.tok.pos()
|
last_pos = p.tok.pos()
|
||||||
p.check(.rsbr)
|
p.check(.rsbr)
|
||||||
if exprs.len == 1 && p.tok.kind in [.name, .amp, .lsbr] && p.tok.line_nr == line_nr {
|
if exprs.len == 1 && p.tok.kind in [.name, .amp, .lsbr] && p.tok.line_nr == line_nr {
|
||||||
// [100]byte
|
// [100]u8
|
||||||
elem_type = p.parse_type()
|
elem_type = p.parse_type()
|
||||||
last_pos = p.tok.pos()
|
last_pos = p.tok.pos()
|
||||||
is_fixed = true
|
is_fixed = true
|
||||||
|
Loading…
Reference in New Issue
Block a user