Skip to content

Commit 2f09a29

Browse files
committed
Use 'generator' parameter for picking generator for DH keys (rather than 'exp'). Change default value to 2.
2 is the default generator for openssl; the number is a mostly arbitrary choice, and smaller values are faster.
1 parent 2b86d68 commit 2f09a29

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

doc/luaossl.pdf

44 Bytes
Binary file not shown.

doc/luaossl.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ \section{Modules}
284284

285285
.bits & number:1024 & private key size \\
286286

287-
.exp & number:65537 & RSA or Diffie-Hellman exponent \\
287+
.exp & number:65537 & RSA exponent \\
288+
289+
.generator & number:2 & Diffie-Hellman generator \\
288290

289291
.dhparam & string & PEM encoded string with precomputed DH parameters \\
290292

src/openssl.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,6 +3212,7 @@ static int pk_new(lua_State *L) {
32123212
int type = EVP_PKEY_RSA;
32133213
unsigned bits = 1024;
32143214
unsigned exp = 65537;
3215+
int generator = 2;
32153216
int curve = NID_X9_62_prime192v1;
32163217
const char *id;
32173218
const char *dhparam = NULL;
@@ -3264,9 +3265,10 @@ static int pk_new(lua_State *L) {
32643265
bits = (unsigned)n;
32653266
}
32663267

3267-
if (loadfield(L, 1, "exp", LUA_TNUMBER, &n)) {
3268-
luaL_argcheck(L, n > 0 && n < UINT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n));
3269-
exp = (unsigned)n;
3268+
/* compat: DH used to use the 'exp' field for the generator */
3269+
if (loadfield(L, 1, "generator", LUA_TNUMBER, &n) || loadfield(L, 1, "exp", LUA_TNUMBER, &n)) {
3270+
luaL_argcheck(L, n > 0 && n <= INT_MAX, 1, lua_pushfstring(L, "%f: `exp' invalid", n));
3271+
generator = (int)n;
32703272
}
32713273
break;
32723274
case EVP_PKEY_EC:
@@ -3327,7 +3329,7 @@ static int pk_new(lua_State *L) {
33273329
BIO_free(bio);
33283330
if (!dh)
33293331
return auxL_error(L, auxL_EOPENSSL, "pkey.new");
3330-
} else if (!(dh = DH_generate_parameters(bits, exp, 0, 0)))
3332+
} else if (!(dh = DH_generate_parameters(bits, generator, 0, 0)))
33313333
return auxL_error(L, auxL_EOPENSSL, "pkey.new");
33323334

33333335

0 commit comments

Comments
 (0)