@@ -37,8 +37,9 @@ const isu8 = (a: unknown): a is Uint8Array => (
3737const au8 = ( a : unknown , l ?: number ) : Bytes => // assert is Uint8Array (of specific length)
3838 ! isu8 ( a ) || ( typeof l === 'number' && l > 0 && a . length !== l ) ?
3939 err ( 'Uint8Array expected' ) : a ;
40- const u8n = ( data ?: any ) => new Uint8Array ( data ) ; // creates Uint8Array
41- const toU8 = ( a : Hex , len ?: number ) => au8 ( isS ( a ) ? h2b ( a ) : u8n ( au8 ( a ) ) , len ) ; // norm(hex/u8a) to u8a
40+ const u8n = ( len : number ) => new Uint8Array ( len ) ; // creates Uint8Array
41+ const u8fr = ( buf : ArrayLike < number > ) => Uint8Array . from ( buf ) ;
42+ const toU8 = ( a : Hex , len ?: number ) => au8 ( isS ( a ) ? h2b ( a ) : u8fr ( au8 ( a ) ) , len ) ; // norm(hex/u8a) to u8a
4243const M = ( a : bigint , b : bigint = P ) => { // mod division
4344 const r = a % b ; return r >= 0n ? r : b + r ;
4445} ;
@@ -326,11 +327,11 @@ function hmacDrbg<T>(asynchronous: boolean) { // HMAC-DRBG async
326327 const _e = 'drbg: tried 1000 values' ;
327328 if ( asynchronous ) { // asynchronous=true
328329 const h = ( ...b : Bytes [ ] ) => etc . hmacSha256Async ( k , v , ...b ) ; // hmac(k)(v, ...values)
329- const reseed = async ( seed = u8n ( ) ) => { // HMAC-DRBG reseed() function. Steps D-G
330- k = await h ( u8n ( [ 0x00 ] ) , seed ) ; // k = hmac(K || V || 0x00 || seed)
330+ const reseed = async ( seed = u8n ( 0 ) ) => { // HMAC-DRBG reseed() function. Steps D-G
331+ k = await h ( u8fr ( [ 0x00 ] ) , seed ) ; // k = hmac(K || V || 0x00 || seed)
331332 v = await h ( ) ; // v = hmac(K || V)
332333 if ( seed . length === 0 ) return ;
333- k = await h ( u8n ( [ 0x01 ] ) , seed ) ; // k = hmac(K || V || 0x01 || seed)
334+ k = await h ( u8fr ( [ 0x01 ] ) , seed ) ; // k = hmac(K || V || 0x01 || seed)
334335 v = await h ( ) ; // v = hmac(K || V)
335336 } ;
336337 const gen = async ( ) => { // HMAC-DRBG generate() function
@@ -352,11 +353,11 @@ function hmacDrbg<T>(asynchronous: boolean) { // HMAC-DRBG async
352353 if ( ! f ) err ( 'etc.hmacSha256Sync not set' ) ;
353354 return f ! ( k , v , ...b ) ; // hmac(k)(v, ...values)
354355 } ;
355- const reseed = ( seed = u8n ( ) ) => { // HMAC-DRBG reseed() function. Steps D-G
356- k = h ( u8n ( [ 0x00 ] ) , seed ) ; // k = hmac(k || v || 0x00 || seed)
356+ const reseed = ( seed = u8n ( 0 ) ) => { // HMAC-DRBG reseed() function. Steps D-G
357+ k = h ( u8fr ( [ 0x00 ] ) , seed ) ; // k = hmac(k || v || 0x00 || seed)
357358 v = h ( ) ; // v = hmac(k || v)
358359 if ( seed . length === 0 ) return ;
359- k = h ( u8n ( [ 0x01 ] ) , seed ) ; // k = hmac(k || v || 0x01 || seed)
360+ k = h ( u8fr ( [ 0x01 ] ) , seed ) ; // k = hmac(k || v || 0x01 || seed)
360361 v = h ( ) ; // v = hmac(k || v)
361362 } ;
362363 const gen = ( ) => { // HMAC-DRBG generate() function
0 commit comments