| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/e_des.c | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||
| 9 | const unsigned char *iv, int enc); | - | ||||||||||||
| 10 | static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); | - | ||||||||||||
| 11 | - | |||||||||||||
| 12 | - | |||||||||||||
| 13 | - | |||||||||||||
| 14 | static int | - | ||||||||||||
| 15 | des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
| 16 | const unsigned char *in, size_t inl) | - | ||||||||||||
| 17 | { | - | ||||||||||||
| 18 | size_t i, bl; bl = ctx->cipher->block_size; if(inl < bl 
 never executed: 1; return 1;never executed: inl -= bl; for(i=0; i <= inl return 1;
 | 0-462 | ||||||||||||
| 19 | DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), executed 462 times by 2 tests:  DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), ctx->cipher_data, ctx->encrypt);Executed by: 
 | 462 | ||||||||||||
| 20 | ctx->cipher_data, ctx->encrypt); executed 462 times by 2 tests:  DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), ctx->cipher_data, ctx->encrypt);Executed by: 
 | 462 | ||||||||||||
| 21 | return executed 20 times by 2 tests: 1; return 1;Executed by: 
 executed 20 times by 2 tests:  return 1;Executed by: 
 | 20 | ||||||||||||
| 22 | } | - | ||||||||||||
| 23 | - | |||||||||||||
| 24 | static int | - | ||||||||||||
| 25 | des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
| 26 | const unsigned char *in, size_t inl) | - | ||||||||||||
| 27 | { | - | ||||||||||||
| 28 | while (inl >= ((size_t)1<<(sizeof(long)*8-2)) 
 | 0-4 | ||||||||||||
| 29 | DES_ofb64_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), ctx->cipher_data, | - | ||||||||||||
| 30 | (DES_cblock *)ctx->iv, &ctx->num); | - | ||||||||||||
| 31 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 32 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 33 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 34 | } never executed:  end of block | 0 | ||||||||||||
| 35 | if (inl 
 | 0-4 | ||||||||||||
| 36 | DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, executed 4 times by 1 test:  DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num);Executed by: 
 | 4 | ||||||||||||
| 37 | (DES_cblock *)ctx->iv, &ctx->num); executed 4 times by 1 test:  DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num);Executed by: 
 | 4 | ||||||||||||
| 38 | return executed 4 times by 1 test: 1; return 1;Executed by: 
 executed 4 times by 1 test:  return 1;Executed by: 
 | 4 | ||||||||||||
| 39 | } | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | static int | - | ||||||||||||
| 42 | des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
| 43 | const unsigned char *in, size_t inl) | - | ||||||||||||
| 44 | { | - | ||||||||||||
| 45 | while (inl >= ((size_t)1<<(sizeof(long)*8-2)) 
 | 0-6 | ||||||||||||
| 46 | DES_ncbc_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), ctx->cipher_data, | - | ||||||||||||
| 47 | (DES_cblock *)ctx->iv, ctx->encrypt); | - | ||||||||||||
| 48 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 49 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 50 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 51 | } never executed:  end of block | 0 | ||||||||||||
| 52 | if (inl 
 | 0-6 | ||||||||||||
| 53 | DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data, executed 6 times by 1 test:  DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt);Executed by: 
 | 6 | ||||||||||||
| 54 | (DES_cblock *)ctx->iv, ctx->encrypt); executed 6 times by 1 test:  DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt);Executed by: 
 | 6 | ||||||||||||
| 55 | return executed 6 times by 1 test: 1; return 1;Executed by: 
 executed 6 times by 1 test:  return 1;Executed by: 
 | 6 | ||||||||||||
| 56 | } | - | ||||||||||||
| 57 | - | |||||||||||||
| 58 | static int | - | ||||||||||||
| 59 | des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
| 60 | const unsigned char *in, size_t inl) | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | while (inl >= ((size_t)1<<(sizeof(long)*8-2)) 
 | 0-4 | ||||||||||||
| 63 | DES_cfb64_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), ctx->cipher_data, | - | ||||||||||||
| 64 | (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); | - | ||||||||||||
| 65 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 66 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 67 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 68 | } never executed:  end of block | 0 | ||||||||||||
| 69 | if (inl 
 | 0-4 | ||||||||||||
| 70 | DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data, executed 4 times by 1 test:  DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);Executed by: 
 | 4 | ||||||||||||
| 71 | (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); executed 4 times by 1 test:  DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);Executed by: 
 | 4 | ||||||||||||
