* authentic) or else 0 (not authentic).
*/
int
-auth_md5 (
- char *pkt_data,
- int mac_size,
- struct key *cmp_key
- )
+auth_md5(
+ char *pkt_data,
+ int mac_size,
+ struct key *cmp_key
+ )
{
register int a;
char digest[16];
MD5_CTX ctx;
+ char *digest_data;
- if(cmp_key->type != 'M')
+ if (cmp_key->type != 'M')
return -1;
MD5Init(&ctx);
- char *digest_data = (char *) emalloc(sizeof(char) * (LEN_PKT_NOMAC + cmp_key->key_len));
+ digest_data = emalloc(sizeof(char) * (LEN_PKT_NOMAC + cmp_key->key_len));
- for(a=0; a<LEN_PKT_NOMAC; a++)
+ for (a = 0; a < LEN_PKT_NOMAC; a++)
digest_data[a] = pkt_data[a];
- for(a=0; a<cmp_key->key_len; a++)
+ for (a = 0; a < cmp_key->key_len; a++)
digest_data[LEN_PKT_NOMAC + a] = cmp_key->key_seq[a];
- MD5Update(&ctx, (unsigned char *)digest_data, LEN_PKT_NOMAC + cmp_key->key_len);
- MD5Final((unsigned char *)digest, &ctx);
+ MD5Update(&ctx, (u_char *)digest_data, LEN_PKT_NOMAC + cmp_key->key_len);
+ MD5Final((u_char *)digest, &ctx);
free(digest_data);
- for(a=0; a<16; a++)
- if(digest[a] != pkt_data[LEN_PKT_MAC + a])
+ for (a = 0; a < 16; a++)
+ if (digest[a] != pkt_data[LEN_PKT_MAC + a])
return 0;
return 1;
* number of keys it read
*/
int
-auth_init (
- const char *keyfile,
- struct key **keys
- )
+auth_init(
+ const char *keyfile,
+ struct key **keys
+ )
{
FILE *keyf = fopen(keyfile, "r");
struct key *prev = NULL;
-
register int a, line_limit;
int scan_cnt, line_cnt = 0;
char kbuf[96];
- if(keyf == NULL) {
- if(ENABLED_OPT(NORMALVERBOSE))
+ if (keyf == NULL) {
+ if (ENABLED_OPT(NORMALVERBOSE))
printf("sntp auth_init: Couldn't open key file %s for reading!\n", keyfile);
return -1;
line_cnt = 0;
- if(feof(keyf)) {
- if(ENABLED_OPT(NORMALVERBOSE))
+ if (feof(keyf)) {
+ if (ENABLED_OPT(NORMALVERBOSE))
printf("sntp auth_init: Key file %s is empty!\n", keyfile);
fclose(keyf);
return -1;
}
-
- while(!feof(keyf)) {
- struct key *act = (struct key *) emalloc(sizeof(struct key));
+ while (!feof(keyf)) {
+ struct key *act = emalloc(sizeof(struct key));
line_limit = 0;
fgets(kbuf, sizeof(kbuf), keyf);
- for(a=0; a<strlen(kbuf) && a < sizeof(kbuf); a++) {
- if(kbuf[a] == '#') {
+ for (a = 0; a < strlen(kbuf) && a < sizeof(kbuf); a++) {
+ if (kbuf[a] == '#') {
line_limit = a;
break;
}
}
- if(line_limit != 0)
+ if (line_limit != 0)
kbuf[line_limit] = '\0';
#ifdef DEBUG
#endif
- if((scan_cnt = sscanf(kbuf, "%i %c %16s", &act->key_id, &act->type, act->key_seq)) == 3) {
+ if ((scan_cnt = sscanf(kbuf, "%i %c %16s", &act->key_id, &act->type, act->key_seq)) == 3) {
act->key_len = strlen(act->key_seq);
act->next = NULL;
#ifdef DEBUG
printf("sntp auth_init: key_id %i type %c with key %s\n", act->key_id, act->type, act->key_seq);
#endif
- }
- else {
+ } else {
#ifdef DEBUG
printf("sntp auth_init: scanf read %i items, doesn't look good, skipping line %i.\n", scan_cnt, line_cnt);
#endif
STDLINE
printf("sntp auth_init: Read %i keys from file %s:\n", line_cnt, keyfile);
- struct key *kptr = *keys;
- for(a=0; a<key_cnt; a++) {
- printf("key_id %i type %c with key %s (key length: %i)\n", kptr->key_id,
- kptr->type, kptr->key_seq, kptr->key_len);
- kptr = kptr->next;
+ {
+ struct key *kptr = *keys;
+
+ for (a = 0; a < key_cnt; a++) {
+ printf("key_id %i type %c with key %s (key length: %i)\n",
+ kptr->key_id, kptr->type, kptr->key_seq, kptr->key_len);
+ kptr = kptr->next;
+ }
}
STDLINE
#endif
* address of the key. If no matching key is found the pointer is not touched.
*/
void
-get_key (
- int key_id,
- struct key **d_key
- )
+get_key(
+ int key_id,
+ struct key **d_key
+ )
{
register int a;
struct key *itr_key = key_ptr;
- if(key_cnt == 0)
+ if (key_cnt == 0)
return;
- for(a=0; a<key_cnt && itr_key != NULL; a++) {
- if(itr_key->key_id == key_id) {
+ for (a = 0; a < key_cnt && itr_key != NULL; a++) {
+ if (itr_key->key_id == key_id) {
*d_key = itr_key;
return;
}