Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/PuTTYNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2018-12-31 16:53:41 +0300
committerSimon Tatham <anakin@pobox.com>2018-12-31 17:54:59 +0300
commit25b034ee39f557cab6e6e7b79591ef46c72cba92 (patch)
tree4a746b1b3b0bef759920f07fe3e16e45fe957339 /sshpubk.c
parentd73a1716f603348739b55b953c3aaa0b86f0ffab (diff)
Complete rewrite of PuTTY's bignum library.
The old 'Bignum' data type is gone completely, and so is sshbn.c. In its place is a new thing called 'mp_int', handled by an entirely new library module mpint.c, with API differences both large and small. The main aim of this change is that the new library should be free of timing- and cache-related side channels. I've written the code so that it _should_ - assuming I haven't made any mistakes - do all of its work without either control flow or memory addressing depending on the data words of the input numbers. (Though, being an _arbitrary_ precision library, it does have to at least depend on the sizes of the numbers - but there's a 'formal' size that can vary separately from the actual magnitude of the represented integer, so if you want to keep it secret that your number is actually small, it should work fine to have a very long mp_int and just happen to store 23 in it.) So I've done all my conditionalisation by means of computing both answers and doing bit-masking to swap the right one into place, and all loops over the words of an mp_int go up to the formal size rather than the actual size. I haven't actually tested the constant-time property in any rigorous way yet (I'm still considering the best way to do it). But this code is surely at the very least a big improvement on the old version, even if I later find a few more things to fix. I've also completely rewritten the low-level elliptic curve arithmetic from sshecc.c; the new ecc.c is closer to being an adjunct of mpint.c than it is to the SSH end of the code. The new elliptic curve code keeps all coordinates in Montgomery-multiplication transformed form to speed up all the multiplications mod the same prime, and only converts them back when you ask for the affine coordinates. Also, I adopted extended coordinates for the Edwards curve implementation. sshecc.c has also had a near-total rewrite in the course of switching it over to the new system. While I was there, I've separated ECDSA and EdDSA more completely - they now have separate vtables, instead of a single vtable in which nearly every function had a big if statement in it - and also made the externally exposed types for an ECDSA key and an ECDH context different. A minor new feature: since the new arithmetic code includes a modular square root function, we can now support the compressed point representation for the NIST curves. We seem to have been getting along fine without that so far, but it seemed a shame not to put it in, since it was suddenly easy. In sshrsa.c, one major change is that I've removed the RSA blinding step in rsa_privkey_op, in which we randomise the ciphertext before doing the decryption. The purpose of that was to avoid timing leaks giving away the plaintext - but the new arithmetic code should take that in its stride in the course of also being careful enough to avoid leaking the _private key_, which RSA blinding had no way to do anything about in any case. Apart from those specific points, most of the rest of the changes are more or less mechanical, just changing type names and translating code into the new API.
Diffstat (limited to 'sshpubk.c')
-rw-r--r--sshpubk.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/sshpubk.c b/sshpubk.c
index 5072ff63..9a187b5c 100644
--- a/sshpubk.c
+++ b/sshpubk.c
@@ -10,6 +10,7 @@
#include <assert.h>
#include "putty.h"
+#include "mpint.h"
#include "ssh.h"
#include "misc.h"
@@ -276,11 +277,11 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
}
memset(&key, 0, sizeof(key));
- key.exponent = bignum_from_decimal(expp);
- key.modulus = bignum_from_decimal(modp);
- if (atoi(bitsp) != bignum_bitcount(key.modulus)) {
- freebn(key.exponent);
- freebn(key.modulus);
+ key.exponent = mp_from_decimal(expp);
+ key.modulus = mp_from_decimal(modp);
+ if (atoi(bitsp) != mp_get_nbits(key.modulus)) {
+ mp_free(key.exponent);
+ mp_free(key.modulus);
sfree(line);
error = "key bit count does not match in SSH-1 public key file";
goto end;
@@ -1360,10 +1361,9 @@ char *ssh1_pubkey_str(struct RSAKey *key)
char *buffer;
char *dec1, *dec2;
- dec1 = bignum_decimal(key->exponent);
- dec2 = bignum_decimal(key->modulus);
- buffer = dupprintf("%d %s %s%s%s", bignum_bitcount(key->modulus),
- dec1, dec2,
+ dec1 = mp_get_decimal(key->exponent);
+ dec2 = mp_get_decimal(key->modulus);
+ buffer = dupprintf("%zd %s %s%s%s", mp_get_nbits(key->modulus), dec1, dec2,
key->comment ? " " : "",
key->comment ? key->comment : "");
sfree(dec1);