htf: Prohibit expand: undefined. Closes gh-18

This commit is contained in:
Paul Miller 2023-04-10 03:02:36 +00:00
parent 5d54bba846
commit 00665b21ab
No known key found for this signature in database
GPG Key ID: 697079DA6878B89B
2 changed files with 4 additions and 4 deletions

@ -17,7 +17,7 @@ export type Opts = {
p: bigint; p: bigint;
m: number; m: number;
k: number; k: number;
expand?: 'xmd' | 'xof'; expand: 'xmd' | 'xof';
hash: CHash; hash: CHash;
}; };
@ -145,10 +145,10 @@ export function hash_to_field(msg: Uint8Array, count: number, options: Opts): bi
prb = expand_message_xmd(msg, DST, len_in_bytes, hash); prb = expand_message_xmd(msg, DST, len_in_bytes, hash);
} else if (expand === 'xof') { } else if (expand === 'xof') {
prb = expand_message_xof(msg, DST, len_in_bytes, k, hash); prb = expand_message_xof(msg, DST, len_in_bytes, k, hash);
} else if (expand === undefined) { } else if (expand === '_internal_pass') { // for internal tests only
prb = msg; prb = msg;
} else { } else {
throw new Error('expand must be "xmd", "xof" or undefined'); throw new Error('expand must be "xmd" or "xof"');
} }
const u = new Array(count); const u = new Array(count);
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {

@ -858,7 +858,7 @@ describe('bls12-381/basic', () => {
const options = { const options = {
p: bls.params.r, p: bls.params.r,
m: 1, m: 1,
expand: undefined, expand: '_internal_pass',
}; };
for (let vector of SCALAR_VECTORS) { for (let vector of SCALAR_VECTORS) {
const [okmAscii, expectedHex] = vector; const [okmAscii, expectedHex] = vector;