-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexpand.go
49 lines (40 loc) · 1.41 KB
/
expand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: MIT
//
// Copyright (C) 2024 Daniel Bourdrez. All Rights Reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree or at
// https://spdx.org/licenses/MIT.html
package hash2curve
import (
"crypto"
"errors"
"github.com/bytemare/hash"
"github.com/bytemare/hash2curve/internal"
)
const (
minLength = 0
recommendedMinLength = 16
)
var errZeroLenDST = errors.New("zero-length DST")
func checkDST(dst []byte) {
if len(dst) < recommendedMinLength {
if len(dst) == minLength {
panic(errZeroLenDST)
}
}
}
// ExpandXMD expands the input and dst using the given fixed length hash function.
// - dst MUST be non-nil, longer than 0 and lower than 256. It's recommended that DST at least 16 bytes long.
// - length must be a positive integer lower than 255 * (size of digest).
func ExpandXMD(id crypto.Hash, input, dst []byte, length uint) []byte {
checkDST(dst)
return internal.ExpandXMD(id, input, dst, length)
}
// ExpandXOF expands the input and dst using the given extendable output hash function.
// - dst MUST be non-nil and its length longer than 0. It's recommended that DST at least 16 bytes long.
// - length must be a positive integer higher than 32.
func ExpandXOF(ext *hash.ExtendableHash, input, dst []byte, length uint) []byte {
checkDST(dst)
return internal.ExpandXOF(ext, input, dst, length)
}