1 /* crypto-null.c --- NULL crypto functions
2  * Copyright (C) 2002-2013 Simon Josefsson
3  *
4  * This file is part of Shishi.
5  *
6  * Shishi is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Shishi is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Shishi; if not, see http://www.gnu.org/licenses or write
18  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19  * Floor, Boston, MA 02110-1301, USA
20  *
21  */
22 
23 #include "internal.h"
24 
25 #include "crypto.h"
26 
27 static int
null_encrypt(Shishi * handle,Shishi_key * key,int keyusage,const char * iv,size_t ivlen,char ** ivout,size_t * ivoutlen,const char * in,size_t inlen,char ** out,size_t * outlen)28 null_encrypt (Shishi * handle,
29 	      Shishi_key * key,
30 	      int keyusage,
31 	      const char *iv, size_t ivlen,
32 	      char **ivout, size_t * ivoutlen,
33 	      const char *in, size_t inlen, char **out, size_t * outlen)
34 {
35   *outlen = inlen;
36   *out = xmalloc (*outlen);
37   memcpy (*out, in, inlen);
38 
39   if (ivout)
40     *ivout = NULL;
41   if (ivoutlen)
42     *ivoutlen = 0;
43 
44   return SHISHI_OK;
45 }
46 
47 static int
null_decrypt(Shishi * handle,Shishi_key * key,int keyusage,const char * iv,size_t ivlen,char ** ivout,size_t * ivoutlen,const char * in,size_t inlen,char ** out,size_t * outlen)48 null_decrypt (Shishi * handle,
49 	      Shishi_key * key,
50 	      int keyusage,
51 	      const char *iv, size_t ivlen,
52 	      char **ivout, size_t * ivoutlen,
53 	      const char *in, size_t inlen, char **out, size_t * outlen)
54 {
55   *outlen = inlen;
56   *out = xmalloc (*outlen);
57   memcpy (*out, in, inlen);
58 
59   if (ivout)
60     *ivout = NULL;
61   if (ivoutlen)
62     *ivoutlen = 0;
63 
64   return SHISHI_OK;
65 }
66 
67 static int
null_random_to_key(Shishi * handle,const char * rnd,size_t rndlen,Shishi_key * outkey)68 null_random_to_key (Shishi * handle,
69 		    const char *rnd, size_t rndlen, Shishi_key * outkey)
70 {
71   return SHISHI_OK;
72 }
73 
74 static int
null_string_to_key(Shishi * handle,const char * password,size_t passwordlen,const char * salt,size_t saltlen,const char * parameter,Shishi_key * outkey)75 null_string_to_key (Shishi * handle,
76 		    const char *password, size_t passwordlen,
77 		    const char *salt, size_t saltlen,
78 		    const char *parameter, Shishi_key * outkey)
79 {
80   return SHISHI_OK;
81 }
82 
83 cipherinfo null_info = {
84   SHISHI_NULL,
85   "NULL",
86   1,
87   0,
88   0,
89   0,
90   SHISHI_RSA_MD5,
91   null_random_to_key,
92   null_string_to_key,
93   null_encrypt,
94   null_decrypt
95 };
96