Skip to content

Commit

Permalink
Bug 1353724, fix key length calculation for PKCS#5 DES-EDE3-CBC-Pad, …
Browse files Browse the repository at this point in the history
…r=rrelyea
  • Loading branch information
ueno committed Apr 5, 2017
1 parent c546432 commit f367b94
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/pk11wrap/pk11pbe.c
Expand Up @@ -370,6 +370,13 @@ sec_pkcs5v2_key_length(SECAlgorithmID *algid, SECAlgorithmID *cipherAlgId)
length = sec_pkcs5v2_aes_key_length(cipherAlg);
} else if (p5_param.keyLength.data != NULL) {
length = DER_GetInteger(&p5_param.keyLength);
} else {
CK_MECHANISM_TYPE cipherMech;
cipherMech = PK11_AlgtagToMechanism(cipherAlg);
if (cipherMech == CKM_INVALID_MECHANISM) {
goto loser;
}
length = PK11_GetMaxKeyLength(cipherMech);
}

loser:
Expand Down
1 change: 1 addition & 0 deletions lib/pk11wrap/pk11priv.h
Expand Up @@ -106,6 +106,7 @@ CK_OBJECT_HANDLE PK11_FindObjectForCert(CERTCertificate *cert,
void *wincx, PK11SlotInfo **pSlot);
PK11SymKey *pk11_CopyToSlot(PK11SlotInfo *slot, CK_MECHANISM_TYPE type,
CK_ATTRIBUTE_TYPE operation, PK11SymKey *symKey);
unsigned int pk11_GetPredefinedKeyLength(CK_KEY_TYPE keyType);

/**********************************************************************
* Certs
Expand Down
8 changes: 8 additions & 0 deletions lib/pk11wrap/pk11slot.c
Expand Up @@ -2291,6 +2291,14 @@ PK11_GetMaxKeyLength(CK_MECHANISM_TYPE mechanism)
}
}
}

/* fallback to pk11_GetPredefinedKeyLength for fixed key size algorithms */
if (keyLength == 0) {
CK_KEY_TYPE keyType;
keyType = PK11_GetKeyType(mechanism, 0);
keyLength = pk11_GetPredefinedKeyLength(keyType);
}

if (le)
PK11_FreeSlotListElement(list, le);
if (freeit)
Expand Down

0 comments on commit f367b94

Please sign in to comment.