X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshbn.c;h=0d64620da5c8728b59adf86e3334148cc76359bb;hb=a8c4e67ff9ebdced0a4fb393f934b22cb5aae02f;hp=b5c99125b2633645d83c06d28e842b8740fb5099;hpb=7d6bf4a6ca94cca24189c5a81c48d78cde407038;p=PuTTY.git diff --git a/sshbn.c b/sshbn.c index b5c99125..0d64620d 100644 --- a/sshbn.c +++ b/sshbn.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "misc.h" @@ -102,6 +103,7 @@ typedef BignumInt *Bignum; BignumInt bnZero[1] = { 0 }; BignumInt bnOne[2] = { 1, 1 }; +BignumInt bnTen[2] = { 1, 10 }; /* * The Bignum format is an array of `BignumInt'. The first @@ -117,7 +119,7 @@ BignumInt bnOne[2] = { 1, 1 }; * nonzero. */ -Bignum Zero = bnZero, One = bnOne; +Bignum Zero = bnZero, One = bnOne, Ten = bnTen; static Bignum newbn(int length) { @@ -1255,6 +1257,30 @@ Bignum bignum_from_bytes_le(const unsigned char *data, int nbytes) return result; } +Bignum bignum_from_decimal(const char *decimal) +{ + Bignum result = copybn(Zero); + + while (*decimal) { + Bignum tmp, tmp2; + + if (!isdigit((unsigned char)*decimal)) { + freebn(result); + return 0; + } + + tmp = bigmul(result, Ten); + tmp2 = bignum_from_long(*decimal - '0'); + result = bigadd(tmp, tmp2); + freebn(tmp); + freebn(tmp2); + + decimal++; + } + + return result; +} + Bignum bignum_random_in_range(const Bignum lower, const Bignum upper) { Bignum ret = NULL;