r3178 - trunk/libmikey/keyagreement
xuan at minisip.org
xuan at minisip.org
Thu Feb 1 15:48:37 CET 2007
Author: xuan
Date: 2007-02-01 15:48:35 +0100 (Thu, 01 Feb 2007)
New Revision: 3178
Modified:
trunk/libmikey/keyagreement/KeyAgreement.cxx
Log:
* Fix for KeyAgreement when using G-D SC (it did not use the MIKEY-on-card functions in all places).
Modified: trunk/libmikey/keyagreement/KeyAgreement.cxx
===================================================================
--- trunk/libmikey/keyagreement/KeyAgreement.cxx 2007-02-01 14:23:28 UTC (rev 3177)
+++ trunk/libmikey/keyagreement/KeyAgreement.cxx 2007-02-01 14:48:35 UTC (rev 3178)
@@ -222,63 +222,68 @@
unsigned char * key, unsigned int keyLength ,
int type ){
- byte_t * label = new byte_t[4+4+1+randLengthValue];
-
- switch( type ){
- case KEY_DERIV_SALT:
- label[0] = 0x39;
- label[1] = 0xA2;
- label[2] = 0xC1;
- label[3] = 0x4B;
- break;
- case KEY_DERIV_TEK:
- label[0] = 0x2A;
- label[1] = 0xD0;
- label[2] = 0x1C;
- label[3] = 0x64;
- break;
- case KEY_DERIV_TRANS_ENCR:
- label[0] = 0x15;
- label[1] = 0x05;
- label[2] = 0x33;
- label[3] = 0xE1;
- break;
- case KEY_DERIV_TRANS_SALT:
- label[0] = 0x29;
- label[1] = 0xB8;
- label[2] = 0x89;
- label[3] = 0x16;
- break;
- case KEY_DERIV_TRANS_AUTH:
- label[0] = 0x2D;
- label[1] = 0x22;
- label[2] = 0xAC;
- label[3] = 0x75;
- break;
- case KEY_DERIV_ENCR:
- label[0] = 0x15;
- label[1] = 0x79;
- label[2] = 0x8C;
- label[3] = 0xEF;
- break;
- case KEY_DERIV_AUTH:
- label[0] = 0x1B;
- label[1] = 0x5C;
- label[2] = 0x79;
- label[3] = 0x73;
- break;
- }
+ if (dynamic_cast<SipSimSmartCardGD*>(*sim)){
+ SipSimSmartCardGD *gd=dynamic_cast<SipSimSmartCardGD*>(*sim);
+ gd->getKey(csId, csbIdValue, (byte_t*)randPtr, randLengthValue, key, keyLength, type);
+ }else{
+ byte_t * label = new byte_t[4+4+1+randLengthValue];
- label[4] = csId;
+ switch( type ){
+ case KEY_DERIV_SALT:
+ label[0] = 0x39;
+ label[1] = 0xA2;
+ label[2] = 0xC1;
+ label[3] = 0x4B;
+ break;
+ case KEY_DERIV_TEK:
+ label[0] = 0x2A;
+ label[1] = 0xD0;
+ label[2] = 0x1C;
+ label[3] = 0x64;
+ break;
+ case KEY_DERIV_TRANS_ENCR:
+ label[0] = 0x15;
+ label[1] = 0x05;
+ label[2] = 0x33;
+ label[3] = 0xE1;
+ break;
+ case KEY_DERIV_TRANS_SALT:
+ label[0] = 0x29;
+ label[1] = 0xB8;
+ label[2] = 0x89;
+ label[3] = 0x16;
+ break;
+ case KEY_DERIV_TRANS_AUTH:
+ label[0] = 0x2D;
+ label[1] = 0x22;
+ label[2] = 0xAC;
+ label[3] = 0x75;
+ break;
+ case KEY_DERIV_ENCR:
+ label[0] = 0x15;
+ label[1] = 0x79;
+ label[2] = 0x8C;
+ label[3] = 0xEF;
+ break;
+ case KEY_DERIV_AUTH:
+ label[0] = 0x1B;
+ label[1] = 0x5C;
+ label[2] = 0x79;
+ label[3] = 0x73;
+ break;
+ }
+
+ label[4] = csId;
+
+ label[5] = (unsigned char)((csbIdValue>>24) & 0xFF);
+ label[6] = (unsigned char)((csbIdValue>>16) & 0xFF);
+ label[7] = (unsigned char)((csbIdValue>>8) & 0xFF);
+ label[8] = (unsigned char)(csbIdValue & 0xFF);
+ memcpy( &label[9], randPtr, randLengthValue );
+ prf( inkey, inkeyLength, label, 9 + randLengthValue, key, keyLength );
- label[5] = (unsigned char)((csbIdValue>>24) & 0xFF);
- label[6] = (unsigned char)((csbIdValue>>16) & 0xFF);
- label[7] = (unsigned char)((csbIdValue>>8) & 0xFF);
- label[8] = (unsigned char)(csbIdValue & 0xFF);
- memcpy( &label[9], randPtr, randLengthValue );
- prf( inkey, inkeyLength, label, 9 + randLengthValue, key, keyLength );
-
- delete [] label;
+ delete [] label;
+ }
}
void KeyAgreement::genTek( unsigned char csId,
@@ -286,7 +291,7 @@
#ifdef SCSIM_SUPPORT
SipSimSmartCardGD *gdSim =dynamic_cast<SipSimSmartCardGD*>(*sim);
if (gdSim){
- gdSim->getTek(csId, csbIdValue, tgkPtr, tgkLengthValue, tek, tekLength);
+ gdSim->getKey(csId, csbIdValue, randPtr, randLengthValue, tek, tekLength, KEY_DERIV_TEK);
}else
#endif
keyDeriv( csId, csbIdValue, tgkPtr, tgkLengthValue, tek, tekLength, KEY_DERIV_TEK );
@@ -327,6 +332,9 @@
if( tgk ){
memcpy( this->tgkPtr, tgk, tgkLengthValue );
}
+ else if(sim){
+ Rand::randomize( this->tgkPtr, tgkLengthValue, sim );
+ }
else{
Rand::randomize( this->tgkPtr, tgkLengthValue );
}
More information about the Minisip-devel
mailing list