Function fromSec1 [src]
Deserialize a SEC1-encoded point.
Prototype
pub fn fromSec1(s: []const u8) (EncodingError || NotSquareError || NonCanonicalError)!P384
Parameters
s: []const u8
Source
pub fn fromSec1(s: []const u8) (EncodingError || NotSquareError || NonCanonicalError)!P384 {
if (s.len < 1) return error.InvalidEncoding;
const encoding_type = s[0];
const encoded = s[1..];
switch (encoding_type) {
0 => {
if (encoded.len != 0) return error.InvalidEncoding;
return P384.identityElement;
},
2, 3 => {
if (encoded.len != 48) return error.InvalidEncoding;
const x = try Fe.fromBytes(encoded[0..48].*, .big);
const y_is_odd = (encoding_type == 3);
const y = try recoverY(x, y_is_odd);
return P384{ .x = x, .y = y };
},
4 => {
if (encoded.len != 96) return error.InvalidEncoding;
const x = try Fe.fromBytes(encoded[0..48].*, .big);
const y = try Fe.fromBytes(encoded[48..96].*, .big);
return P384.fromAffineCoordinates(.{ .x = x, .y = y });
},
else => return error.InvalidEncoding,
}
}