| 72 | return executed 4 times by 1 test: 1; return 1;Executed by: 
 executed 4 times by 1 test:  return 1;Executed by: 
 | 4 | ||||||||||||
| 73 | } | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | - | |||||||||||||
| 76 | - | |||||||||||||
| 77 | static int | - | ||||||||||||
| 78 | des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
| 79 | const unsigned char *in, size_t inl) | - | ||||||||||||
| 80 | { | - | ||||||||||||
| 81 | size_t n, chunk = ((size_t)1<<(sizeof(long)*8-2))/8; | - | ||||||||||||
| 82 | unsigned char c[1], d[1]; | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | if (inl < chunk 
 | 0 | ||||||||||||
| 85 | chunk = inl; never executed:  chunk = inl; | 0 | ||||||||||||
| 86 | - | |||||||||||||
| 87 | while (inl 
 
 | 0 | ||||||||||||
| 88 | for (n = 0; n < chunk*8 
 | 0 | ||||||||||||
| 89 | c[0] = ( 
 
 | 0 | ||||||||||||
| 90 | DES_cfb_encrypt(c, d, 1, 1, ctx->cipher_data, | - | ||||||||||||
| 91 | (DES_cblock *)ctx->iv, ctx->encrypt); | - | ||||||||||||
| 92 | out[n / 8] = (out[n / 8] & | - | ||||||||||||
| 93 | ~(0x80 >> (unsigned int)(n % 8))) | | - | ||||||||||||
| 94 | ((d[0] & 0x80) >> (unsigned int)(n % 8)); | - | ||||||||||||
| 95 | } never executed:  end of block | 0 | ||||||||||||
| 96 | inl -= chunk; | - | ||||||||||||
| 97 | in += chunk; | - | ||||||||||||
| 98 | out += chunk; | - | ||||||||||||
| 99 | if (inl < chunk 
 | 0 | ||||||||||||
| 100 | chunk = inl; never executed:  chunk = inl; | 0 | ||||||||||||
| 101 | } never executed:  end of block | 0 | ||||||||||||
| 102 | - | |||||||||||||
| 103 | return never executed: 1; return 1;never executed:  return 1; | 0 | ||||||||||||
| 104 | } | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | static int | - | ||||||||||||
| 107 | des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||
| 108 | const unsigned char *in, size_t inl) | - | ||||||||||||
| 109 | { | - | ||||||||||||
| 110 | while (inl >= ((size_t)1<<(sizeof(long)*8-2)) 
 | 0-4 | ||||||||||||
| 111 | DES_cfb_encrypt(in, out, 8, (long)((size_t)1<<(sizeof(long)*8-2)), | - | ||||||||||||
| 112 | ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt); | - | ||||||||||||
| 113 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 114 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 115 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||
| 116 | } never executed:  end of block | 0 | ||||||||||||
| 117 | if (inl 
 | 0-4 | ||||||||||||
| 118 | DES_cfb_encrypt(in, out, 8, (long)inl, ctx->cipher_data, executed 4 times by 1 test:  DES_cfb_encrypt(in, out, 8, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt);Executed by: 
 | 4 | ||||||||||||
| 119 | (DES_cblock *)ctx->iv, ctx->encrypt); executed 4 times by 1 test:  DES_cfb_encrypt(in, out, 8, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, ctx->encrypt);Executed by: 
 | 4 | ||||||||||||
| 120 | return executed 4 times by 1 test: 1; return 1;Executed by: 
 executed 4 times by 1 test:  return 1;Executed by: 
 | 4 | ||||||||||||
| 121 | } | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | static const EVP_CIPHER des_cbc = { 31, 8, 8, 8, 0x200 | 0x2, des_init_key, des_cbc_cipher, | - | ||||||||||||
| 124 | ((void *)0) | - | ||||||||||||
| 125 | , sizeof(DES_key_schedule), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
| 126 | ((void *)0) | - | ||||||||||||
| 127 | }; const EVP_CIPHER *EVP_des_cbc(void) { return executed 625 times by 33 tests: &des_cbc; return &des_cbc;Executed by: 
 executed 625 times by 33 tests: } static const EVP_CIPHER des_cfb64 = { 30, 1, 8, 8, 0x200 | 0x3, des_init_key, des_cfb64_cipher, return &des_cbc;Executed by: 
 | 625 | ||||||||||||
| 128 | ((void *)0) | - | ||||||||||||
| 129 | , sizeof(DES_key_schedule), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
| 130 | ((void *)0) | - | ||||||||||||
| 131 | }; const EVP_CIPHER *EVP_des_cfb64(void) { return executed 292 times by 33 tests: &des_cfb64; return &des_cfb64;Executed by: 
 executed 292 times by 33 tests: } static const EVP_CIPHER des_ofb = { 45, 1, 8, 8, 0x200 | 0x4, des_init_key, des_ofb_cipher, return &des_cfb64;Executed by: 
 | 292 | ||||||||||||
| 132 | ((void *)0) | - | ||||||||||||
| 133 | , sizeof(DES_key_schedule), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
| 134 | ((void *)0) | - | ||||||||||||
| 135 | }; const EVP_CIPHER *EVP_des_ofb(void) { return executed 292 times by 33 tests: &des_ofb; return &des_ofb;Executed by: 
 executed 292 times by 33 tests: } static const EVP_CIPHER des_ecb = { 29, 8, 8, 0, 0x200 | 0x1, des_init_key, des_ecb_cipher, return &des_ofb;Executed by: 
 | 292 | ||||||||||||
| 136 | ((void *)0) | - | ||||||||||||
| 137 | , sizeof(DES_key_schedule), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
| 138 | ((void *)0) | - | ||||||||||||
| 139 | }; const EVP_CIPHER *EVP_des_ecb(void) { return executed 292 times by 33 tests: &des_ecb; return &des_ecb;Executed by: 
 executed 292 times by 33 tests: } return &des_ecb;Executed by: 
 | 292 | ||||||||||||
| 140 | - | |||||||||||||
| 141 | - | |||||||||||||
| 142 | - | |||||||||||||
| 143 | - | |||||||||||||
| 144 | - | |||||||||||||
| 145 | static const EVP_CIPHER des_cfb1 = { 656, 1, 8, 8, 0x200 | 0x3, des_init_key, des_cfb1_cipher, | - | ||||||||||||
| 146 | ((void *)0) | - | ||||||||||||
| 147 | , sizeof(DES_key_schedule), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
| 148 | ((void *)0) | - | ||||||||||||
| 149 | }; const EVP_CIPHER *EVP_des_cfb1(void) { return executed 292 times by 33 tests: &des_cfb1; return &des_cfb1;Executed by: 
 executed 292 times by 33 tests: } return &des_cfb1;Executed by: 
 | 292 | ||||||||||||
| 150 | - | |||||||||||||
| 151 | - | |||||||||||||
| 152 | - | |||||||||||||
| 153 | - | |||||||||||||
| 154 | static const EVP_CIPHER des_cfb8 = { 657, 1, 8, 8, 0x200 | 0x3, des_init_key, des_cfb8_cipher, | - | ||||||||||||
| 155 | ((void *)0) | - | ||||||||||||
| 156 | , sizeof(DES_key_schedule), EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, des_ctrl, | - | ||||||||||||
| 157 | ((void *)0) | - | ||||||||||||
| 158 | }; const EVP_CIPHER *EVP_des_cfb8(void) { return executed 292 times by 33 tests: &des_cfb8; return &des_cfb8;Executed by: 
 executed 292 times by 33 tests: } return &des_cfb8;Executed by: 
 | 292 | ||||||||||||
| 159 | - | |||||||||||||
| 160 | - | |||||||||||||
| 161 | - | |||||||||||||
| 162 | - | |||||||||||||
| 163 | static int | - | ||||||||||||
| 164 | des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||
| 165 | const unsigned char *iv, int enc) | - | ||||||||||||
| 166 | { | - | ||||||||||||
| 167 | DES_cblock *deskey = (DES_cblock *)key; | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | DES_set_key_unchecked(deskey, ctx->cipher_data); | - | ||||||||||||
| 170 | return executed 34 times by 2 tests: 1; return 1;Executed by: 
 executed 34 times by 2 tests:  return 1;Executed by: 
 | 34 | ||||||||||||
| 171 | } | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | static int | - | ||||||||||||
| 174 | des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | - | ||||||||||||
| 175 | { | - | ||||||||||||
| 176 | switch (type) { | - | ||||||||||||
| 177 | case never executed: 0x6: case 0x6:never executed:  case 0x6: | 0 | ||||||||||||
| 178 | if (DES_random_key((DES_cblock *)ptr) == 0 
 | 0 | ||||||||||||
| 179 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 180 | return never executed: 1; return 1;never executed:  return 1; | 0 | ||||||||||||
| 181 | - | |||||||||||||
| 182 | default never executed: : default:never executed:  default: | 0 | ||||||||||||
| 183 | return never executed: -1; return -1;never executed:  return -1; | 0 | ||||||||||||
| 184 | } | - | ||||||||||||
| 185 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |