From fb395c3f01bad1a597af37758818a43d2f76e85f Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Mon, 10 Jun 2013 17:03:32 +0800 Subject: [PATCH] Cleanup encryption key setting by moving core to file. --- crypt.c | 39 ++------------------------------------- crypt.h | 5 ++++- ebind.c | 1 - file.c | 41 +++++++++++++++++++++++++++++++++++++---- file.h | 5 +++++ main.c | 6 ++---- names.c | 1 - 7 files changed, 50 insertions(+), 48 deletions(-) diff --git a/crypt.c b/crypt.c index 70b2fb5..3384410 100644 --- a/crypt.c +++ b/crypt.c @@ -9,47 +9,12 @@ * written by Dana Hoggatt and Daniel Lawrence */ -#include -#include "display.h" -#include "estruct.h" -#include "edef.h" -#include "input.h" - #if CRYPT +#include + static int mod95(int); -/* - * reset encryption key of current buffer - * - * int f; default flag - * int n; numeric argument - */ -int set_encryption_key(int f, int n) -{ - int status; /* return status */ - int odisinp; /* original vlaue of disinp */ - char key[NPAT]; /* new encryption string */ - - /* turn command input echo off */ - odisinp = disinp; - disinp = FALSE; - - /* get the string to use as an encrytion string */ - status = mlreply("Encryption String: ", key, NPAT - 1); - disinp = odisinp; - if (status != TRUE) - return status; - - /* and encrypt it */ - myencrypt((char *) NULL, 0); - myencrypt(key, strlen(key)); - - /* and save it off */ - strcpy(curbp->b_key, key); - mlwrite(" "); /* clear it off the bottom line */ - return TRUE; -} /********** * diff --git a/crypt.h b/crypt.h index 18951c2..7cfbaca 100644 --- a/crypt.h +++ b/crypt.h @@ -1,7 +1,10 @@ #ifndef _CRYPT_H_ #define _CRYPT_H_ -int set_encryption_key( int f, int n) ; +#include "estruct.h" + +#if CRYPT void myencrypt( char *bptr, unsigned len) ; +#endif #endif diff --git a/ebind.c b/ebind.c index 2f9e9ad..c43ab92 100644 --- a/ebind.c +++ b/ebind.c @@ -12,7 +12,6 @@ #include "bind.h" #include "bindable.h" #include "buffer.h" -#include "crypt.h" #include "eval.h" #include "exec.h" #include "file.h" diff --git a/file.c b/file.c index fc3a9a3..4312fc2 100644 --- a/file.c +++ b/file.c @@ -119,6 +119,41 @@ int viewfile(int f, int n) } #if CRYPT +void cryptbufferkey( struct buffer *bp) { + myencrypt( (char *) NULL, 0) ; + myencrypt( bp->b_key, strlen( bp->b_key)) ; +} + +/* + * reset encryption key of current buffer + * + * int f; default flag + * int n; numeric argument + */ +int set_encryption_key(int f, int n) +{ + int status; /* return status */ + int odisinp; /* original vlaue of disinp */ + char key[NPAT]; /* new encryption string */ + + /* turn command input echo off */ + odisinp = disinp; + disinp = FALSE; + + /* get the string to use as an encrytion string */ + status = mlreply("Encryption String: ", key, NPAT - 1); + disinp = odisinp; + if (status != TRUE) + return status; + + /* save it off and encrypt it*/ + strcpy(curbp->b_key, key); + cryptbufferkey( curbp) ; + + mlwrite(" "); /* clear it off the bottom line */ + return TRUE; +} + static int resetkey(void) { /* reset the encryption key if needed */ int s; /* return status */ @@ -139,12 +174,10 @@ static int resetkey(void) /* and set up the key to be used! */ /* de-encrypt it */ - myencrypt((char *) NULL, 0); - myencrypt(curbp->b_key, strlen(curbp->b_key)); + cryptbufferkey( curbp) ; /* re-encrypt it...seeding it to start */ - myencrypt((char *) NULL, 0); - myencrypt(curbp->b_key, strlen(curbp->b_key)); + cryptbufferkey( curbp) ; } return TRUE; diff --git a/file.h b/file.h index 886ce52..f2f1d55 100644 --- a/file.h +++ b/file.h @@ -1,6 +1,11 @@ #ifndef _FILE_H_ #define _FILE_H_ +#if CRYPT +void cryptbufferkey( struct buffer *bp) ; +int set_encryption_key( int f, int n) ; +#endif + int fileread( int f, int n) ; int insfile( int f, int n) ; int filefind( int f, int n) ; diff --git a/main.c b/main.c index cedd4dc..e6bd8eb 100644 --- a/main.c +++ b/main.c @@ -61,7 +61,6 @@ #include "bind.h" #include "bindable.h" #include "buffer.h" -#include "crypt.h" #include "display.h" #include "edef.h" /* Global definitions. */ #include "estruct.h" /* Global structures and defines. */ @@ -269,9 +268,8 @@ int main(int argc, char **argv) #if CRYPT if (cryptflag) { bp->b_mode |= MDCRYPT; - myencrypt((char *) NULL, 0); - myencrypt(ekey, strlen(ekey)); - strncpy(bp->b_key, ekey, NPAT); + strncpy( bp->b_key, ekey, NPAT) ; + cryptbufferkey( bp) ; } #endif } diff --git a/names.c b/names.c index 82dfa0b..e451240 100644 --- a/names.c +++ b/names.c @@ -15,7 +15,6 @@ #include "display.h" #include "eval.h" #include "exec.h" -#include "crypt.h" #include "file.h" #include "isearch.h" #include "line.h"