chiark / gitweb /
Fix bizarre `if (!consttime_memeq(X, Y, N)!=0)' idioms.
[secnet.git] / rsa.c
diff --git a/rsa.c b/rsa.c
index bdacfe99d120099009f9e24c3452f1e856069630..01d97c3e95533ced3757e716b38cb0dfc8476433 100644 (file)
--- a/rsa.c
+++ b/rsa.c
@@ -1,10 +1,34 @@
-/* This file is part of secnet, and is distributed under the terms of
-   the GNU General Public License version 2 or later.
+/*
+ * rsa.c: implementation of RSA with PKCS#1 padding
+ */
+/*
+ * This file is Free Software.  It was originally written for secnet.
+ *
+ * Copyright 1995-2003 Stephen Early
+ * Copyright 2002-2014 Ian Jackson
+ * Copyright 2001      Simon Tatham
+ * Copyright 2013      Mark Wooding
+ *
+ * You may redistribute secnet as a whole and/or modify it under the
+ * terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3, or (at your option) any
+ * later version.
+ *
+ * You may redistribute this file and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software
+ * Foundation; either version 2, or (at your option) any later
+ * version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, see
+ * https://www.gnu.org/licenses/gpl.html.
+ */
 
-   Copyright (C) 1995-2002 Stephen Early
-   Copyright (C) 2001 Simon Tatham
-   Copyright (C) 2002 Ian Jackson
-   */
 
 #include <stdio.h>
 #include <string.h>
@@ -124,8 +148,8 @@ static string_t rsa_sign(void *sst, uint8_t *data, int32_t datalen)
     mpz_init(&u);
     mpz_init(&v);
 
-    mpz_powm(&u, &a, &st->dp, &st->p);
-    mpz_powm(&v, &a, &st->dq, &st->q);
+    mpz_powm_sec(&u, &a, &st->dp, &st->p);
+    mpz_powm_sec(&v, &a, &st->dq, &st->q);
     mpz_sub(&tmp, &u, &v);
     mpz_mul(&tmp2, &tmp, &st->w);
     mpz_add(&tmp, &tmp2, &v);
@@ -268,7 +292,7 @@ static list_t *rsapriv_apply(closure_t *self, struct cloc loc, dict_t *context,
     i=list_elem(args,0);
     if (i) {
        if (i->type!=t_string) {
-           cfgfatal(i->loc,"rsa-public","first argument must be a string\n");
+           cfgfatal(i->loc,"rsa-private","first argument must be a string\n");
        }
        filename=i->data.string;
     } else {