Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: mozilla/security/nss/lib/freebl/dh.c

Issue 10961060: Update NSS to NSS 3.14 Beta 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Add the NSS snapshot timestamp to README.chromium and nss-checkout.sh Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mozilla/security/nss/lib/freebl/blapit.h ('k') | mozilla/security/nss/lib/freebl/drbg.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mozilla/security/nss/lib/freebl/dh.c
===================================================================
--- mozilla/security/nss/lib/freebl/dh.c (revision 158129)
+++ mozilla/security/nss/lib/freebl/dh.c (working copy)
@@ -21,9 +21,28 @@
#include "mpprime.h"
#include "secmpi.h"
-#define DH_SECRET_KEY_LEN 20
#define KEA_DERIVED_SECRET_LEN 128
+/* Lengths are in bytes. */
+static unsigned int
+dh_GetSecretKeyLen(unsigned int primeLen)
+{
+ /* Based on Table 2 in NIST SP 800-57. */
+ if (primeLen >= 1920) { /* 15360 bits */
+ return 64; /* 512 bits */
+ }
+ if (primeLen >= 960) { /* 7680 bits */
+ return 48; /* 384 bits */
+ }
+ if (primeLen >= 384) { /* 3072 bits */
+ return 32; /* 256 bits */
+ }
+ if (primeLen >= 256) { /* 2048 bits */
+ return 28; /* 224 bits */
+ }
+ return 20; /* 160 bits */
+}
+
SECStatus
DH_GenParam(int primeLen, DHParams **params)
{
@@ -154,7 +173,8 @@
CHECK_SEC_OK( SECITEM_CopyItem(arena, &key->base, &params->base) );
SECITEM_TO_MPINT(key->base, &g);
/* Generate private key xa */
- SECITEM_AllocItem(arena, &key->privateValue, DH_SECRET_KEY_LEN);
+ SECITEM_AllocItem(arena, &key->privateValue,
+ dh_GetSecretKeyLen(params->prime.len));
RNG_GenerateGlobalRandomBytes(key->privateValue.data,
key->privateValue.len);
SECITEM_TO_MPINT( key->privateValue, &xa );
« no previous file with comments | « mozilla/security/nss/lib/freebl/blapit.h ('k') | mozilla/security/nss/lib/freebl/drbg.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698