summaryrefslogtreecommitdiff
path: root/proto
diff options
context:
space:
mode:
Diffstat (limited to 'proto')
-rw-r--r--proto/ospf/packet.c31
-rw-r--r--proto/rip/packets.c18
2 files changed, 23 insertions, 26 deletions
diff --git a/proto/ospf/packet.c b/proto/ospf/packet.c
index 0975b251..9690c28a 100644
--- a/proto/ospf/packet.c
+++ b/proto/ospf/packet.c
@@ -11,6 +11,7 @@
#include "ospf.h"
#include "nest/password.h"
#include "lib/md5.h"
+#include "lib/socket.h"
void
ospf_pkt_fill_hdr(struct ospf_iface *ifa, void *buf, u8 h_type)
@@ -108,11 +109,11 @@ ospf_pkt_finalize(struct ospf_iface *ifa, struct ospf_packet *pkt)
char password[OSPF_AUTH_CRYPT_SIZE];
strncpy(password, passwd->password, sizeof(password));
- struct MD5Context ctxt;
- MD5Init(&ctxt);
- MD5Update(&ctxt, (char *) pkt, plen);
- MD5Update(&ctxt, password, OSPF_AUTH_CRYPT_SIZE);
- MD5Final(tail, &ctxt);
+ struct md5_context ctx;
+ md5_init(&ctx);
+ md5_update(&ctx, (char *) pkt, plen);
+ md5_update(&ctx, password, OSPF_AUTH_CRYPT_SIZE);
+ memcpy((byte *) tail, md5_final(&ctx), MD5_SIZE);
break;
default:
@@ -174,19 +175,17 @@ ospf_pkt_checkauth(struct ospf_neighbor *n, struct ospf_iface *ifa, struct ospf_
if (!pass)
DROP("no suitable password found", auth->md5.keyid);
- void *tail = ((void *) pkt) + plen;
- char passwd[OSPF_AUTH_CRYPT_SIZE];
- char md5sum[OSPF_AUTH_CRYPT_SIZE];
-
- strncpy(passwd, pass->password, OSPF_AUTH_CRYPT_SIZE);
+ byte *tail = ((byte *) pkt) + plen;
+ char received[OSPF_AUTH_CRYPT_SIZE];
+ memcpy(received, tail, OSPF_AUTH_CRYPT_SIZE);
+ strncpy(tail, pass->password, OSPF_AUTH_CRYPT_SIZE);
- struct MD5Context ctxt;
- MD5Init(&ctxt);
- MD5Update(&ctxt, (char *) pkt, plen);
- MD5Update(&ctxt, passwd, OSPF_AUTH_CRYPT_SIZE);
- MD5Final(md5sum, &ctxt);
+ struct md5_context ctx;
+ md5_init(&ctx);
+ md5_update(&ctx, (byte *) pkt, plen + OSPF_AUTH_CRYPT_SIZE);
+ char *computed = md5_final(&ctx);
- if (memcmp(md5sum, tail, OSPF_AUTH_CRYPT_SIZE))
+ if (memcmp(received, computed, OSPF_AUTH_CRYPT_SIZE))
DROP("wrong MD5 digest", pass->id);
if (n)
diff --git a/proto/rip/packets.c b/proto/rip/packets.c
index e2a2390b..4fc832d5 100644
--- a/proto/rip/packets.c
+++ b/proto/rip/packets.c
@@ -240,10 +240,10 @@ rip_fill_authentication(struct rip_proto *p, struct rip_iface *ifa, struct rip_p
*plen += sizeof(struct rip_auth_tail) + RIP_MD5_LENGTH;
- struct MD5Context ctxt;
- MD5Init(&ctxt);
- MD5Update(&ctxt, (byte *) pkt, *plen);
- MD5Final(tail->auth_data, &ctxt);
+ struct md5_context ctx;
+ md5_init(&ctx);
+ md5_update(&ctx, (byte *) pkt, *plen);
+ memcpy(tail->auth_data, md5_final(&ctx), RIP_MD5_LENGTH);
return;
default:
@@ -311,15 +311,13 @@ rip_check_authentication(struct rip_proto *p, struct rip_iface *ifa, struct rip_
}
char received[RIP_MD5_LENGTH];
- char computed[RIP_MD5_LENGTH];
-
memcpy(received, tail->auth_data, RIP_MD5_LENGTH);
strncpy(tail->auth_data, pass->password, RIP_MD5_LENGTH);
- struct MD5Context ctxt;
- MD5Init(&ctxt);
- MD5Update(&ctxt, (byte *) pkt, *plen);
- MD5Final(computed, &ctxt);
+ struct md5_context ctx;
+ md5_init(&ctx);
+ md5_update(&ctx, (byte *) pkt, *plen);
+ char *computed = md5_final(&ctx);
if (memcmp(received, computed, RIP_MD5_LENGTH))
DROP("wrong MD5 digest", pass->id);