| 1 |
package jose |
| 2 |
|
| 3 |
func init() { |
| 4 |
RegisterJwa(&EcdhAesKW{ keySizeBits: 128, aesKW: &AesKW{ keySizeBits: 128}, ecdh: &Ecdh{directAgreement:false}}) |
| 5 |
RegisterJwa(&EcdhAesKW{ keySizeBits: 192, aesKW: &AesKW{ keySizeBits: 192}, ecdh: &Ecdh{directAgreement:false}}) |
| 6 |
RegisterJwa(&EcdhAesKW{ keySizeBits: 256, aesKW: &AesKW{ keySizeBits: 256}, ecdh: &Ecdh{directAgreement:false}}) |
| 7 |
} |
| 8 |
|
| 9 |
// Elliptic curve Diffie–Hellman with AES Key Wrap key management algorithm implementation |
| 10 |
type EcdhAesKW struct{ |
| 11 |
keySizeBits int |
| 12 |
aesKW JwaAlgorithm |
| 13 |
ecdh JwaAlgorithm |
| 14 |
} |
| 15 |
|
| 16 |
func (alg *EcdhAesKW) Name() string { |
| 17 |
switch alg.keySizeBits { |
| 18 |
case 128: return ECDH_ES_A128KW |
| 19 |
case 192: return ECDH_ES_A192KW |
| 20 |
default: return ECDH_ES_A256KW |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
func (alg *EcdhAesKW) WrapNewKey(cekSizeBits int, key interface{}, header map[string]interface{}) (cek []byte, encryptedCek []byte, err error) { |
| 25 |
var kek []byte |
| 26 |
|
| 27 |
if kek,_,err=alg.ecdh.WrapNewKey(alg.keySizeBits, key, header);err!=nil { |
| 28 |
return nil,nil,err |
| 29 |
} |
| 30 |
|
| 31 |
return alg.aesKW.WrapNewKey(cekSizeBits,kek,header) |
| 32 |
} |
| 33 |
|
| 34 |
func (alg *EcdhAesKW) Unwrap(encryptedCek []byte, key interface{}, cekSizeBits int, header map[string]interface{}) (cek []byte, err error) { |
| 35 |
var kek []byte |
| 36 |
|
| 37 |
if kek,err=alg.ecdh.Unwrap(nil, key, alg.keySizeBits, header);err!=nil { |
| 38 |
return nil,err |
| 39 |
} |
| 40 |
|
| 41 |
return alg.aesKW.Unwrap(encryptedCek,kek,cekSizeBits,header) |
| 42 |
} |