vault/sdk/helper/keysutil/consts.go
Alexander Scheel 961e76ae35
Add support for PKCSv1_5_NoOID signatures (#17636)
* Add support for PKCSv1_5_NoOID signatures

This assumes a pre-hashed input has been provided to Vault, but we do
not write the hash's OID into the signature stream. This allows us to
generate the alternative PKCSv1_5_NoOID signature type rather than the
existing PKCSv1_5_DERnull signature type we presently use.

These are specified in RFC 3447 Section 9.2.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add changelog

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Exclude new none type from PSS based tests

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add tests for PKCS#1v1.5 signatures

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
2022-10-27 08:26:20 -04:00

81 lines
1.6 KiB
Go

package keysutil
import (
"crypto"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"hash"
"golang.org/x/crypto/sha3"
)
type HashType uint32
const (
HashTypeNone HashType = iota
HashTypeSHA1
HashTypeSHA2224
HashTypeSHA2256
HashTypeSHA2384
HashTypeSHA2512
HashTypeSHA3224
HashTypeSHA3256
HashTypeSHA3384
HashTypeSHA3512
)
type MarshalingType uint32
const (
_ = iota
MarshalingTypeASN1 MarshalingType = iota
MarshalingTypeJWS
)
var (
HashTypeMap = map[string]HashType{
"none": HashTypeNone,
"sha1": HashTypeSHA1,
"sha2-224": HashTypeSHA2224,
"sha2-256": HashTypeSHA2256,
"sha2-384": HashTypeSHA2384,
"sha2-512": HashTypeSHA2512,
"sha3-224": HashTypeSHA3224,
"sha3-256": HashTypeSHA3256,
"sha3-384": HashTypeSHA3384,
"sha3-512": HashTypeSHA3512,
}
HashFuncMap = map[HashType]func() hash.Hash{
HashTypeNone: nil,
HashTypeSHA1: sha1.New,
HashTypeSHA2224: sha256.New224,
HashTypeSHA2256: sha256.New,
HashTypeSHA2384: sha512.New384,
HashTypeSHA2512: sha512.New,
HashTypeSHA3224: sha3.New224,
HashTypeSHA3256: sha3.New256,
HashTypeSHA3384: sha3.New384,
HashTypeSHA3512: sha3.New512,
}
CryptoHashMap = map[HashType]crypto.Hash{
HashTypeNone: 0,
HashTypeSHA1: crypto.SHA1,
HashTypeSHA2224: crypto.SHA224,
HashTypeSHA2256: crypto.SHA256,
HashTypeSHA2384: crypto.SHA384,
HashTypeSHA2512: crypto.SHA512,
HashTypeSHA3224: crypto.SHA3_224,
HashTypeSHA3256: crypto.SHA3_256,
HashTypeSHA3384: crypto.SHA3_384,
HashTypeSHA3512: crypto.SHA3_512,
}
MarshalingTypeMap = map[string]MarshalingType{
"asn1": MarshalingTypeASN1,
"jws": MarshalingTypeJWS,
}
)