[Git][NTPsec/ntpsec][master] 2 commits: Some u_long -> unsigned int changes.
Eric S. Raymond
gitlab at mg.gitlab.com
Fri Sep 23 11:28:25 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
906dbcdb by Eric S. Raymond at 2016-09-23T07:06:59-04:00
Some u_long -> unsigned int changes.
These are valid because the invention and major uses of u_long in this
codebase predate the 64-bit transition - it may look like we're
narrowing size from 64 to 32 bits, but what we're actually doing is
replacing an earlier hack for guaranteeing 32-bit size by people
who cut their teeth on 16-bit ints.
We might actually get a little optimization out of this, but the
real reason is to get rid of the obfuscatory typedef.
- - - - -
8bb29358 by Eric S. Raymond at 2016-09-23T07:26:12-04:00
Typedef cleansing - u_long to unsigned int, u_short to unsigned short.
As before, valid because these date from the 32-bit era. Resolves a very
old to-do item.
- - - - -
3 changed files:
- devel/TODO
- include/ntp_stdlib.h
- libntp/authkeys.c
Changes:
=====================================
devel/TODO
=====================================
--- a/devel/TODO
+++ b/devel/TODO
@@ -156,8 +156,6 @@ __________
== Old, sometime ancient stuff ==
-970711: Look Real Hard at changing the key stuff from u_long to u_int32.
-
970711: Make sure it's safe to convert proto_config's 2nd argument from
u_long to u_int32. Watch "set" in ntp_request.c:setclr_flags().
=====================================
include/ntp_stdlib.h
=====================================
--- a/include/ntp_stdlib.h
+++ b/include/ntp_stdlib.h
@@ -59,7 +59,7 @@ extern int authencrypt (keyid_t, uint32_t *, int);
extern int authhavekey (keyid_t);
extern int authistrusted (keyid_t);
extern bool authreadkeys (const char *);
-extern void authtrust (keyid_t, unsigned long);
+extern void authtrust (keyid_t, unsigned int);
extern bool authusekey (keyid_t, int, const uint8_t *);
/*
@@ -176,13 +176,13 @@ extern void rereadkeys (void);
*/
/* authkeys.c */
-extern unsigned long authkeynotfound; /* keys not found */
-extern unsigned long authkeylookups; /* calls to lookup keys */
-extern unsigned long authnumkeys; /* number of active keys */
-extern unsigned long authkeyexpired; /* key lifetime expirations */
-extern unsigned long authkeyuncached; /* cache misses */
-extern unsigned long authencryptions; /* calls to encrypt */
-extern unsigned long authdecryptions; /* calls to decrypt */
+extern unsigned int authkeynotfound; /* keys not found */
+extern unsigned int authkeylookups; /* calls to lookup keys */
+extern unsigned int authnumkeys; /* number of active keys */
+extern unsigned int authkeyexpired; /* key lifetime expirations */
+extern unsigned int authkeyuncached; /* cache misses */
+extern unsigned int authencryptions; /* calls to encrypt */
+extern unsigned int authdecryptions; /* calls to decrypt */
extern int authnumfreekeys;
=====================================
libntp/authkeys.c
=====================================
--- a/libntp/authkeys.c
+++ b/libntp/authkeys.c
@@ -23,11 +23,11 @@ struct savekey {
symkey * hlink; /* next in hash bucket */
DECL_DLIST_LINK(symkey, llink); /* for overall & free lists */
uint8_t * secret; /* shared secret */
- u_long lifetime; /* remaining lifetime */
+ unsigned int lifetime; /* remaining lifetime */
keyid_t keyid; /* key identifier */
- u_short type; /* OpenSSL digest NID */
- u_short secretsize; /* secret octets */
- u_short flags; /* KEY_ flags that wave */
+ unsigned short type; /* OpenSSL digest NID */
+ unsigned short secretsize; /* secret octets */
+ unsigned short flags; /* KEY_ flags that wave */
};
/* define the payload region of symkey beyond the list pointers */
@@ -46,10 +46,10 @@ struct symkey_alloc_tag {
symkey_alloc * authallocs;
#endif /* DEBUG */
-static inline u_short auth_log2(double x);
+static inline unsigned short auth_log2(double x);
static void auth_resize_hashtable(void);
-static void allocsymkey(symkey **, keyid_t, u_short,
- u_short, u_long, u_short, uint8_t *);
+static void allocsymkey(symkey **, keyid_t, unsigned short,
+ unsigned short, unsigned int, unsigned short, uint8_t *);
static void freesymkey(symkey *, symkey **);
#ifdef DEBUG
static void free_auth_mem(void);
@@ -62,18 +62,18 @@ symkey key_listhead; /* list of all in-use keys */
*/
#define KEYHASH(keyid) ((keyid) & authhashmask)
#define INIT_AUTHHASHSIZE 64
-u_short authhashbuckets = INIT_AUTHHASHSIZE;
-u_short authhashmask = INIT_AUTHHASHSIZE - 1;
+unsigned short authhashbuckets = INIT_AUTHHASHSIZE;
+unsigned short authhashmask = INIT_AUTHHASHSIZE - 1;
symkey **key_hash;
-u_long authkeynotfound; /* keys not found */
-u_long authkeylookups; /* calls to lookup keys */
-u_long authnumkeys; /* number of active keys */
-u_long authkeyexpired; /* key lifetime expirations */
-u_long authkeyuncached; /* cache misses */
-u_long authnokey; /* calls to encrypt with no key */
-u_long authencryptions; /* calls to encrypt */
-u_long authdecryptions; /* calls to decrypt */
+unsigned int authkeynotfound; /* keys not found */
+unsigned int authkeylookups; /* calls to lookup keys */
+unsigned int authnumkeys; /* number of active keys */
+unsigned int authkeyexpired; /* key lifetime expirations */
+unsigned int authkeyuncached; /* cache misses */
+unsigned int authnokey; /* calls to encrypt with no key */
+unsigned int authencryptions; /* calls to encrypt */
+unsigned int authdecryptions; /* calls to decrypt */
/*
* Storage for free symkey structures. We malloc() such things but
@@ -87,11 +87,11 @@ int authnumfreekeys;
/*
* The key cache. We cache the last key we looked at here.
*/
-keyid_t cache_keyid; /* key identifier */
-uint8_t *cache_secret; /* secret */
-u_short cache_secretsize; /* secret length */
-int cache_type; /* OpenSSL digest NID */
-u_short cache_flags; /* flags that wave */
+keyid_t cache_keyid; /* key identifier */
+uint8_t *cache_secret; /* secret */
+unsigned short cache_secretsize; /* secret length */
+int cache_type; /* OpenSSL digest NID */
+unsigned short cache_flags; /* flags that wave */
/*
@@ -205,10 +205,10 @@ auth_prealloc_symkeys(
}
-static inline u_short
+static inline unsigned short
auth_log2(double x)
{
- return (u_short)(log10(x) / log10(2));
+ return (unsigned short)(log10(x) / log10(2));
}
@@ -222,9 +222,9 @@ auth_log2(double x)
static void
auth_resize_hashtable(void)
{
- u_long totalkeys;
- u_short hashbits;
- u_short hash;
+ unsigned int totalkeys;
+ unsigned short hashbits;
+ unsigned short hash;
size_t newalloc;
symkey * sk;
@@ -258,10 +258,10 @@ static void
allocsymkey(
symkey ** bucket,
keyid_t id,
- u_short flags,
- u_short type,
- u_long lifetime,
- u_short secretsize,
+ unsigned short flags,
+ unsigned short type,
+ unsigned int lifetime,
+ unsigned short secretsize,
uint8_t * secret
)
{
@@ -419,12 +419,12 @@ authhavekey(
void
authtrust(
keyid_t id,
- u_long trust
+ unsigned int trust
)
{
symkey ** bucket;
symkey * sk;
- u_long lifetime;
+ unsigned int lifetime;
/*
* Search bin for key; if it does not exist and is untrusted,
@@ -530,9 +530,9 @@ MD5auth_setkey(
bucket = &key_hash[KEYHASH(keyno)];
for (sk = *bucket; sk != NULL; sk = sk->hlink) {
if (keyno == sk->keyid) {
- sk->type = (u_short)keytype;
+ sk->type = (unsigned short)keytype;
secretsize = len;
- sk->secretsize = (u_short)secretsize;
+ sk->secretsize = (unsigned short)secretsize;
free(sk->secret);
sk->secret = emalloc(secretsize);
memcpy(sk->secret, key, secretsize);
@@ -550,8 +550,8 @@ MD5auth_setkey(
secretsize = len;
secret = emalloc(secretsize);
memcpy(secret, key, secretsize);
- allocsymkey(bucket, keyno, 0, (u_short)keytype, 0,
- (u_short)secretsize, secret);
+ allocsymkey(bucket, keyno, 0, (unsigned short)keytype, 0,
+ (unsigned short)secretsize, secret);
#ifdef DEBUG
if (debug >= 4) {
size_t j;
@@ -609,7 +609,7 @@ auth_agekeys(void)
authkeyexpired++;
}
ITER_DLIST_END()
- DPRINTF(1, ("auth_agekeys: at %lu keys %lu expired %lu\n",
+ DPRINTF(1, ("auth_agekeys: at %lu keys %u expired %u\n",
current_time, authnumkeys, authkeyexpired));
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/fd68e6f562589ecf066f0913030f1f792d4ea9c8...8bb29358a9f92de689655a4db511bc29f9807517
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160923/01a943bb/attachment.html>
More information about the vc
mailing list