OpenCoverage

dtls1_bitmap.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/ssl/record/dtls1_bitmap.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include "../ssl_locl.h"-
11#include "record_locl.h"-
12-
13/* mod 128 saturating subtract of two 64-bit values in big-endian order */-
14static int satsub64be(const unsigned char *v1, const unsigned char *v2)-
15{-
16 int64_t ret;-
17 uint64_t l1, l2;-
18-
19 n2l8(v1, l1);-
20 n2l8(v2, l2);-
21-
22 ret = l1 - l2;-
23-
24 /* We do not permit wrap-around */-
25 if (l1 > l2 && ret < 0)
l1 > l2Description
TRUEevaluated 5384 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1450 times by 1 test
Evaluated by:
  • libssl.so.1.1
ret < 0Description
TRUEnever evaluated
FALSEevaluated 5384 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-5384
26 return 128;
never executed: return 128;
0
27 else if (l2 > l1 && ret > 0)
l2 > l1Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 6812 times by 1 test
Evaluated by:
  • libssl.so.1.1
ret > 0Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-6812
28 return -128;
never executed: return -128;
0
29-
30 if (ret > 128)
ret > 128Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 6815 times by 1 test
Evaluated by:
  • libssl.so.1.1
19-6815
31 return 128;
executed 19 times by 1 test: return 128;
Executed by:
  • libssl.so.1.1
19
32 else if (ret < -128)
ret < -128Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 6810 times by 1 test
Evaluated by:
  • libssl.so.1.1
5-6810
33 return -128;
executed 5 times by 1 test: return -128;
Executed by:
  • libssl.so.1.1
5
34 else-
35 return (int)ret;
executed 6810 times by 1 test: return (int)ret;
Executed by:
  • libssl.so.1.1
6810
36}-
37-
38int dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap)-
39{-
40 int cmp;-
41 unsigned int shift;-
42 const unsigned char *seq = s->rlayer.read_sequence;-
43-
44 cmp = satsub64be(seq, bitmap->max_seq_num);-
45 if (cmp > 0) {
cmp > 0Description
TRUEevaluated 2693 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 732 times by 1 test
Evaluated by:
  • libssl.so.1.1
732-2693
46 SSL3_RECORD_set_seq_num(RECORD_LAYER_get_rrec(&s->rlayer), seq);-
47 return 1; /* this record in new */
executed 2693 times by 1 test: return 1;
Executed by:
  • libssl.so.1.1
2693
48 }-
49 shift = -cmp;-
50 if (shift >= sizeof(bitmap->map) * 8)
shift >= sizeo...tmap->map) * 8Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 727 times by 1 test
Evaluated by:
  • libssl.so.1.1
5-727
51 return 0; /* stale, outside the window */
executed 5 times by 1 test: return 0;
Executed by:
  • libssl.so.1.1
5
52 else if (bitmap->map & (1UL << shift))
bitmap->map & (1UL << shift)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 725 times by 1 test
Evaluated by:
  • libssl.so.1.1
2-725
53 return 0; /* record previously received */
executed 2 times by 1 test: return 0;
Executed by:
  • libssl.so.1.1
2
54-
55 SSL3_RECORD_set_seq_num(RECORD_LAYER_get_rrec(&s->rlayer), seq);-
56 return 1;
executed 725 times by 1 test: return 1;
Executed by:
  • libssl.so.1.1
725
57}-
58-
59void dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap)-
60{-
61 int cmp;-
62 unsigned int shift;-
63 const unsigned char *seq = RECORD_LAYER_get_read_sequence(&s->rlayer);-
64-
65 cmp = satsub64be(seq, bitmap->max_seq_num);-
66 if (cmp > 0) {
cmp > 0Description
TRUEevaluated 2691 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 718 times by 1 test
Evaluated by:
  • libssl.so.1.1
718-2691
67 shift = cmp;-
68 if (shift < sizeof(bitmap->map) * 8)
shift < sizeof...tmap->map) * 8Description
TRUEevaluated 2682 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libssl.so.1.1
9-2682
69 bitmap->map <<= shift, bitmap->map |= 1UL;
executed 2682 times by 1 test: bitmap->map <<= shift, bitmap->map |= 1UL;
Executed by:
  • libssl.so.1.1
2682
70 else-
71 bitmap->map = 1UL;
executed 9 times by 1 test: bitmap->map = 1UL;
Executed by:
  • libssl.so.1.1
9
72 memcpy(bitmap->max_seq_num, seq, SEQ_NUM_SIZE);-
73 } else {
executed 2691 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
2691
74 shift = -cmp;-
75 if (shift < sizeof(bitmap->map) * 8)
shift < sizeof...tmap->map) * 8Description
TRUEevaluated 718 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEnever evaluated
0-718
76 bitmap->map |= 1UL << shift;
executed 718 times by 1 test: bitmap->map |= 1UL << shift;
Executed by:
  • libssl.so.1.1
718
77 }
executed 718 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
718
78}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2