diff options
author | David Phillips <david@yeah.nah.nz> | 2019-03-11 17:40:01 +1300 |
---|---|---|
committer | David Phillips <david@yeah.nah.nz> | 2019-03-11 17:40:01 +1300 |
commit | 2b2ad2c10770c6a864f3ada1e2803ed72c8dfa1b (patch) | |
tree | 7c1f729554d45bc6998fd869e4164b7728988a56 | |
parent | 98bc6a685212cb6c8a3fd853545352da8f30549f (diff) | |
download | sand-leek-2b2ad2c10770c6a864f3ada1e2803ed72c8dfa1b.tar.xz |
Move comments to headers where applicable
-rw-r--r-- | key_update.c | 7 | ||||
-rw-r--r-- | key_update.h | 3 | ||||
-rw-r--r-- | onion_base32.c | 14 | ||||
-rw-r--r-- | onion_base32.h | 14 | ||||
-rw-r--r-- | unit_label.c | 20 | ||||
-rw-r--r-- | unit_label.h | 21 |
6 files changed, 40 insertions, 39 deletions
diff --git a/key_update.c b/key_update.c index 87acafb..493b32d 100644 --- a/key_update.c +++ b/key_update.c @@ -2,9 +2,7 @@ #include <openssl/rsa.h> #if OPENSSL_VERSION_NUMBER >= 0x10100000L -/* re-calculate the decryption key `d` for the given key - * the product of e and d must be congruent to 1, and since we are messing - * with e to generate our keys, we must re-calculate d */ + int key_update_d(RSA *rsa_key) { const BIGNUM *p = NULL; @@ -66,9 +64,6 @@ key_update_d(RSA *rsa_key) { #else -/* re-calculate the decryption key `d` for the given key - * the product of e and d must be congruent to 1, and since we are messing - * with e to generate our keys, we must re-calculate d */ int key_update_d(RSA *rsa_key) { BIGNUM *gcd = BN_new(); diff --git a/key_update.h b/key_update.h index 66512b6..ff6271d 100644 --- a/key_update.h +++ b/key_update.h @@ -1,3 +1,6 @@ #include <openssl/rsa.h> +/* re-calculate the decryption key `d` for the given key + * the product of e and d must be congruent to 1, and since we are messing + * with e to generate our keys, we must re-calculate d */ int key_update_d(RSA *rsa_key); diff --git a/onion_base32.c b/onion_base32.c index 701b302..53c6404 100644 --- a/onion_base32.c +++ b/onion_base32.c @@ -3,11 +3,6 @@ static const char base32_lookup[] = "abcdefghijklmnopqrstuvwxyz234567"; -/* Find the first instance of a character in `subject` which is not in the - * base32 alphabet. - * Returns the offset into `subject` of the first such character, or -1 - * if no such character exists in the string - */ int check_base32(char *subject) { size_t offset = 0; @@ -18,11 +13,6 @@ check_base32(char *subject) { return -1; } -/* Simple and reliable base32 algorithm - "old trusty" - * Note: This is not a general base32 algorithm; it outputs only the - * first 16 base32 symbols of the input buffer, using only the first - * 20 bytes of that buffer. - */ void onion_base32(char output[16], unsigned char sum[20]) { size_t c = 0; @@ -43,7 +33,7 @@ onion_base32(char output[16], unsigned char sum[20]) { /* Helper function for onion_base32_dec. Decodes a single base32 character * into its binary equivalent */ -unsigned char +static unsigned char base32_dec_single(char b) { if (b >= 'a' && b <= 'z') return b - 'a'; @@ -53,8 +43,6 @@ base32_dec_single(char b) { return 0; } -/* Simple algorithm to decode a 16-byte base32 sequence to the 10 bytes - * it represents, placing the result in dec */ void onion_base32_dec(unsigned char dec[10], char base32[16]) { diff --git a/onion_base32.h b/onion_base32.h index 854c6f9..3ed2bf7 100644 --- a/onion_base32.h +++ b/onion_base32.h @@ -1,3 +1,17 @@ +/* Find the first instance of a character in `subject` which is not in the + * base32 alphabet. + * Returns the offset into `subject` of the first such character, or -1 + * if no such character exists in the string + */ int check_base32(char *); + +/* Simple and reliable base32 algorithm - "old trusty" + * Note: This is not a general base32 algorithm; it outputs only the + * first 16 base32 symbols of the input buffer, using only the first + * 20 bytes of that buffer. + */ void onion_base32(char [16], unsigned char (*)); + +/* Simple algorithm to decode a 16-byte base32 sequence to the 10 bytes + * it represents, placing the result in dec */ void onion_base32_dec(unsigned char [10], char[16]); diff --git a/unit_label.c b/unit_label.c index 8b7f352..276be91 100644 --- a/unit_label.c +++ b/unit_label.c @@ -2,26 +2,6 @@ #include "unit_label.h" -/* Assign *unit a unit string from table unit_label that best fits value. - * returns the value reduced by the chosen unit's magnitude - * - * Tables are worked through in order, stopping at an entry with a falsey - * label. While the value is larger than the current unit's maximum count, - * the value is divided by this count and the next unit in the table is - * examined. Example: - * {100, "flooby" }, - * {500, "glargle"}, - * { 30, "lafplop"}, // Can be any non-zero count - * { 0, NULL } // Can be any count - * - * Given this table is in `labels`, - * ret1 = make_unit_whatsit(labels, &unit1, 150); - * ret2 = make_unit_whatsit(labels, &unit2, 50); - * ret3 = make_unit_whatsit(labels, &unit3, 55000); - * leaves ret1 as 1.5 and unit1 as "gargle", - * leaves ret2 as 50 and unit2 as "flooby", - * leaves ret3 as 1.1 and unit3 as "lafplop", - */ double make_unit_whatsit(const struct unit_label l[], char **unit, double value) { size_t i = 0; diff --git a/unit_label.h b/unit_label.h index 8f6220c..286407b 100644 --- a/unit_label.h +++ b/unit_label.h @@ -1,3 +1,4 @@ +/* struct representing a single row in the unit table mentioned above */ struct unit_label { /* number of times this unit fits into the immediate larger one */ double count; @@ -6,4 +7,24 @@ struct unit_label { char *label; }; +/* Assign *unit a unit string from table unit_label that best fits value. + * returns the value reduced by the chosen unit's magnitude + * + * Tables are worked through in order, stopping at an entry with a falsey + * label. While the value is larger than the current unit's maximum count, + * the value is divided by this count and the next unit in the table is + * examined. Example: + * {100, "flooby" }, + * {500, "glargle"}, + * { 30, "lafplop"}, // Can be any non-zero count + * { 0, NULL } // Can be any count + * + * Given this table is in `labels`, + * ret1 = make_unit_whatsit(labels, &unit1, 150); + * ret2 = make_unit_whatsit(labels, &unit2, 50); + * ret3 = make_unit_whatsit(labels, &unit3, 55000); + * leaves ret1 as 1.5 and unit1 as "gargle", + * leaves ret2 as 50 and unit2 as "flooby", + * leaves ret3 as 1.1 and unit3 as "lafplop", + */ double make_unit_whatsit(const struct unit_label l[], char **unit, double value); |