Skip to content

Commit

Permalink
types: Add getMechanismParam
Browse files Browse the repository at this point in the history
Fixes build error triggered by miekg/pkcs11
40e115a85e0196984e45b254c509d74900738bb4
  • Loading branch information
JeremyRand committed Jun 20, 2021
1 parent 5dc27f5 commit 0a827eb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ static inline CK_VOID_PTR getAttributePval(CK_ATTRIBUTE_PTR a)
return a->pValue;
}
static inline CK_VOID_PTR getMechanismParam(CK_MECHANISM_PTR m)
{
return m->pParameter;
}
*/
import "C"

Expand Down Expand Up @@ -148,19 +153,19 @@ func toMechanism(pMechanism C.CK_MECHANISM_PTR) *pkcs11.Mechanism {
C.CKM_SHA384_RSA_PKCS_PSS, C.CKM_SHA512_RSA_PKCS_PSS,
C.CKM_SHA3_256_RSA_PKCS_PSS, C.CKM_SHA3_384_RSA_PKCS_PSS,
C.CKM_SHA3_512_RSA_PKCS_PSS, C.CKM_SHA3_224_RSA_PKCS_PSS:
pssParam := C.CK_RSA_PKCS_PSS_PARAMS_PTR(pMechanism.pParameter)
pssParam := C.CK_RSA_PKCS_PSS_PARAMS_PTR(C.getMechanismParam(pMechanism))
goHashAlg := uint(pssParam.hashAlg)
goMgf := uint(pssParam.mgf)
goSLen := uint(pssParam.sLen)
return pkcs11.NewMechanism(uint(pMechanism.mechanism), pkcs11.NewPSSParams(goHashAlg, goMgf, goSLen))
case C.CKM_AES_GCM:
gcmParam := C.CK_GCM_PARAMS_PTR(pMechanism.pParameter)
gcmParam := C.CK_GCM_PARAMS_PTR(C.getMechanismParam(pMechanism))
goIV := C.GoBytes(unsafe.Pointer(gcmParam.pIv), C.int(gcmParam.ulIvLen))
goAad := C.GoBytes(unsafe.Pointer(gcmParam.pAAD), C.int(gcmParam.ulAADLen))
goTag := int(gcmParam.ulTagBits)
return pkcs11.NewMechanism(uint(pMechanism.mechanism), pkcs11.NewGCMParams(goIV, goAad, goTag))
case C.CKM_RSA_PKCS_OAEP:
oaepParams := C.CK_RSA_PKCS_OAEP_PARAMS_PTR(pMechanism.pParameter)
oaepParams := C.CK_RSA_PKCS_OAEP_PARAMS_PTR(C.getMechanismParam(pMechanism))
goHashAlg := uint(oaepParams.hashAlg)
goMgf := uint(oaepParams.mgf)
goSourceType := uint(oaepParams.source)
Expand Down

0 comments on commit 0a827eb

Please sign in to comment.