Changeset 54e1fe4
- Timestamp:
- Mar 1, 2010, 8:33:48 PM (15 years ago)
- Branches:
- release-1.5
- Children:
- 8fff19a
- Parents:
- b381b55
- git-author:
- Anders Kaseorg <andersk@mit.edu> (02/07/10 22:55:21)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (03/01/10 20:33:48)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
functions.c
rcce5dbd r54e1fe4 425 425 char *cryptmsg; 426 426 owl_message *m; 427 #ifdef OWL_ENABLE_ZCRYPT428 int ret;429 #endif430 427 431 428 /* create the zwrite and send the message */ … … 438 435 mymsg=owl_zwrite_get_message(&z); 439 436 #ifdef OWL_ENABLE_ZCRYPT 440 /* Allocate enough space for the crypted message. For each byte of 441 * the message, the encoded cyphertext will have two bytes. Block 442 * size is 8 bytes of input, or 16 bytes of output, so make sure we 443 * have at least one block worth of space allocated. If the message 444 * is empty, no blocks are sent, but we still allocate one 445 * block. The additional 16 bytes also provide space for the null 446 * terminator, as we will never use all of it for cyphertext. 447 */ 448 cryptmsg=owl_malloc((strlen(mymsg)*2)+16); 449 ret=owl_zcrypt_encrypt(cryptmsg, mymsg, owl_zwrite_get_class(&z), owl_zwrite_get_instance(&z)); 450 if (ret) { 437 cryptmsg = owl_zcrypt_encrypt(mymsg, owl_zwrite_get_class(&z), owl_zwrite_get_instance(&z)); 438 if (!cryptmsg) { 451 439 owl_function_error("Error in zcrypt, possibly no key found. Message not sent."); 452 440 owl_function_beep(); 453 owl_free(cryptmsg);454 441 owl_zwrite_free(&z); 455 442 return; -
message.c
rb381b55 r54e1fe4 841 841 /* if zcrypt is enabled try to decrypt the message */ 842 842 if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) { 843 char *out; 844 int ret; 845 846 out=owl_malloc(strlen(owl_message_get_body(m))*16+20); 847 ret=owl_zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m)); 848 if (ret == 0) 843 char *out = owl_zcrypt_decrypt(owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m)); 844 if (out) { 849 845 owl_message_set_body(m, out); 850 owl_free(out); 846 owl_free(out); 847 } 851 848 } 852 849 #endif -
zcrypt.c
rb22170c r54e1fe4 76 76 /* The 'owl_zcrypt_decrypt' function was written by kretch for Owl. 77 77 * Decrypt the message in 'in' on class 'class' and instance 78 * 'instance' and leave the result in 'out'. Out must be a buffer 79 * allocated by the caller. 80 * 81 * return 0 on success, otherwise -1 78 * 'instance'. Return must be freed by caller. 82 79 */ 83 int owl_zcrypt_decrypt(char *out, const char *in, const char *class, const char *instance) { 80 char *owl_zcrypt_decrypt(const char *in, const char *class, const char *instance) 81 { 84 82 const char *inptr, *endptr; 85 83 char *fname, keystring[MAX_KEY]; 86 84 FILE *fkey; 87 85 des_key_schedule schedule; 86 char *out; 88 87 unsigned char input[8], output[8]; 89 88 int i, c1, c2; 90 89 91 90 fname=GetZephyrVarKeyFile("zcrypt", class, instance); 92 if (!fname) return (-1);91 if (!fname) return NULL; 93 92 fkey=fopen(fname, "r"); 94 if (!fkey) return (-1);93 if (!fkey) return NULL; 95 94 if (!fgets(keystring, MAX_KEY-1, fkey)) { 96 95 fclose(fkey); 97 return -1;96 return NULL; 98 97 } 99 98 fclose(fkey); 100 99 100 out = owl_malloc(strlen(in) * 16 + 20); 101 101 strcpy(out, ""); 102 102 … … 120 120 if (out[0] && out[strlen(out) - 1] != '\n') 121 121 strcat(out, "\n"); 122 return(0); 123 } 124 125 int owl_zcrypt_encrypt(char *out, const char *in, const char *class, const char *instance) { 122 return out; 123 } 124 125 char *owl_zcrypt_encrypt(const char *in, const char *class, const char *instance) 126 { 126 127 char *fname, keystring[MAX_KEY]; 127 128 FILE *fkey; 128 129 des_key_schedule schedule; 130 char *out; 129 131 unsigned char input[8], output[8]; 130 132 int size, length, i; … … 133 135 134 136 fname=GetZephyrVarKeyFile("zcrypt", class, instance); 135 if (!fname) return (-1);137 if (!fname) return NULL; 136 138 fkey=fopen(fname, "r"); 137 if (!fkey) return (-1);139 if (!fkey) return NULL; 138 140 if (!fgets(keystring, MAX_KEY-1, fkey)) { 139 141 fclose(fkey); 140 return -1;142 return NULL; 141 143 } 142 144 fclose(fkey); 143 145 144 146 owl_zcrypt_string_to_schedule(keystring, &schedule); 147 148 /* Allocate enough space for the crypted message. For each byte of 149 * the message, the encoded cyphertext will have two bytes. Block 150 * size is 8 bytes of input, or 16 bytes of output, so make sure we 151 * have at least one block worth of space allocated. If the message 152 * is empty, no blocks are sent, but we still allocate one 153 * block. The additional 16 bytes also provide space for the null 154 * terminator, as we will never use all of it for cyphertext. 155 */ 156 out = owl_malloc((strlen(in) * 2) + 16); 145 157 146 158 inbuff=in; … … 182 194 if (size < 8) break; 183 195 } 184 return (0);196 return out; 185 197 } 186 198
Note: See TracChangeset
for help on using the changeset viewer.