Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RSA AES key wrap mechanism parameters #166

Merged
merged 1 commit into from
Feb 3, 2023
Merged

Conversation

varder
Copy link
Contributor

@varder varder commented Jan 20, 2023

Mechanism implementation:
OP-TEE/optee_os#5647

pkcs11-spec-v3.1-cs01
6.1.23 RSA AES KEY WRAP

The RSA AES key wrap mechanism based on the RSA public-key cryptosystem and the AES key wrap mechanism. It supports single-part key wrapping and key unwrapping.

How to use:

params := &pkcs11.RSAAESKeyWrapParams{
	AESKeyBits: 256,
	OAEPParams: pkcs11.OAEPParams{
		HashAlg:    pkcs11.CKM_SHA256,
		MGF:        pkcs11.CKG_MGF1_SHA256,
		SourceType: pkcs11.CKZ_DATA_SPECIFIED,
	},
}
mechanism := []*pkcs11.Mechanism {
    pkcs11.NewMechanism(pkcs11.CKM_RSA_AES_KEY_WRAP, params)
}
unwrappedKey, err := ctx.UnwrapKey(session, mechanism, wrappingKeyObj,
                                   wrappedKey, unwrappedKeyAttributes)

@varder varder changed the title Add RSA AES KEY WRAP mechanism parameters Add RSA AES key wrap mechanism parameters Jan 20, 2023
@varder
Copy link
Contributor Author

varder commented Feb 2, 2023

Hi @miekg,
Could you please have a look at the PR

params.go Outdated
@@ -26,6 +26,11 @@ static inline void putECDH1PublicParams(CK_ECDH1_DERIVE_PARAMS_PTR params, CK_VO
params->pPublicData = pPublicData;
params->ulPublicDataLen = ulPublicDataLen;
}

static inline void putRsaAesKeyWrapParams(CK_RSA_AES_KEY_WRAP_PARAMS_PTR params, CK_VOID_PTR pOAEPParams)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static inline void putRsaAesKeyWrapParams(CK_RSA_AES_KEY_WRAP_PARAMS_PTR params, CK_VOID_PTR pOAEPParams)
static inline void putRSAAESKeyWrapParams(CK_RSA_AES_KEY_WRAP_PARAMS_PTR params, CK_VOID_PTR pOAEPParams)

to keep in-line with the usage of RSA and AES in this pkg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

params.go Outdated
@@ -188,3 +193,23 @@ func cECDH1DeriveParams(p *ECDH1DeriveParams, arena arena) ([]byte, arena) {

return memBytes(unsafe.Pointer(&params), unsafe.Sizeof(params)), arena
}

type RsaAesKeyWrapParams struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same: s/Rsa/RSA en for AES

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

params.go Outdated
OAEPParams OAEPParams
}

func cRsaAesKeyWrapParams(p *RsaAesKeyWrapParams, arena arena) ([]byte, arena) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@miekg
Copy link
Owner

miekg commented Feb 2, 2023

some style stuff, otherwise lgtm

pkcs11-spec-v3.1-cs01
6.1.23 RSA AES KEY WRAP

The RSA AES key wrap mechanism based on the RSA public-key
cryptosystem and the AES key wrap mechanism. It supports
single-part key wrapping and key unwrapping.

How to use:

params := &pkcs11.RSAAESKeyWrapParams{
	AESKeyBits: 256,
	OAEPParams: pkcs11.OAEPParams{
		HashAlg:    pkcs11.CKM_SHA256,
		MGF:        pkcs11.CKG_MGF1_SHA256,
		SourceType: pkcs11.CKZ_DATA_SPECIFIED,
	},
}
mechanism := []*pkcs11.Mechanism {
    pkcs11.NewMechanism(pkcs11.CKM_RSA_AES_KEY_WRAP, params)
}
unwrappedKey, err := ctx.UnwrapKey(session, mechanism, wrappingKeyObj,
                                   wrappedKey, unwrappedKeyAttributes)

Signed-off-by: Valerii Chubar <valerii_chubar@epam.com>
@miekg miekg merged commit e93055c into miekg:master Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants