e1a956f777dfcc21ad1810ac84cee494fbab206a
[krb5.git] / src / lib / crypto / raw_des.c
1 /*
2  * lib/crypto/raw-des.c
3  *
4  * Copyright 1994, 1995 by the Massachusetts Institute of Technology.
5  * 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 M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  M.I.T. makes no representations about the suitability of
20  * this software for any purpose.  It is provided "as is" without express
21  * or implied warranty.
22  */
23
24 #include "k5-int.h"
25 #include "des_int.h"
26
27 krb5_error_code INTERFACE mit_raw_des_encrypt_func
28     PROTOTYPE(( krb5_const_pointer, krb5_pointer, const size_t,
29                krb5_encrypt_block *, krb5_pointer ));
30
31 krb5_error_code INTERFACE mit_raw_des_decrypt_func
32     PROTOTYPE(( krb5_const_pointer, krb5_pointer, const size_t,
33                krb5_encrypt_block *, krb5_pointer ));
34
35 static krb5_cryptosystem_entry mit_raw_des_cryptosystem_entry = {
36     0,
37     mit_raw_des_encrypt_func,
38     mit_raw_des_decrypt_func,
39     mit_des_process_key,
40     mit_des_finish_key,
41     mit_des_string_to_key,
42     mit_des_init_random_key,
43     mit_des_finish_random_key,
44     mit_des_random_key,
45     sizeof(mit_des_cblock),
46     0,
47     sizeof(mit_des_cblock),
48     ETYPE_RAW_DES_CBC,
49     KEYTYPE_DES
50     };
51
52 krb5_cs_table_entry krb5_raw_des_cst_entry = {
53     0,
54     &mit_raw_des_cryptosystem_entry,
55     0
56     };
57
58 krb5_error_code INTERFACE
59 mit_raw_des_decrypt_func(in, out, size, key, ivec)
60     krb5_const_pointer in;
61     krb5_pointer out;
62     const size_t size;
63     krb5_encrypt_block * key;
64     krb5_pointer ivec;
65 {
66     return (mit_des_cbc_encrypt ((const mit_des_cblock *) in, 
67                                  out, 
68                                  size, 
69                                  (struct mit_des_ks_struct *)key->priv, 
70                                  ivec ? ivec : (krb5_pointer)key->key->contents,
71                                  MIT_DES_DECRYPT));
72 }
73
74 krb5_error_code INTERFACE
75 mit_raw_des_encrypt_func(in, out, size, key, ivec)
76     krb5_const_pointer in;
77     krb5_pointer out;
78     const size_t size;
79     krb5_encrypt_block * key;
80     krb5_pointer ivec;
81 {
82    int sumsize;
83
84    /* round up to des block size */
85
86    sumsize =  krb5_roundup(size, sizeof(mit_des_cblock));
87
88    /* assemble crypto input into the output area, then encrypt in place. */
89
90    memset((char *)out, 0, sumsize);
91    memcpy((char *)out, (char *)in, size);
92
93     /* We depend here on the ability of this DES implementation to
94        encrypt plaintext to ciphertext in-place. */
95     return (mit_des_cbc_encrypt (out, 
96                                  out, 
97                                  sumsize, 
98                                  (struct mit_des_ks_struct *)key->priv, 
99                                  ivec ? ivec : (krb5_pointer)key->key->contents,
100                                  MIT_DES_ENCRYPT));
101 }