aboutsummarylogtreecommitdiffstats
path: root/rc4.h
diff options
context:
space:
mode:
Diffstat (limited to 'rc4.h')
-rw-r--r--rc4.h68
1 files changed, 51 insertions, 17 deletions
diff --git a/rc4.h b/rc4.h
index 5e864db0f39b..7f6a9eec428f 100644
--- a/rc4.h
+++ b/rc4.h
@@ -13,43 +13,77 @@
#include "string-tick.h"
/**
- * Takes a password from user input and returns it (max 32 chars)
- * @return password
+ * Returns a password string taken from user input with a maximum of 32 characters. The user's input
+ * should not be echoed in the terminal, so ncurses noecho() function should be used.
+ * @return the password taken from input
*/
char* rc4_getPassword(void);
/**
- * Performs key exchange
- * @param keySchedule
- * @param key password
+ * Precondition: keySchedule is an int array of size 256 and key is a valid string
+ * Postcondition: keySchedule values have been initialized by the RC4 key-scheduling algorithm.
+ * Performs the RC4 key exchange with keylength 256. Pseudocode example:
+ * for i from 0 to 255
+ * S[i] := i
+ * endfor
+ * j := 0
+ * for i from 0 to 255
+ * j := (j + S[i] + key[i mod keylength]) mod 256
+ swap values of S[i] and S[j]
+ * endfor
+ *
+ * @param keySchedule int array of size keylength
+ * @param key user given password
*/
void rc4_key_exchange(int keySchedule[KEY_SCHEDULE_LENGTH], char* key);
/**
- * Performs pseudo-random generation algorithm
- * @param keySchedule
+ * Precondition: keySchedule is an int array of size 256 already initialized by the RC4 key-scheduling algorithm
+ * Performs the RC4 pseudo-random generation algorithm with keylength 256. Returns a string of length len with output
+ * frm this algorithm. Pseudocode example:
+ * i := 0
+ * j := 0
+ * while GeneratingOutput:
+ * i := (i + 1) mod 256
+ * j := (j + S[i]) mod 256
+ * swap values of S[i] and S[j]
+ * K := S[(S[i] + S[j]) mod 256]
+ * output K
+ * endwhile
+ *
+ * @param keySchedule int array of size keylength (already initialized)
* @param len size of portfolio in bytes
- * @return string that can be XOR'ed with message to be en/decoded
+ * @return string of size len that can be XOR'ed with message to be en/decoded
*/
char* rc4_prga(int keySchedule[KEY_SCHEDULE_LENGTH], size_t len);
/**
- * XOR's the string created by prga by the portfolio to encrypt or decrypt it
- * @param output string to be XOR'ed
- * @param message portoflio string
- * @param len length of portfolio in bytes
+ * Precondition: output is a string containing the output of the RC4 pseudo-random generation algorithm. pString
+ * is a String object containing the portfolio.
+ * XOR's the each index of output by each index of the char* in pString and stores that in the index of output
+ * @param output string
+ * @param message portoflio String
*/
void rc4_execute(char* output, String* pString);
/**
- * Returns an either encrypted or decrypted string of the input
- * @param input the string to encrypt or decrypt
- * @param input_len the length of the string
- * @param password the password to encrypt or decrypt with
- * @return encrypted or decrypted string
+ * Returns an encoded string given a String object and password used to encode it.
+ * @param pString The String to encode.
+ * @param password the key used to encode
+ * @return encoded string
*/
char* rc4_encode_string(String* pString, char* password);
+/**
+ * Given input input_pString, returns an encrypted or decrypted version of it. If trying to encrypt a non-JSON
+ * formatted input_pString, abort. Similarly, if trying to decrypt a JSON-formatted input_pString, abort. password may
+ * be a string or NULL. If NULL, get a password from the user if encrypting, ask for the password again to confirm
+ * inputs are the same. If decrypting and the decrypted String is not JSON formatted, abort (wrong password).
+ * @param input_pString the String to encrypt/decrypt
+ * @param password the key or NULL
+ * @param option ENCRYPT or DECRYPT
+ * @return encrypted or decrypted String
+ */
String* rc4_get_crypted_string(String* input_pString, char* password, int option);
#endif \ No newline at end of file