//This program is free software: you can redistribute it and/or modify it under the terms #of the GNU General Public License as published by the Free Software Foundation, either #version 3 of the License, or (at your option) any later version. //This program is distributed in the hope that it will be useful, but WITHOUT ANY #WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A #PARTICULAR PURPOSE. See the GNU General Public License for more details. //You should have received a copy of the GNU General Public License along with this #program. If not, see #ifndef TINYRSA_H #define TINYRSA_H /* tinyRSA.c */ /* RSA cipher: tiny version with 4-5 digit keys and cipher block chaining */ /* Unless otherwise noted Copyright 1995 Willis E. Howard, III */ /* Willis E. Howard, III email: WEHoward@aol.com mail: POB 1473 Elkhart, IN 46515 */ /* RSA cipher under U.S. patent 4405829 will expire September 20, 2000 */ /* tinyRSA should be considered only an educational tool because the */ /* small number of digits used in the key make decryption trivial. */ /* Use of this program is not in violation of U.S. patent 4405829 */ /* because it does not perform public key cryptography. */ /* Program TINYKEY should be used to generate public and private keys. */ /* Program TINYSOLV can generate private keys from public keys. */ /* If a version of TINYSOLV could be written for 200 digit keys, */ /* no current version of RSA would be secure. */ /* Theory of RSA: Choose two really large prime numbers p and q. (This program uses really small prime numbers p and q.) Then, p * q = n, where modulus n should have 150-200 digits. Select a random number e subject to the condition that e and (p-1)(q-1) are relatively prime, or gcd(e,(p-1)(q-1)) = 1. Finally, solve for d where e * d = 1 mod((p-1)(q-1)). We have e and n as public keys, d and n as private keys. The above procedure is done by key selection software. To encrypt message block x, calculate y = x^e mod(n). Tell everybody -- even your brother -- the values e and n. They can use the above formula to send you encrypted messages. To decrypt message block y, calculate x = y^d mod(n). Don't tell anybody the value of d. As long as n is over 120 digits, state of the art can not get d from e and n. The message blocks should have a length just short of the length of n. */ /* under MSDOS, NMAKE /F TINYRSA.MAK all clean */ /* Note: Encrypted files double in size. This is a side effect of the way that tinyRSA is implemented. With a little bit packing, the size of the encrypted files could be made smaller. But, this is such an insecure implementation that you shouldn't be using it for anything serious anyway. */ #include #include #include "crypt.h" #include #include #include /* This routine uses the common interface to CRYPT.C. Generally, the name of this module becomes the name of the executable file. */ int process_key ( char * ); long modexp_l ( long, long, long ); char ** crypt_help_tinyrsa (); /* crypt_key: Get the key from the passed string (that may be a file name in some implementations) or from a key file name. Return 0 on success but exit on error. */ int crypt_key_tinyrsa (int key_type, char *key_text); /* crypt_key_erase: If a local copy of the key has been made, erase it from memory. This increases security that the key can not be obtained from an examination of memory. */ void crypt_key_erase_tinyrsa (); /* crypt_select: If encryption and decryption require different ciphers, this routine defines the direction. Valid choices are ENCRYPTION_SELECT and DECRYPTION_SELECT. */ int crypt_select_tinyrsa (int selection); /* crypt_file: encrypt or decrypt the source to the destination file. Do not exit from this routine. Return 0 on success and return 1 on error. Use an fprintf(stderr, ... ) to report the nature of the error and close any open files. This allows the main routine to do some cleanup before exiting. */ int crypt_file_tinyrsa (char *source, char *dest); //int process_key(char *p); //long modexp_l(long a, long x, long n); #endif // TINYRSA_H