X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsptps.c;h=12c6c7f022b83fbf89adc2e536932415f4365fd6;hb=5ede437307cc3bbb20431f4b82f4a2ef79c9b746;hp=422940c9df26d0bc864d6f880ca426c119059e80;hpb=aaff0ed08916f936b0a7b8a3d0607b8111b7a185;p=meshlink diff --git a/src/sptps.c b/src/sptps.c index 422940c9..12c6c7f0 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -376,6 +376,20 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) { } } +// Check datagram for valid HMAC +bool sptps_verify_datagram(sptps_t *s, const char *data, size_t len) { + if(!s->instate || len < 21) + return false; + + char buffer[len + 23]; + uint16_t netlen = htons(len - 21); + + memcpy(buffer, &netlen, 2); + memcpy(buffer + 2, data, len); + + return digest_verify(&s->indigest, buffer, len - 14, buffer + len - 14); +} + // Receive incoming data, datagram version. static bool sptps_receive_data_datagram(sptps_t *s, const char *data, size_t len) { if(len < (s->instate ? 21 : 5))