-: 0:Source:f_aead.c -: 0:Graph:/var/tsitkova/Sources/v10/trunk/src/lib/crypto/builtin/des/f_aead.so.gcno -: 0:Data:/var/tsitkova/Sources/v10/trunk/src/lib/crypto/builtin/des/f_aead.so.gcda -: 0:Runs:1630 -: 0:Programs:1 -: 1:/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -: 2:/* -: 3: * Copyright (C) 2008 by the Massachusetts Institute of Technology. -: 4: * Copyright 1995 by Richard P. Basch. All Rights Reserved. -: 5: * Copyright 1995 by Lehman Brothers, Inc. All Rights Reserved. -: 6: * -: 7: * Export of this software from the United States of America may -: 8: * require a specific license from the United States Government. -: 9: * It is the responsibility of any person or organization contemplating -: 10: * export to obtain such a license before exporting. -: 11: * -: 12: * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and -: 13: * distribute this software and its documentation for any purpose and -: 14: * without fee is hereby granted, provided that the above copyright -: 15: * notice appear in all copies and that both that copyright notice and -: 16: * this permission notice appear in supporting documentation, and that -: 17: * the name of Richard P. Basch, Lehman Brothers and M.I.T. not be used -: 18: * in advertising or publicity pertaining to distribution of the software -: 19: * without specific, written prior permission. Richard P. Basch, -: 20: * Lehman Brothers and M.I.T. make no representations about the suitability -: 21: * of this software for any purpose. It is provided "as is" without -: 22: * express or implied warranty. -: 23: */ -: 24: -: 25:#include "crypto_int.h" -: 26:#include "des_int.h" -: 27:#include "f_tables.h" -: 28: -: 29:const mit_des_cblock mit_des_zeroblock /* = all zero */; -: 30: -: 31:void 604: 32:krb5int_des_cbc_encrypt(krb5_crypto_iov *data, unsigned long num_data, -: 33: const mit_des_key_schedule schedule, -: 34: mit_des_cblock ivec) -: 35:{ -: 36: unsigned DES_INT32 left, right; -: 37: const unsigned DES_INT32 *kp; -: 38: const unsigned char *ip; -: 39: struct iov_block_state input_pos, output_pos; 604: 40: unsigned char storage[MIT_DES_BLOCK_LENGTH], *block = NULL, *ptr; -: 41: 604: 42: IOV_BLOCK_STATE_INIT(&input_pos); 604: 43: IOV_BLOCK_STATE_INIT(&output_pos); -: 44: -: 45: /* Get key pointer here. This won't need to be reinitialized. */ 604: 46: kp = (const unsigned DES_INT32 *)schedule; -: 47: -: 48: /* Initialize left and right with the contents of the initial vector. */ 604: 49: ip = (ivec != NULL) ? ivec : mit_des_zeroblock; 604: 50: GET_HALF_BLOCK(left, ip); 604: 51: GET_HALF_BLOCK(right, ip); -: 52: -: 53: /* Work the length down 8 bytes at a time. */ -: 54: for (;;) { -: 55: unsigned DES_INT32 temp; -: 56: 5629: 57: if (!krb5int_c_iov_get_block_nocopy(storage, MIT_DES_BLOCK_LENGTH, -: 58: data, num_data, &input_pos, &ptr)) -: 59: break; 5025: 60: block = ptr; -: 61: -: 62: /* Decompose this block and xor it with the previous ciphertext. */ 5025: 63: GET_HALF_BLOCK(temp, ptr); 5025: 64: left ^= temp; 5025: 65: GET_HALF_BLOCK(temp, ptr); 5025: 66: right ^= temp; -: 67: -: 68: /* Encrypt what we have and put back into block. */ 5025: 69: DES_DO_ENCRYPT(left, right, kp); 5025: 70: ptr = block; 5025: 71: PUT_HALF_BLOCK(left, ptr); 5025: 72: PUT_HALF_BLOCK(right, ptr); -: 73: 5025: 74: krb5int_c_iov_put_block_nocopy(data, num_data, storage, -: 75: MIT_DES_BLOCK_LENGTH, &output_pos, -: 76: block); 5025: 77: } -: 78: 950: 79: if (ivec != NULL && block != NULL) { 346: 80: ptr = ivec; 346: 81: PUT_HALF_BLOCK(left, ptr); 346: 82: PUT_HALF_BLOCK(right, ptr); -: 83: } 604: 84:} -: 85: -: 86:void 738: 87:krb5int_des_cbc_decrypt(krb5_crypto_iov *data, unsigned long num_data, -: 88: const mit_des_key_schedule schedule, -: 89: mit_des_cblock ivec) -: 90:{ -: 91: unsigned DES_INT32 left, right; -: 92: const unsigned DES_INT32 *kp; -: 93: const unsigned char *ip; -: 94: unsigned DES_INT32 ocipherl, ocipherr; -: 95: unsigned DES_INT32 cipherl, cipherr; -: 96: struct iov_block_state input_pos, output_pos; 738: 97: unsigned char storage[MIT_DES_BLOCK_LENGTH], *block = NULL, *ptr; -: 98: 738: 99: IOV_BLOCK_STATE_INIT(&input_pos); 738: 100: IOV_BLOCK_STATE_INIT(&output_pos); -: 101: -: 102: /* Get key pointer here. This won't need to be reinitialized. */ 738: 103: kp = (const unsigned DES_INT32 *)schedule; -: 104: -: 105: /* -: 106: * Decrypting is harder than encrypting because of -: 107: * the necessity of remembering a lot more things. -: 108: * Should think about this a little more... -: 109: */ -: 110: -: 111: /* Prime the old cipher with ivec. */ 738: 112: ip = (ivec != NULL) ? ivec : mit_des_zeroblock; 738: 113: GET_HALF_BLOCK(ocipherl, ip); 738: 114: GET_HALF_BLOCK(ocipherr, ip); -: 115: -: 116: /* Work the length down 8 bytes at a time. */ -: 117: for (;;) { 6140: 118: if (!krb5int_c_iov_get_block_nocopy(storage, MIT_DES_BLOCK_LENGTH, -: 119: data, num_data, &input_pos, &ptr)) -: 120: break; 5402: 121: block = ptr; -: 122: -: 123: /* Split this block into left and right. */ 5402: 124: GET_HALF_BLOCK(left, ptr); 5402: 125: GET_HALF_BLOCK(right, ptr); 5402: 126: cipherl = left; 5402: 127: cipherr = right; -: 128: -: 129: /* Decrypt and xor with the old cipher to get plain text. */ 5402: 130: DES_DO_DECRYPT(left, right, kp); 5402: 131: left ^= ocipherl; 5402: 132: right ^= ocipherr; -: 133: -: 134: /* Store the encrypted halves back into block. */ 5402: 135: ptr = block; 5402: 136: PUT_HALF_BLOCK(left, ptr); 5402: 137: PUT_HALF_BLOCK(right, ptr); -: 138: -: 139: /* Save current cipher block halves. */ 5402: 140: ocipherl = cipherl; 5402: 141: ocipherr = cipherr; -: 142: 5402: 143: krb5int_c_iov_put_block_nocopy(data, num_data, storage, -: 144: MIT_DES_BLOCK_LENGTH, &output_pos, -: 145: block); 5402: 146: } -: 147: 1278: 148: if (ivec != NULL && block != NULL) { 540: 149: ptr = ivec; 540: 150: PUT_HALF_BLOCK(ocipherl, ptr); 540: 151: PUT_HALF_BLOCK(ocipherr, ptr); -: 152: } 738: 153:} -: 154: -: 155:void 145: 156:krb5int_des_cbc_mac(const krb5_crypto_iov *data, unsigned long num_data, -: 157: const mit_des_key_schedule schedule, mit_des_cblock ivec, -: 158: mit_des_cblock out) -: 159:{ -: 160: unsigned DES_INT32 left, right; -: 161: const unsigned DES_INT32 *kp; -: 162: const unsigned char *ip; -: 163: struct iov_block_state input_pos; -: 164: unsigned char storage[MIT_DES_BLOCK_LENGTH], *ptr; -: 165: 145: 166: IOV_BLOCK_STATE_INIT(&input_pos); 145: 167: input_pos.include_sign_only = 1; -: 168: -: 169: /* Get key pointer here. This won't need to be reinitialized. */ 145: 170: kp = (const unsigned DES_INT32 *)schedule; -: 171: -: 172: /* Initialize left and right with the contents of the initial vector. */ 145: 173: ip = (ivec != NULL) ? ivec : mit_des_zeroblock; 145: 174: GET_HALF_BLOCK(left, ip); 145: 175: GET_HALF_BLOCK(right, ip); -: 176: -: 177: /* Work the length down 8 bytes at a time. */ -: 178: for (;;) { -: 179: unsigned DES_INT32 temp; -: 180: 500: 181: if (!krb5int_c_iov_get_block_nocopy(storage, MIT_DES_BLOCK_LENGTH, -: 182: data, num_data, &input_pos, &ptr)) -: 183: break; -: 184: -: 185: /* Decompose this block and xor it with the previous ciphertext. */ 355: 186: GET_HALF_BLOCK(temp, ptr); 355: 187: left ^= temp; 355: 188: GET_HALF_BLOCK(temp, ptr); 355: 189: right ^= temp; -: 190: -: 191: /* Encrypt what we have. */ 355: 192: DES_DO_ENCRYPT(left, right, kp); 355: 193: } -: 194: -: 195: /* Output the final ciphertext block. */ 145: 196: ptr = out; 145: 197: PUT_HALF_BLOCK(left, ptr); 145: 198: PUT_HALF_BLOCK(right, ptr); 145: 199:} -: 200: -: 201:#if defined(CONFIG_SMALL) && !defined(CONFIG_SMALL_NO_CRYPTO) -: 202:void krb5int_des_do_encrypt_2 (unsigned DES_INT32 *left, -: 203: unsigned DES_INT32 *right, -: 204: const unsigned DES_INT32 *kp) -: 205:{ -: 206: DES_DO_ENCRYPT_1 (*left, *right, kp); -: 207:} -: 208: -: 209:void krb5int_des_do_decrypt_2 (unsigned DES_INT32 *left, -: 210: unsigned DES_INT32 *right, -: 211: const unsigned DES_INT32 *kp) -: 212:{ -: 213: DES_DO_DECRYPT_1 (*left, *right, kp); -: 214:} -: 215:#endif