@@ -427,7 +427,7 @@ public HMACKey cmacKdf(KMPreSharedKey preSharedKey, byte[] label, short labelSta
427
427
short keyOutLen = n * 16 ;
428
428
//Convert Hmackey to AES Key as the algorithm is ALG_AES_CMAC_128.
429
429
KMHmacKey hmacKey = ((KMHmacKey ) preSharedKey );
430
- hmacKey .getKey (tmpArray , (short ) 0 );
430
+ hmacKey .hmacKey . getKey (tmpArray , (short ) 0 );
431
431
aesKeys [KEYSIZE_256_OFFSET ].setKey (tmpArray , (short ) 0 );
432
432
//Initialize the key derivation function.
433
433
kdf .init (aesKeys [KEYSIZE_256_OFFSET ], Signature .MODE_SIGN );
@@ -473,20 +473,20 @@ public short hmacSign(byte[] keyBuf, short keyStart, short keyLength,
473
473
@ Override
474
474
public short hmacSign (Object key ,
475
475
byte [] data , short dataStart , short dataLength , byte [] mac , short macStart ) {
476
- if (!(key instanceof KMHmacKey )) {
477
- KMException .throwIt (KMError .INVALID_ARGUMENT );
478
- }
479
- KMHmacKey hmacKey = (KMHmacKey ) key ;
480
- return hmacSign (hmacKey .getKey () , data , dataStart , dataLength , mac , macStart );
476
+ if (!(key instanceof KMHmacKey )) {
477
+ KMException .throwIt (KMError .INVALID_ARGUMENT );
478
+ }
479
+ KMHmacKey hmacKey = (KMHmacKey ) key ;
480
+ return hmacSign (hmacKey .hmacKey , data , dataStart , dataLength , mac , macStart );
481
481
}
482
482
483
483
@ Override
484
484
public short hmacKDF (KMMasterKey masterkey , byte [] data , short dataStart ,
485
485
short dataLength , byte [] signature , short signatureStart ) {
486
486
try {
487
487
KMAESKey aesKey = (KMAESKey ) masterkey ;
488
- short keyLen = (short ) (aesKey .getKeySizeBits () / 8 );
489
- aesKey .getKey (tmpArray , (short ) 0 );
488
+ short keyLen = (short ) (aesKey .aesKey . getSize () / 8 );
489
+ aesKey .aesKey . getKey (tmpArray , (short ) 0 );
490
490
return hmacSign (tmpArray , (short ) 0 , keyLen , data , dataStart , dataLength ,
491
491
signature , signatureStart );
492
492
} finally {
@@ -498,7 +498,7 @@ public short hmacKDF(KMMasterKey masterkey, byte[] data, short dataStart,
498
498
public boolean hmacVerify (KMComputedHmacKey key , byte [] data , short dataStart ,
499
499
short dataLength , byte [] mac , short macStart , short macLength ) {
500
500
KMHmacKey hmacKey = (KMHmacKey ) key ;
501
- hmacSignature .init (hmacKey .getKey () , Signature .MODE_VERIFY );
501
+ hmacSignature .init (hmacKey .hmacKey , Signature .MODE_VERIFY );
502
502
return hmacSignature .verify (data , dataStart , dataLength , mac , macStart ,
503
503
macLength );
504
504
}
@@ -602,7 +602,7 @@ public KMOperation createSymmetricCipher(short alg, short purpose, short macLeng
602
602
}
603
603
// Get the KeyObject from the operation and update the key with the secret key material.
604
604
KMKeyObject keyObj = operation .getKeyObject ();
605
- Key key = (Key )keyObj .getKeyObjectInstance () ;
605
+ Key key = (Key )keyObj .keyObjectInst ;
606
606
switch (secretLength ) {
607
607
case 32 :
608
608
case 16 :
@@ -634,7 +634,7 @@ public KMOperation createHmacSignerVerifier(short purpose, short digest,
634
634
}
635
635
// Get the KeyObject from the operation and update the key with the secret key material.
636
636
KMKeyObject keyObj = operation .getKeyObject ();
637
- HMACKey key = (HMACKey )keyObj .getKeyObjectInstance () ;
637
+ HMACKey key = (HMACKey )keyObj .keyObjectInst ;
638
638
key .setKey (secret , secretStart , secretLength );
639
639
((KMOperationImpl ) operation ).init (key , digest , null , (short ) 0 , (short ) 0 );
640
640
return operation ;
@@ -649,7 +649,7 @@ private KMOperation createHmacSignerVerifier(short purpose, short digest, HMACKe
649
649
KMType .HMAC , KMType .INVALID_VALUE , KMType .INVALID_VALUE , KMType .INVALID_VALUE , (short )0 , isTrustedConf );
650
650
// Get the KeyObject from the operation and update the key with the secret key material.
651
651
KMKeyObject keyObj = operation .getKeyObject ();
652
- HMACKey key = (HMACKey )keyObj .getKeyObjectInstance () ;
652
+ HMACKey key = (HMACKey )keyObj .keyObjectInst ;
653
653
short len = hmacKey .getKey (tmpArray , (short ) 0 );
654
654
key .setKey (tmpArray , (short ) 0 , len );
655
655
((KMOperationImpl ) operation ).init (key , digest , null , (short ) 0 , (short ) 0 );
@@ -716,8 +716,8 @@ public KMOperation initSymmetricOperation(byte purpose, byte alg, byte digest, b
716
716
switch (interfaceType ) {
717
717
case KMDataStoreConstants .INTERFACE_TYPE_MASTER_KEY :
718
718
KMAESKey aesKey = (KMAESKey ) key ;
719
- keyLen = (short ) (aesKey .getKeySizeBits () / 8 );
720
- aesKey .getKey (tmpArray , (short ) 0 );
719
+ keyLen = (short ) (aesKey .aesKey . getSize () / 8 );
720
+ aesKey .aesKey . getKey (tmpArray , (short ) 0 );
721
721
break ;
722
722
723
723
default :
@@ -743,7 +743,7 @@ public KMOperation initSymmetricOperation(byte purpose, byte alg, byte digest, b
743
743
@ Override
744
744
public KMOperation initTrustedConfirmationSymmetricOperation (KMComputedHmacKey computedHmacKey ) {
745
745
KMHmacKey key = (KMHmacKey ) computedHmacKey ;
746
- return createHmacSignerVerifier (KMType .VERIFY , KMType .SHA2_256 , key .getKey () , true );
746
+ return createHmacSignerVerifier (KMType .VERIFY , KMType .SHA2_256 , key .hmacKey , true );
747
747
}
748
748
749
749
public KMOperation createRsaSigner (short digest , short padding , byte [] secret ,
@@ -754,7 +754,7 @@ public KMOperation createRsaSigner(short digest, short padding, byte[] secret,
754
754
KMType .INVALID_VALUE , KMType .INVALID_VALUE , secretLength , false );
755
755
// Get the KeyObject from the operation and update the key with the secret key material.
756
756
KMKeyObject keyObj = operation .getKeyObject ();
757
- RSAPrivateKey key = (RSAPrivateKey )((KeyPair )(keyObj .getKeyObjectInstance () )).getPrivate ();
757
+ RSAPrivateKey key = (RSAPrivateKey )((KeyPair )(keyObj .keyObjectInst )).getPrivate ();
758
758
key .setExponent (secret , secretStart , secretLength );
759
759
key .setModulus (modBuffer , modOff , modLength );
760
760
((KMOperationImpl ) operation ).init (key , digest , null , (short ) 0 , (short ) 0 );
@@ -769,7 +769,7 @@ public KMOperation createRsaDecipher(short padding, short mgfDigest, byte[] secr
769
769
KMType .INVALID_VALUE , KMType .INVALID_VALUE , secretLength , false );
770
770
// Get the KeyObject from the operation and update the key with the secret key material.
771
771
KMKeyObject keyObj = operation .getKeyObject ();
772
- RSAPrivateKey key = (RSAPrivateKey ) ((KeyPair )(keyObj .getKeyObjectInstance () )).getPrivate ();
772
+ RSAPrivateKey key = (RSAPrivateKey ) ((KeyPair )(keyObj .keyObjectInst )).getPrivate ();
773
773
key .setExponent (secret , secretStart , secretLength );
774
774
key .setModulus (modBuffer , modOff , modLength );
775
775
((KMOperationImpl ) operation ).init (key , KMType .INVALID_VALUE , null , (short ) 0 , (short ) 0 );
@@ -783,7 +783,7 @@ public KMOperation createEcSigner(short digest, byte[] secret,
783
783
.getOperationImpl (KMType .SIGN , alg , KMType .EC , KMType .INVALID_VALUE ,
784
784
KMType .INVALID_VALUE , KMType .INVALID_VALUE , secretLength , false );
785
785
KMKeyObject keyObj = operation .getKeyObject ();
786
- ECPrivateKey key = (ECPrivateKey ) ((KeyPair )(keyObj .getKeyObjectInstance () )).getPrivate ();
786
+ ECPrivateKey key = (ECPrivateKey ) ((KeyPair )(keyObj .keyObjectInst )).getPrivate ();
787
787
key .setS (secret , secretStart , secretLength );
788
788
((KMOperationImpl ) operation ).init (key , digest , null , (short ) 0 , (short ) 0 );
789
789
return operation ;
@@ -795,7 +795,7 @@ public KMOperation createKeyAgreement(byte[] secret, short secretStart,
795
795
.getOperationImpl (KMType .AGREE_KEY , KeyAgreement .ALG_EC_SVDP_DH_PLAIN ,
796
796
KMType .EC , KMType .INVALID_VALUE , KMType .INVALID_VALUE , KMType .INVALID_VALUE , (short )0 , false );
797
797
KMKeyObject keyObj = operation .getKeyObject ();
798
- ECPrivateKey key = (ECPrivateKey ) ((KeyPair )(keyObj .getKeyObjectInstance () )).getPrivate ();
798
+ ECPrivateKey key = (ECPrivateKey ) ((KeyPair )(keyObj .keyObjectInst )).getPrivate ();
799
799
key .setS (secret , secretStart , secretLength );
800
800
((KMOperationImpl ) operation ).init (key , KMType .INVALID_VALUE , null , (short ) 0 , (short ) 0 );
801
801
return operation ;
@@ -864,7 +864,7 @@ public KMMasterKey createMasterKey(KMMasterKey masterKey, short keySizeBits) {
864
864
masterKey = new KMAESKey (key );
865
865
short keyLen = (short ) (keySizeBits / 8 );
866
866
getTrueRandomNumber (tmpArray , (short ) 0 , keyLen );
867
- ((KMAESKey )masterKey ).setKey (tmpArray , (short ) 0 );
867
+ ((KMAESKey )masterKey ).aesKey . setKey (tmpArray , (short ) 0 );
868
868
}
869
869
return (KMMasterKey ) masterKey ;
870
870
} finally {
@@ -883,7 +883,7 @@ public KMPreSharedKey createPreSharedKey(KMPreSharedKey preSharedKey, byte[] key
883
883
false );
884
884
preSharedKey = new KMHmacKey (key );
885
885
}
886
- ((KMHmacKey )preSharedKey ).setKey (keyData , offset , length );
886
+ ((KMHmacKey )preSharedKey ).hmacKey . setKey (keyData , offset , length );
887
887
return (KMPreSharedKey ) preSharedKey ;
888
888
}
889
889
@@ -897,7 +897,7 @@ public KMComputedHmacKey createComputedHmacKey(KMComputedHmacKey computedHmacKey
897
897
false );
898
898
computedHmacKey = new KMHmacKey (key );
899
899
}
900
- ((KMHmacKey )computedHmacKey ).setKey (keyData , offset , length );
900
+ ((KMHmacKey )computedHmacKey ).hmacKey . setKey (keyData , offset , length );
901
901
return (KMComputedHmacKey ) computedHmacKey ;
902
902
}
903
903
@@ -933,7 +933,7 @@ public short ecSign256(KMAttestationKey ecPrivKey, byte[] inputDataBuf, short in
933
933
934
934
signer = Signature .OneShot .open (MessageDigest .ALG_SHA_256 ,
935
935
Signature .SIG_CIPHER_ECDSA , Cipher .PAD_NULL );
936
- signer .init (((KMECPrivateKey ) ecPrivKey ).getPrivateKey (), Signature .MODE_SIGN );
936
+ signer .init (((KMECPrivateKey ) ecPrivKey ).ecKeyPair . getPrivate (), Signature .MODE_SIGN );
937
937
return signer .sign (inputDataBuf , inputDataStart , inputDataLength ,
938
938
outputDataBuf , outputDataStart );
939
939
} finally {
@@ -1071,7 +1071,7 @@ public short ecSign256(KMDeviceUniqueKeyPair ecPrivKey, byte[] inputDataBuf,
1071
1071
try {
1072
1072
signer = Signature .OneShot .open (MessageDigest .ALG_SHA_256 ,
1073
1073
Signature .SIG_CIPHER_ECDSA , Cipher .PAD_NULL );
1074
- signer .init (((KMECDeviceUniqueKey ) ecPrivKey ).getPrivateKey (), Signature .MODE_SIGN );
1074
+ signer .init (((KMECDeviceUniqueKey ) ecPrivKey ).ecKeyPair . getPrivate (), Signature .MODE_SIGN );
1075
1075
return signer .sign (inputDataBuf , inputDataStart , inputDataLength ,
1076
1076
outputDataBuf , outputDataStart );
1077
1077
} finally {
@@ -1090,8 +1090,10 @@ public KMDeviceUniqueKeyPair createRkpDeviceUniqueKeyPair(KMDeviceUniqueKeyPair
1090
1090
poolMgr .initECKey (ecKeyPair );
1091
1091
key = new KMECDeviceUniqueKey (ecKeyPair );
1092
1092
}
1093
- ((KMECDeviceUniqueKey ) key ).setS (privKey , privKeyOff , privKeyLen );
1094
- ((KMECDeviceUniqueKey ) key ).setW (pubKey , pubKeyOff , pubKeyLen );
1093
+ ECPrivateKey ecKeyPair = (ECPrivateKey ) ((KMECDeviceUniqueKey ) key ).ecKeyPair .getPrivate ();
1094
+ ECPublicKey ecPublicKey = (ECPublicKey ) ((KMECDeviceUniqueKey ) key ).ecKeyPair .getPublic ();
1095
+ ecKeyPair .setS (privKey , privKeyOff , privKeyLen );
1096
+ ecPublicKey .setW (pubKey , pubKeyOff , pubKeyLen );
1095
1097
return (KMDeviceUniqueKeyPair ) key ;
1096
1098
}
1097
1099
@@ -1103,7 +1105,7 @@ public KMRkpMacKey createRkpMacKey(KMRkpMacKey rkpMacKey, byte[] keyData,
1103
1105
false );
1104
1106
rkpMacKey = new KMHmacKey (key );
1105
1107
}
1106
- ((KMHmacKey ) rkpMacKey ).setKey (keyData , offset , length );
1108
+ ((KMHmacKey ) rkpMacKey ).hmacKey . setKey (keyData , offset , length );
1107
1109
return rkpMacKey ;
1108
1110
}
1109
1111
0 commit comments