Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › crypto/ › pcurves/ › p384/ › scalar.zig › ScalarDouble
ScalarDouble
scalar.ScalarDouble
const ScalarDouble = struct
File
Code
const ScalarDouble = struct {
x1 : Fe ,
x2 : Fe ,
fn fromBytes (comptime bits : usize , s_ : [bits / 8 ]u8 , endian : std .builtin .Endian ) ScalarDouble {
debug .assert (bits > 0 and bits <= 512 and bits >= Fe .saturated_bits and bits <= Fe .saturated_bits * 2 );
var s = s_ ;
if (endian == .big ) {
for (s_ , 0 ..) |x , i | s [s .len - 1 - i ] = x ;
}
var t = ScalarDouble { .x1 = undefined , .x2 = Fe .zero };
{
var b : [encoded_length ]u8 = @splat (0 );
const len = @min (s .len , 32 );
b [0 ..len ].* = s [0 ..len ].*;
t .x1 = Fe .fromBytes (b , .little ) catch unreachable ;
}
if (s_ .len >= 32 ) {
var b : [encoded_length ]u8 = @splat (0 );
const len = @min (s .len - 32 , 32 );
b [0 ..len ].* = s [32 ..][0 ..len ].*;
t .x2 = Fe .fromBytes (b , .little ) catch unreachable ;
}
return t ;
}
fn reduce (expanded : ScalarDouble , comptime bits : usize ) Scalar {
debug .assert (bits > 0 and bits <= Fe .saturated_bits * 3 and bits <= 512 );
var fe = expanded .x1 ;
if (bits >= 256 ) {
const st1 = Fe .fromInt (1 << 256 ) catch unreachable ;
fe = fe .add (expanded .x2 .mul (st1 ));
}
return Scalar { .fe = fe };
}
}