X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/74a94bd06358ca24b4a3a1acaa524c7235f38664..d7b6f0d1cda54fe872145ab6ee20bf5bc131be8d:/lib/basen.c diff --git a/lib/basen.c b/lib/basen.c index 69ab273..362ab58 100644 --- a/lib/basen.c +++ b/lib/basen.c @@ -25,7 +25,11 @@ #include "basen.h" -/* test whether v is 0 */ +/** @brief Test whether v is 0 + * @param v Pointer to bigendian bignum + * @param nwords Length of bignum + * @return !v + */ static int zero(const unsigned long *v, int nwords) { int n; @@ -34,7 +38,14 @@ static int zero(const unsigned long *v, int nwords) { return n == nwords; } -/* divide v by m returning the remainder */ +/** @brief Divide v by m returning the remainder. + * @param v Pointer to bigendian bignum + * @param nwords Length of bignum + * @param m Divisor (must not be 0) + * @return Remainder + * + * The quotient is stored in @p v. + */ static unsigned divide(unsigned long *v, int nwords, unsigned long m) { unsigned long r = 0, a, b; int n; @@ -54,6 +65,17 @@ static unsigned divide(unsigned long *v, int nwords, unsigned long m) { return r; } +/** @brief Convert v to a chosen base + * @param v Pointer to bigendian bignum + * @param nwords Length of bignum + * @param buffer Output buffer + * @param bufsize Size of output buffer + * @param base Number base (2..62) + * @return 0 on success, -1 if the buffer is too small + * + * Converts @p v to a string in the given base using decimal digits, lower case + * letter sand upper case letters as digits. + */ int basen(unsigned long *v, int nwords, char buffer[],