Skip to content

Commit 7876821

Browse files
committed
chore: wip
chore: wip
1 parent 0841530 commit 7876821

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/mgf.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
* @author Chris Breuer
66
*/
77

8-
import { md } from './md'
8+
import { mgf1 } from './mgf1'
9+
import { sha1 } from './algorithms/hash/sha1'
910

10-
export const mgf = {
11-
mgf1: md.sha1.create().update('sha1').digest(),
11+
export interface MGF {
12+
mgf1: (seed: string, maskLen: number) => string
13+
}
14+
15+
export const mgf: MGF = {
16+
mgf1: (seed: string, maskLen: number) => mgf1.create(sha1.create()).generate(seed, maskLen)
1217
}

src/mgf1.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
* @author Chris Breuer
77
*/
88

9-
import { ByteBuffer } from './utils'
9+
import { ByteBuffer, ByteStringBuffer } from './utils'
1010

1111
interface MessageDigest {
1212
start: () => void
13-
update: (data: string) => void
14-
digest: () => string
13+
update: (data: string | ByteStringBuffer) => void
14+
digest: () => ByteStringBuffer
1515
digestLength: number
1616
}
1717

@@ -44,7 +44,7 @@ export function create(md: MessageDigest) {
4444
// b. Concatenate the hash of the seed mgfSeed and C to the octet string T:
4545
md.start()
4646
md.update(seed + c.getBytes())
47-
t.putBuffer(md.digest())
47+
t.putBuffer(new ByteBuffer(md.digest().getBytes()))
4848
}
4949

5050
// output the leading maskLen octets of T as the octet string mask
@@ -54,8 +54,8 @@ export function create(md: MessageDigest) {
5454
}
5555

5656
return {
57-
generate,
58-
}
57+
generate: generate
58+
} as { generate: (seed: string, maskLen: number) => string }
5959
}
6060

6161
export interface MGF1 {

0 commit comments

Comments
 (0)