X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=ssl%2Fpacket_locl.h;h=507d64f8c41eb9bdce78be4763599b15b788a4bc;hb=788d72ba021fdd29f6b3e573adc313d97f7d224d;hp=9354e6c99834ef87e3db9188d8daa590af274ed1;hpb=329428708d6836676f6a7078aa2e2a1db9a1addb;p=openssl.git diff --git a/ssl/packet_locl.h b/ssl/packet_locl.h index 9354e6c998..507d64f8c4 100644 --- a/ssl/packet_locl.h +++ b/ssl/packet_locl.h @@ -62,6 +62,7 @@ # include # include # include +# include # include "e_os.h" # ifdef __cplusplus @@ -85,7 +86,7 @@ static inline void packet_forward(PACKET *pkt, size_t len) /* * Returns the number of bytes remaining to be read in the PACKET */ -__owur static inline size_t PACKET_remaining(const PACKET *pkt) +static inline size_t PACKET_remaining(const PACKET *pkt) { return pkt->remaining; } @@ -106,7 +107,8 @@ static inline unsigned char *PACKET_data(const PACKET *pkt) * copy of the data so |buf| must be present for the whole time that the PACKET * is being used. */ -static inline int PACKET_buf_init(PACKET *pkt, unsigned char *buf, size_t len) +__owur static inline int PACKET_buf_init(PACKET *pkt, unsigned char *buf, + size_t len) { /* Sanity check for negative values. */ if (buf + len < buf) @@ -124,6 +126,18 @@ static inline void PACKET_null_init(PACKET *pkt) pkt->remaining = 0; } +/* + * Returns 1 if the packet has length |num| and its contents equal the |num| + * bytes read from |ptr|. Returns 0 otherwise (lengths or contents not equal). + * If lengths are equal, performs the comparison in constant time. + */ +__owur static inline int PACKET_equal(const PACKET *pkt, const void *ptr, + size_t num) { + if (PACKET_remaining(pkt) != num) + return 0; + return CRYPTO_memcmp(pkt->curr, ptr, num) == 0; +} + /* * Peek ahead and initialize |subpkt| with the next |len| bytes read from |pkt|. * Data is not copied: the |subpkt| packet will share its underlying buffer with @@ -135,9 +149,7 @@ __owur static inline int PACKET_peek_sub_packet(const PACKET *pkt, if (PACKET_remaining(pkt) < len) return 0; - PACKET_buf_init(subpkt, pkt->curr, len); - - return 1; + return PACKET_buf_init(subpkt, pkt->curr, len); } /*