/src/openssl30/crypto/des/ncbc_enc.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 1998-2016 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 4 |  |  * Licensed under the Apache License 2.0 (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 |  | /*- | 
| 11 |  |  * #included by: | 
| 12 |  |  *    cbc_enc.c  (DES_cbc_encrypt) | 
| 13 |  |  *    des_enc.c  (DES_ncbc_encrypt) | 
| 14 |  |  */ | 
| 15 |  |  | 
| 16 |  | #include "des_local.h" | 
| 17 |  |  | 
| 18 |  | #ifdef CBC_ENC_C__DONT_UPDATE_IV | 
| 19 |  | void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, | 
| 20 |  |                      DES_key_schedule *_schedule, DES_cblock *ivec, int enc) | 
| 21 |  | #else | 
| 22 |  | void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, | 
| 23 |  |                       long length, DES_key_schedule *_schedule, | 
| 24 |  |                       DES_cblock *ivec, int enc) | 
| 25 |  | #endif | 
| 26 | 0 | { | 
| 27 | 0 |     register DES_LONG tin0, tin1; | 
| 28 | 0 |     register DES_LONG tout0, tout1, xor0, xor1; | 
| 29 | 0 |     register long l = length; | 
| 30 | 0 |     DES_LONG tin[2]; | 
| 31 | 0 |     unsigned char *iv; | 
| 32 |  | 
 | 
| 33 | 0 |     iv = &(*ivec)[0]; | 
| 34 |  | 
 | 
| 35 | 0 |     if (enc) { | 
| 36 | 0 |         c2l(iv, tout0); | 
| 37 | 0 |         c2l(iv, tout1); | 
| 38 | 0 |         for (l -= 8; l >= 0; l -= 8) { | 
| 39 | 0 |             c2l(in, tin0); | 
| 40 | 0 |             c2l(in, tin1); | 
| 41 | 0 |             tin0 ^= tout0; | 
| 42 | 0 |             tin[0] = tin0; | 
| 43 | 0 |             tin1 ^= tout1; | 
| 44 | 0 |             tin[1] = tin1; | 
| 45 | 0 |             DES_encrypt1((DES_LONG *)tin, _schedule, DES_ENCRYPT); | 
| 46 | 0 |             tout0 = tin[0]; | 
| 47 | 0 |             l2c(tout0, out); | 
| 48 | 0 |             tout1 = tin[1]; | 
| 49 | 0 |             l2c(tout1, out); | 
| 50 | 0 |         } | 
| 51 | 0 |         if (l != -8) { | 
| 52 | 0 |             c2ln(in, tin0, tin1, l + 8); | 
| 53 | 0 |             tin0 ^= tout0; | 
| 54 | 0 |             tin[0] = tin0; | 
| 55 | 0 |             tin1 ^= tout1; | 
| 56 | 0 |             tin[1] = tin1; | 
| 57 | 0 |             DES_encrypt1((DES_LONG *)tin, _schedule, DES_ENCRYPT); | 
| 58 | 0 |             tout0 = tin[0]; | 
| 59 | 0 |             l2c(tout0, out); | 
| 60 | 0 |             tout1 = tin[1]; | 
| 61 | 0 |             l2c(tout1, out); | 
| 62 | 0 |         } | 
| 63 | 0 | #ifndef CBC_ENC_C__DONT_UPDATE_IV | 
| 64 | 0 |         iv = &(*ivec)[0]; | 
| 65 | 0 |         l2c(tout0, iv); | 
| 66 | 0 |         l2c(tout1, iv); | 
| 67 | 0 | #endif | 
| 68 | 0 |     } else { | 
| 69 | 0 |         c2l(iv, xor0); | 
| 70 | 0 |         c2l(iv, xor1); | 
| 71 | 0 |         for (l -= 8; l >= 0; l -= 8) { | 
| 72 | 0 |             c2l(in, tin0); | 
| 73 | 0 |             tin[0] = tin0; | 
| 74 | 0 |             c2l(in, tin1); | 
| 75 | 0 |             tin[1] = tin1; | 
| 76 | 0 |             DES_encrypt1((DES_LONG *)tin, _schedule, DES_DECRYPT); | 
| 77 | 0 |             tout0 = tin[0] ^ xor0; | 
| 78 | 0 |             tout1 = tin[1] ^ xor1; | 
| 79 | 0 |             l2c(tout0, out); | 
| 80 | 0 |             l2c(tout1, out); | 
| 81 | 0 |             xor0 = tin0; | 
| 82 | 0 |             xor1 = tin1; | 
| 83 | 0 |         } | 
| 84 | 0 |         if (l != -8) { | 
| 85 | 0 |             c2l(in, tin0); | 
| 86 | 0 |             tin[0] = tin0; | 
| 87 | 0 |             c2l(in, tin1); | 
| 88 | 0 |             tin[1] = tin1; | 
| 89 | 0 |             DES_encrypt1((DES_LONG *)tin, _schedule, DES_DECRYPT); | 
| 90 | 0 |             tout0 = tin[0] ^ xor0; | 
| 91 | 0 |             tout1 = tin[1] ^ xor1; | 
| 92 | 0 |             l2cn(tout0, tout1, out, l + 8); | 
| 93 | 0 | #ifndef CBC_ENC_C__DONT_UPDATE_IV | 
| 94 | 0 |             xor0 = tin0; | 
| 95 | 0 |             xor1 = tin1; | 
| 96 | 0 | #endif | 
| 97 | 0 |         } | 
| 98 | 0 | #ifndef CBC_ENC_C__DONT_UPDATE_IV | 
| 99 | 0 |         iv = &(*ivec)[0]; | 
| 100 | 0 |         l2c(xor0, iv); | 
| 101 | 0 |         l2c(xor1, iv); | 
| 102 | 0 | #endif | 
| 103 | 0 |     } | 
| 104 | 0 |     tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0; | 
| 105 | 0 |     tin[0] = tin[1] = 0; | 
| 106 | 0 | } |