From e4db7671a91a7552c642acc979f0eb278f8d467f Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 28 Feb 2011 23:43:21 +0100 Subject: [PATCH] Rename struct rc4_context and stream cipher send/receive functions. This only changes the name structures and functions. Unfortunately, the patch is rather large since it requires to fixup all callers of the affected functions. However, each change is either a simple rename or a trivial documentation adjustment. --- afs.c | 30 +++++++++---------- afs.cmd | 10 +++---- afs.h | 2 +- aft.c | 52 ++++++++++++++++---------------- attribute.c | 28 +++++++++--------- blob.c | 36 +++++++++++----------- client.h | 4 +-- client_common.c | 63 +++++++++++++++++++-------------------- command.c | 79 ++++++++++++++++++++++++------------------------- command.h | 2 +- crypt.c | 56 ++++++++++++++++++----------------- crypt.h | 21 +++++++------ 12 files changed, 193 insertions(+), 190 deletions(-) diff --git a/afs.c b/afs.c index c5a088cb..337045c9 100644 --- a/afs.c +++ b/afs.c @@ -580,22 +580,22 @@ out: * Result handler for sending data to the para_client process. * * \param result The data to be sent. - * \param private Pointer to rc4 context. + * \param private Pointer to the context. * - * \return The return value of the underlying call to rc4_send_bin_buffer(). + * \return The return value of the underlying call to sc_send_bin_buffer(). * - * \sa \ref callback_result_handler, \ref rc4_send_bin_buffer(). + * \sa \ref callback_result_handler, \ref sc_send_bin_buffer(). */ -int rc4_send_result(struct osl_object *result, void *private) +int sc_send_result(struct osl_object *result, void *private) { - struct rc4_context *rc4c = private; + struct stream_cipher_context *scc = private; if (!result->size) return 1; - return rc4_send_bin_buffer(rc4c, result->data, result->size); + return sc_send_bin_buffer(scc, result->data, result->size); } -int com_select(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_select(struct stream_cipher_context *scc, int argc, char * const * const argv) { struct osl_object query; @@ -604,7 +604,7 @@ int com_select(struct rc4_context *rc4c, int argc, char * const * const argv) query.data = argv[1]; query.size = strlen(argv[1]) + 1; return send_callback_request(com_select_callback, &query, - &rc4_send_result, rc4c); + &sc_send_result, scc); } static void init_admissible_files(char *arg) @@ -1018,7 +1018,7 @@ out: free(pb.buf); } -int com_init(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_init(struct stream_cipher_context *scc, int argc, char * const * const argv) { int i, j, ret; uint32_t table_mask = (1 << (NUM_AFS_TABLES + 1)) - 1; @@ -1044,9 +1044,9 @@ int com_init(struct rc4_context *rc4c, int argc, char * const * const argv) } } ret = send_callback_request(create_tables_callback, &query, - rc4_send_result, rc4c); + sc_send_result, scc); if (ret < 0) - return rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret)); + return sc_send_va_buffer(scc, "%s\n", para_strerror(-ret)); return ret; } @@ -1064,7 +1064,7 @@ enum com_check_flags { CHECK_PLAYLISTS = 4 }; -int com_check(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_check(struct stream_cipher_context *scc, int argc, char * const * const argv) { unsigned flags = 0; int i, ret; @@ -1097,19 +1097,19 @@ int com_check(struct rc4_context *rc4c, int argc, char * const * const argv) flags = ~0U; if (flags & CHECK_AFT) { ret = send_callback_request(aft_check_callback, NULL, - rc4_send_result, rc4c); + sc_send_result, scc); if (ret < 0) return ret; } if (flags & CHECK_PLAYLISTS) { ret = send_callback_request(playlist_check_callback, - NULL, rc4_send_result, rc4c); + NULL, sc_send_result, scc); if (ret < 0) return ret; } if (flags & CHECK_MOODS) { ret = send_callback_request(mood_check_callback, NULL, - rc4_send_result, rc4c); + sc_send_result, scc); if (ret < 0) return ret; } diff --git a/afs.cmd b/afs.cmd index 8a2ae3b3..22a0786b 100644 --- a/afs.cmd +++ b/afs.cmd @@ -260,7 +260,7 @@ H: loads the mood named 'foo'. --- T: add N: add@member@ -O: int com_add@member@(struct rc4_context *rc4c, int argc, char * const * const argv); +O: int com_add@member@(struct stream_cipher_context *scc, int argc, char * const * const argv); P: AFS_READ | AFS_WRITE D: Read data from stdin and add it as a blob to the @member@ table. U: add@member@ @member@_name @@ -273,7 +273,7 @@ H: given name already exists, its contents are replaced by the new data. --- T: cat N: cat@member@ -O: int com_cat@member@(struct rc4_context *rc4c, int argc, char * const * const argv); +O: int com_cat@member@(struct stream_cipher_context *scc, int argc, char * const * const argv); P: AFS_READ D: Dump the contents of a blob of type @member@ to stdout. U: cat@member@ @member@_name @@ -283,7 +283,7 @@ H: they were previously added. --- T: ls N: ls@member@ -O: int com_ls@member@(struct rc4_context *rc4c, int argc, char * const * const argv); +O: int com_ls@member@(struct stream_cipher_context *scc, int argc, char * const * const argv); P: AFS_READ D: List blobs of type @member@ matching a pattern. U: ls@member@ [-i] [-l] [-r] [pattern] @@ -303,7 +303,7 @@ H: -r Reverse sort order. --- T: rm N: rm@member@ -O: int com_rm@member@(struct rc4_context *rc4c, int argc, char * const * const argv); +O: int com_rm@member@(struct stream_cipher_context *scc, int argc, char * const * const argv); P: AFS_READ | AFS_WRITE D: Remove blob(s) of type @member@ from the @member@ table. U: rm@member@ pattern... @@ -312,7 +312,7 @@ H: any given pattern. --- T: mv N: mv@member@ -O: int com_mv@member@(struct rc4_context *rc4c, int argc, char * const * const argv); +O: int com_mv@member@(struct stream_cipher_context *scc, int argc, char * const * const argv); P: AFS_READ | AFS_WRITE D: Rename a blob of type @member@. U: mv@member@ old_@member@_name new_@member@_name diff --git a/afs.h b/afs.h index 96da2da0..7a93183e 100644 --- a/afs.h +++ b/afs.h @@ -205,7 +205,7 @@ typedef void callback_function(int fd, const struct osl_object *); * \sa \ref send_callback_request(). */ typedef int callback_result_handler(struct osl_object *result, void *private); -int rc4_send_result(struct osl_object *result, void *private); +int sc_send_result(struct osl_object *result, void *private); int pass_buffer_as_shm(char *buf, size_t size, void *fd_ptr); __noreturn void afs_init(uint32_t cookie, int socket_fd); diff --git a/aft.c b/aft.c index 3b2f9172..6aace3ae 100644 --- a/aft.c +++ b/aft.c @@ -1396,7 +1396,7 @@ out: /* * TODO: flags -h (sort by hash) */ -int com_ls(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_ls(struct stream_cipher_context *scc, int argc, char * const * const argv) { int i, ret; unsigned flags = 0; @@ -1508,7 +1508,7 @@ int com_ls(struct rc4_context *rc4c, int argc, char * const * const argv) opts.mode = mode; opts.num_patterns = argc - i; ret = send_option_arg_callback_request(&query, opts.num_patterns, - argv + i, com_ls_callback, rc4_send_result, rc4c); + argv + i, com_ls_callback, sc_send_result, scc); return ret; } @@ -1795,8 +1795,8 @@ out: /** Used by com_add(). */ struct private_add_data { - /** The socket file descriptor, including rc4 keys. */ - struct rc4_context *rc4c; + /** The socket file descriptor, including stream cipher keys. */ + struct stream_cipher_context *scc; /** The given add flags. */ uint32_t flags; }; @@ -1851,7 +1851,7 @@ static int add_one_audio_file(const char *path, void *private_data) ret = 1; if (pb && (pad->flags & ADD_FLAG_LAZY)) { /* lazy is really cheap */ if (pad->flags & ADD_FLAG_VERBOSE) - send_ret = rc4_send_va_buffer(pad->rc4c, + send_ret = sc_send_va_buffer(pad->scc, "lazy-ignore: %s\n", path); goto out_free; } @@ -1872,7 +1872,7 @@ static int add_one_audio_file(const char *path, void *private_data) ret = 1; if (pb && hs && hs == pb && !(pad->flags & ADD_FLAG_FORCE)) { if (pad->flags & ADD_FLAG_VERBOSE) - send_ret = rc4_send_va_buffer(pad->rc4c, + send_ret = sc_send_va_buffer(pad->scc, "%s exists, not forcing update\n", path); goto out_unmap; } @@ -1890,13 +1890,13 @@ static int add_one_audio_file(const char *path, void *private_data) munmap(map.data, map.size); close(fd); if (pad->flags & ADD_FLAG_VERBOSE) { - send_ret = rc4_send_va_buffer(pad->rc4c, "adding %s\n", path); + send_ret = sc_send_va_buffer(pad->scc, "adding %s\n", path); if (send_ret < 0) goto out_free; } save_add_callback_buffer(hash, path, afhi_ptr, pad->flags, format_num, &obj); /* Ask afs to consider this entry for adding. */ - ret = send_callback_request(com_add_callback, &obj, rc4_send_result, pad->rc4c); + ret = send_callback_request(com_add_callback, &obj, sc_send_result, pad->scc); goto out_free; out_unmap: @@ -1904,7 +1904,7 @@ out_unmap: munmap(map.data, map.size); out_free: if (ret < 0 && send_ret >= 0) - send_ret = rc4_send_va_buffer(pad->rc4c, + send_ret = sc_send_va_buffer(pad->scc, "failed to add %s (%s)\n", path, para_strerror(-ret)); free(obj.data); if (afhi_ptr) { @@ -1920,10 +1920,10 @@ out_free: return send_ret; } -int com_add(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_add(struct stream_cipher_context *scc, int argc, char * const * const argv) { int i, ret; - struct private_add_data pad = {.rc4c = rc4c, .flags = 0}; + struct private_add_data pad = {.scc = scc, .flags = 0}; struct stat statbuf; for (i = 1; i < argc; i++) { @@ -1957,7 +1957,7 @@ int com_add(struct rc4_context *rc4c, int argc, char * const * const argv) char *path; ret = verify_path(argv[i], &path); if (ret < 0) { - ret = rc4_send_va_buffer(rc4c, "%s: %s\n", argv[i], + ret = sc_send_va_buffer(scc, "%s: %s\n", argv[i], para_strerror(-ret)); if (ret < 0) return ret; @@ -1965,7 +1965,7 @@ int com_add(struct rc4_context *rc4c, int argc, char * const * const argv) } ret = stat(path, &statbuf); if (ret < 0) { - ret = rc4_send_va_buffer(rc4c, "failed to stat %s (%s)\n", path, + ret = sc_send_va_buffer(scc, "failed to stat %s (%s)\n", path, strerror(errno)); free(path); if (ret < 0) @@ -1978,7 +1978,7 @@ int com_add(struct rc4_context *rc4c, int argc, char * const * const argv) else ret = add_one_audio_file(path, &pad); if (ret < 0) { - rc4_send_va_buffer(rc4c, "%s: %s\n", path, para_strerror(-ret)); + sc_send_va_buffer(scc, "%s: %s\n", path, para_strerror(-ret)); free(path); return ret; } @@ -2110,7 +2110,7 @@ static void com_touch_callback(int fd, const struct osl_object *query) free(tad.pb.buf); } -int com_touch(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_touch(struct stream_cipher_context *scc, int argc, char * const * const argv) { struct com_touch_options cto = { .num_played = -1, @@ -2178,9 +2178,9 @@ int com_touch(struct rc4_context *rc4c, int argc, char * const * const argv) if (i >= argc) return -E_AFT_SYNTAX; ret = send_option_arg_callback_request(&query, argc - i, - argv + i, com_touch_callback, rc4_send_result, rc4c); + argv + i, com_touch_callback, sc_send_result, scc); if (ret < 0) - rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret)); + sc_send_va_buffer(scc, "%s\n", para_strerror(-ret)); return ret; } @@ -2262,7 +2262,7 @@ static void com_rm_callback(int fd, const struct osl_object *query) } /* TODO options: -r (recursive) */ -int com_rm(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_rm(struct stream_cipher_context *scc, int argc, char * const * const argv) { uint32_t flags = 0; struct osl_object query = {.data = &flags, .size = sizeof(flags)}; @@ -2293,9 +2293,9 @@ int com_rm(struct rc4_context *rc4c, int argc, char * const * const argv) if (i >= argc) return -E_AFT_SYNTAX; ret = send_option_arg_callback_request(&query, argc - i, argv + i, - com_rm_callback, rc4_send_result, rc4c); + com_rm_callback, sc_send_result, scc); if (ret < 0) - rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret)); + sc_send_va_buffer(scc, "%s\n", para_strerror(-ret)); return ret; } @@ -2410,7 +2410,7 @@ out: free(cad.pb.buf); } -int com_cpsi(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_cpsi(struct stream_cipher_context *scc, int argc, char * const * const argv) { unsigned flags = 0; int i, ret; @@ -2455,9 +2455,9 @@ int com_cpsi(struct rc4_context *rc4c, int argc, char * const * const argv) if (!(flags & ~CPSI_FLAG_VERBOSE)) /* no copy flags given */ flags = ~(unsigned)CPSI_FLAG_VERBOSE | flags; ret = send_option_arg_callback_request(&options, argc - i, argv + i, - com_cpsi_callback, rc4_send_result, rc4c); + com_cpsi_callback, sc_send_result, scc); if (ret < 0) - rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret)); + sc_send_va_buffer(scc, "%s\n", para_strerror(-ret)); return ret; } @@ -2475,7 +2475,7 @@ static void afs_stat_callback(int fd, const struct osl_object *query) /** * Get the current afs status items from the afs process and send it using RC4. * - * \param rc4c The rc4 context for data encryption. + * \param scc The stream cipher context for data encryption. * \param parser_friendly Whether parser-friendly output format should be used. * * As the contents of the afs status items change in time and the command @@ -2484,12 +2484,12 @@ static void afs_stat_callback(int fd, const struct osl_object *query) * is used to pass the status items from the afs process to the command handler * via a shared memory area and a pipe. */ -int send_afs_status(struct rc4_context *rc4c, int parser_friendly) +int send_afs_status(struct stream_cipher_context *scc, int parser_friendly) { struct osl_object query = {.data = &parser_friendly, .size = sizeof(parser_friendly)}; - return send_callback_request(afs_stat_callback, &query, rc4_send_result, rc4c); + return send_callback_request(afs_stat_callback, &query, sc_send_result, scc); } /* TODO: optionally fix problems by removing offending rows */ diff --git a/attribute.c b/attribute.c index bef25fc0..4c664996 100644 --- a/attribute.c +++ b/attribute.c @@ -176,7 +176,7 @@ static void com_lsatt_callback(int fd, const struct osl_object *query) free(laad.pb.buf); } -int com_lsatt(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_lsatt(struct stream_cipher_context *scc, int argc, char * const * const argv) { unsigned flags = 0; struct osl_object options = {.data = &flags, .size = sizeof(flags)}; @@ -204,12 +204,12 @@ int com_lsatt(struct rc4_context *rc4c, int argc, char * const * const argv) } } ret = send_option_arg_callback_request(&options, argc - i, argv + i, - com_lsatt_callback, rc4_send_result, rc4c); + com_lsatt_callback, sc_send_result, scc); if (!ret) { if (argc > 1) - ret = rc4_send_va_buffer(rc4c, "no matches\n"); + ret = sc_send_va_buffer(scc, "no matches\n"); } else if (ret < 0) - rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret)); + sc_send_va_buffer(scc, "%s\n", para_strerror(-ret)); return ret; } @@ -277,7 +277,7 @@ out: PARA_NOTICE_LOG("%s\n", para_strerror(-ret)); } -int com_setatt(__a_unused struct rc4_context *rc4c, int argc, char * const * const argv) +int com_setatt(__a_unused struct stream_cipher_context *scc, int argc, char * const * const argv) { if (argc < 3) return -E_ATTR_SYNTAX; @@ -358,16 +358,16 @@ out: free(pb.buf); } -int com_addatt(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_addatt(struct stream_cipher_context *scc, int argc, char * const * const argv) { int ret; if (argc < 2) return -E_ATTR_SYNTAX; ret = send_standard_callback_request(argc - 1, argv + 1, com_addatt_callback, - rc4_send_result, rc4c); + sc_send_result, scc); if (ret < 0) - rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret)); + sc_send_va_buffer(scc, "%s\n", para_strerror(-ret)); return ret; } @@ -401,16 +401,16 @@ out: free(pb.buf); } -int com_mvatt(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_mvatt(struct stream_cipher_context *scc, int argc, char * const * const argv) { int ret; if (argc != 3) return -E_ATTR_SYNTAX; ret = send_standard_callback_request(argc - 1, argv + 1, com_mvatt_callback, - rc4_send_result, rc4c); + sc_send_result, scc); if (ret < 0) - rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret)); + sc_send_va_buffer(scc, "%s\n", para_strerror(-ret)); return ret; } @@ -473,16 +473,16 @@ static void com_rmatt_callback(int fd, const struct osl_object *query) free(raad.pb.buf); } -int com_rmatt(struct rc4_context *rc4c, int argc, char * const * const argv) +int com_rmatt(struct stream_cipher_context *scc, int argc, char * const * const argv) { int ret; if (argc < 2) return -E_ATTR_SYNTAX; ret = send_standard_callback_request(argc - 1, argv + 1, com_rmatt_callback, - rc4_send_result, rc4c); + sc_send_result, scc); if (ret < 0) - rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret)); + sc_send_va_buffer(scc, "%s\n", para_strerror(-ret)); return ret; } diff --git a/blob.c b/blob.c index cefd0288..dfe4e374 100644 --- a/blob.c +++ b/blob.c @@ -161,7 +161,7 @@ static void com_lsblob_callback(struct osl_table *table, free(lbad.pb.buf); } -static int com_lsblob(callback_function *f, struct rc4_context *rc4c, int argc, char * const * const argv) +static int com_lsblob(callback_function *f, struct stream_cipher_context *scc, int argc, char * const * const argv) { uint32_t flags = 0; struct osl_object options = {.data = &flags, .size = sizeof(flags)}; @@ -192,7 +192,7 @@ static int com_lsblob(callback_function *f, struct rc4_context *rc4c, int argc, // if (argc > i) // return -E_BLOB_SYNTAX; return send_option_arg_callback_request(&options, argc - i, - argv + i, f, rc4_send_result, rc4c); + argv + i, f, sc_send_result, scc); } static int cat_blob(struct osl_table *table, struct osl_row *row, @@ -225,13 +225,13 @@ static void com_catblob_callback(struct osl_table *table, int fd, for_each_matching_row(&pmd); } -static int com_catblob(callback_function *f, struct rc4_context *rc4c, int argc, +static int com_catblob(callback_function *f, struct stream_cipher_context *scc, int argc, char * const * const argv) { if (argc < 2) return -E_BLOB_SYNTAX; return send_standard_callback_request(argc - 1, argv + 1, f, - rc4_send_result, rc4c); + sc_send_result, scc); } /** Used for removing rows from a blob table. */ @@ -294,13 +294,13 @@ out: free(rmbd.pb.buf); } -static int com_rmblob(callback_function *f, struct rc4_context *rc4c, int argc, +static int com_rmblob(callback_function *f, struct stream_cipher_context *scc, int argc, char * const * const argv) { if (argc < 2) return -E_MOOD_SYNTAX; return send_option_arg_callback_request(NULL, argc - 1, argv + 1, f, - rc4_send_result, rc4c); + sc_send_result, scc); } static void com_addblob_callback(struct osl_table *table, __a_unused int fd, @@ -376,7 +376,7 @@ out: * write input from fd to dynamically allocated buffer, * but maximal max_size byte. */ -static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object *obj) +static int fd2buf(struct stream_cipher_context *scc, unsigned max_size, struct osl_object *obj) { const size_t chunk_size = 1024; size_t size = 2048, received = 0; @@ -384,7 +384,7 @@ static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object char *buf = para_malloc(size); for (;;) { - ret = rc4_recv_bin_buffer(rc4c, buf + received, chunk_size); + ret = sc_recv_bin_buffer(scc, buf + received, chunk_size); if (ret <= 0) break; received += ret; @@ -406,7 +406,7 @@ static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object /* * Read data from a file descriptor, and send it to the afs process. * - * \param rc4c crypt context containing the file descriptor to read data from. + * \param scc crypt context containing the file descriptor to read data from. * \param arg_obj Pointer to the arguments to \a f. * \param f The callback function. * \param max_len Don't read more than that many bytes from stdin. @@ -416,14 +416,14 @@ static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object * This function is used by commands that wish to let para_server store * arbitrary data specified by the user (for instance the add_blob family of * commands). First, at most \a max_len bytes are read and decrypted from the - * file descriptor given by \a rc4c. The result is concatenated with the buffer + * file descriptor given by \a scc. The result is concatenated with the buffer * given by \a arg_obj, and the combined buffer is made available to the afs * process via the callback method. See \ref send_callback_request for details. * * \return Negative on errors, the return value of the underlying call to * send_callback_request() otherwise. */ -static int stdin_command(struct rc4_context *rc4c, struct osl_object *arg_obj, +static int stdin_command(struct stream_cipher_context *scc, struct osl_object *arg_obj, callback_function *f, unsigned max_len, callback_result_handler *result_handler, void *private_result_data) @@ -431,10 +431,10 @@ static int stdin_command(struct rc4_context *rc4c, struct osl_object *arg_obj, struct osl_object query, stdin_obj; int ret; - ret = rc4_send_buffer(rc4c, AWAITING_DATA_MSG); + ret = sc_send_buffer(scc, AWAITING_DATA_MSG); if (ret < 0) return ret; - ret = fd2buf(rc4c, max_len, &stdin_obj); + ret = fd2buf(scc, max_len, &stdin_obj); if (ret < 0) return ret; query.size = arg_obj->size + stdin_obj.size; @@ -447,7 +447,7 @@ static int stdin_command(struct rc4_context *rc4c, struct osl_object *arg_obj, return ret; } -static int com_addblob(callback_function *f, struct rc4_context *rc4c, int argc, +static int com_addblob(callback_function *f, struct stream_cipher_context *scc, int argc, char * const * const argv) { struct osl_object arg_obj; @@ -458,7 +458,7 @@ static int com_addblob(callback_function *f, struct rc4_context *rc4c, int argc, return -E_BLOB_SYNTAX; arg_obj.size = strlen(argv[1]) + 1; arg_obj.data = (char *)argv[1]; - return stdin_command(rc4c, &arg_obj, f, 10 * 1024 * 1024, NULL, NULL); + return stdin_command(scc, &arg_obj, f, 10 * 1024 * 1024, NULL, NULL); } /* FIXME: Print output to client, not to log file */ @@ -484,7 +484,7 @@ out: PARA_NOTICE_LOG("%s\n", para_strerror(-ret)); } -static int com_mvblob(callback_function *f, __a_unused struct rc4_context *rc4c, +static int com_mvblob(callback_function *f, __a_unused struct stream_cipher_context *scc, int argc, char * const * const argv) { if (argc != 3) @@ -498,9 +498,9 @@ static int com_mvblob(callback_function *f, __a_unused struct rc4_context *rc4c, { \ return com_ ## cmd_name ## blob_callback(table_name ## _table, fd, query); \ } \ - int com_ ## cmd_name ## cmd_prefix(struct rc4_context *rc4c, int argc, char * const * const argv) \ + int com_ ## cmd_name ## cmd_prefix(struct stream_cipher_context *scc, int argc, char * const * const argv) \ { \ - return com_ ## cmd_name ## blob(com_ ## cmd_name ## cmd_prefix ## _callback, rc4c, argc, argv); \ + return com_ ## cmd_name ## blob(com_ ## cmd_name ## cmd_prefix ## _callback, scc, argc, argv); \ } static int blob_get_name_by_id(struct osl_table *table, uint32_t id, diff --git a/client.h b/client.h index 78cfb5d8..2d63c410 100644 --- a/client.h +++ b/client.h @@ -30,8 +30,8 @@ enum { struct client_task { /** The state of the connection. */ int status; - /** The file descriptor and the rc4 keys. */ - struct rc4_context rc4c; + /** The file descriptor and the session keys. */ + struct stream_cipher_context scc; /** The configuration (including the command). */ struct client_args_info conf; /** The config file for client options. */ diff --git a/client_common.c b/client_common.c index c55db47b..ba419786 100644 --- a/client_common.c +++ b/client_common.c @@ -39,10 +39,10 @@ void client_close(struct client_task *ct) { if (!ct) return; - if (ct->rc4c.fd >= 0) - close(ct->rc4c.fd); - stream_cipher_free(ct->rc4c.recv); - stream_cipher_free(ct->rc4c.send); + if (ct->scc.fd >= 0) + close(ct->scc.fd); + sc_free(ct->scc.recv); + sc_free(ct->scc.send); free(ct->user); free(ct->config_file); free(ct->key_file); @@ -70,19 +70,19 @@ static void client_pre_select(struct sched *s, struct task *t) struct client_task *ct = container_of(t, struct client_task, task); struct btr_node *btrn = ct->btrn; - if (ct->rc4c.fd < 0) + if (ct->scc.fd < 0) return; switch (ct->status) { case CL_CONNECTED: case CL_SENT_AUTH: case CL_SENT_CH_RESPONSE: case CL_SENT_COMMAND: - para_fd_set(ct->rc4c.fd, &s->rfds, &s->max_fileno); + para_fd_set(ct->scc.fd, &s->rfds, &s->max_fileno); return; case CL_RECEIVED_WELCOME: case CL_RECEIVED_PROCEED: - para_fd_set(ct->rc4c.fd, &s->wfds, &s->max_fileno); + para_fd_set(ct->scc.fd, &s->wfds, &s->max_fileno); return; case CL_RECEIVING: @@ -91,7 +91,7 @@ static void client_pre_select(struct sched *s, struct task *t) if (ret < 0) sched_min_delay(s); else - para_fd_set(ct->rc4c.fd, &s->rfds, + para_fd_set(ct->scc.fd, &s->rfds, &s->max_fileno); } return; @@ -101,7 +101,7 @@ static void client_pre_select(struct sched *s, struct task *t) if (ret < 0) sched_min_delay(s); else - para_fd_set(ct->rc4c.fd, &s->wfds, + para_fd_set(ct->scc.fd, &s->wfds, &s->max_fileno); } return; @@ -114,12 +114,12 @@ static int client_recv_buffer(struct client_task *ct, fd_set *rfds, int ret; if (ct->status < CL_SENT_CH_RESPONSE) - return read_nonblock(ct->rc4c.fd, buf, sz, rfds, n); + return read_nonblock(ct->scc.fd, buf, sz, rfds, n); *n = 0; - ret = rc4_recv_buffer(&ct->rc4c, buf, sz); + ret = sc_recv_buffer(&ct->scc, buf, sz); /* - * rc4_recv_buffer is used with blocking fds elsewhere, so it + * sc_recv_buffer is used with blocking fds elsewhere, so it * does not use the nonblock-API. Therefore we need to * check for EOF and EAGAIN. */ @@ -155,7 +155,7 @@ static void client_post_select(struct sched *s, struct task *t) char buf[CLIENT_BUFSIZE]; t->error = 0; - if (ct->rc4c.fd < 0) + if (ct->scc.fd < 0) return; switch (ct->status) { case CL_CONNECTED: /* receive welcome message */ @@ -167,20 +167,20 @@ static void client_post_select(struct sched *s, struct task *t) case CL_RECEIVED_WELCOME: /* send auth command */ sprintf(buf, AUTH_REQUEST_MSG "%s", ct->user); PARA_INFO_LOG("--> %s\n", buf); - if (!FD_ISSET(ct->rc4c.fd, &s->wfds)) + if (!FD_ISSET(ct->scc.fd, &s->wfds)) return; - ret = send_buffer(ct->rc4c.fd, buf); + ret = send_buffer(ct->scc.fd, buf); if (ret < 0) goto out; ct->status = CL_SENT_AUTH; return; case CL_SENT_AUTH: /* - * Receive challenge and rc4 keys, decrypt the challenge and + * Receive challenge and session keys, decrypt the challenge and * send back the hash of the decrypted challenge. */ { - /* decrypted challenge/rc4 buffer */ + /* decrypted challenge/session key buffer */ unsigned char crypt_buf[1024]; /* the SHA1 of the decrypted challenge */ unsigned char challenge_sha1[HASH_SIZE]; @@ -194,13 +194,12 @@ static void client_post_select(struct sched *s, struct task *t) if (ret < 0) goto out; sha1_hash((char *)crypt_buf, CHALLENGE_SIZE, challenge_sha1); - ct->rc4c.send = stream_cipher_new(crypt_buf + CHALLENGE_SIZE, + ct->scc.send = sc_new(crypt_buf + CHALLENGE_SIZE, RC4_KEY_LEN); + ct->scc.recv = sc_new(crypt_buf + CHALLENGE_SIZE + RC4_KEY_LEN, RC4_KEY_LEN); - ct->rc4c.recv = stream_cipher_new(crypt_buf + CHALLENGE_SIZE - + RC4_KEY_LEN, RC4_KEY_LEN); hash_to_asc(challenge_sha1, buf); PARA_INFO_LOG("--> %s\n", buf); - ret = send_bin_buffer(ct->rc4c.fd, (char *)challenge_sha1, + ret = send_bin_buffer(ct->scc.fd, (char *)challenge_sha1, HASH_SIZE); if (ret < 0) goto out; @@ -225,7 +224,7 @@ static void client_post_select(struct sched *s, struct task *t) { int i; char *command = NULL; - if (!FD_ISSET(ct->rc4c.fd, &s->wfds)) + if (!FD_ISSET(ct->scc.fd, &s->wfds)) return; for (i = 0; i < ct->conf.inputs_num; i++) { char *tmp = command; @@ -235,7 +234,7 @@ static void client_post_select(struct sched *s, struct task *t) } command = para_strcat(command, EOC_MSG "\n"); PARA_DEBUG_LOG("--> %s\n", command); - ret = rc4_send_buffer(&ct->rc4c, command); + ret = sc_send_buffer(&ct->scc, command); free(command); if (ret < 0) goto out; @@ -269,10 +268,10 @@ static void client_post_select(struct sched *s, struct task *t) goto out; if (ret == 0) return; - if (!FD_ISSET(ct->rc4c.fd, &s->wfds)) + if (!FD_ISSET(ct->scc.fd, &s->wfds)) return; sz = btr_next_buffer(btrn, &buf2); - ret = rc4_send_bin_buffer(&ct->rc4c, buf2, sz); + ret = sc_send_bin_buffer(&ct->scc, buf2, sz); if (ret < 0) goto out; btr_consume(btrn, sz); @@ -290,7 +289,7 @@ static void client_post_select(struct sched *s, struct task *t) * The FD_ISSET() is not strictly necessary, but is allows us * to skip the malloc below if there is nothing to read anyway. */ - if (!FD_ISSET(ct->rc4c.fd, &s->rfds)) + if (!FD_ISSET(ct->scc.fd, &s->rfds)) return; buf2 = para_malloc(CLIENT_BUFSIZE); ret = client_recv_buffer(ct, &s->rfds, buf2, CLIENT_BUFSIZE, &n); @@ -316,14 +315,14 @@ static int client_connect(struct client_task *ct) { int ret; - ct->rc4c.fd = -1; + ct->scc.fd = -1; ret = para_connect_simple(IPPROTO_TCP, ct->conf.hostname_arg, ct->conf.server_port_arg); if (ret < 0) return ret; - ct->rc4c.fd = ret; + ct->scc.fd = ret; ct->status = CL_CONNECTED; - ret = mark_fd_nonblocking(ct->rc4c.fd); + ret = mark_fd_nonblocking(ct->scc.fd); if (ret < 0) goto err_out; ct->task.pre_select = client_pre_select; @@ -332,8 +331,8 @@ static int client_connect(struct client_task *ct) register_task(&ct->task); return 1; err_out: - close(ct->rc4c.fd); - ct->rc4c.fd = -1; + close(ct->scc.fd); + ct->scc.fd = -1; return ret; } @@ -364,7 +363,7 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr, ct->btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = "client", .parent = parent, .child = child)); *ct_ptr = ct; - ct->rc4c.fd = -1; + ct->scc.fd = -1; ret = -E_CLIENT_SYNTAX; if (client_cmdline_parser(argc, argv, &ct->conf)) goto out; diff --git a/command.c b/command.c index 2c9d29df..34e6494f 100644 --- a/command.c +++ b/command.c @@ -43,7 +43,7 @@ extern int mmd_mutex; extern struct misc_meta_data *mmd; extern struct sender senders[]; -int send_afs_status(struct rc4_context *rc4c, int parser_friendly); +int send_afs_status(struct stream_cipher_context *scc, int parser_friendly); const char *status_item_list[] = {STATUS_ITEM_ARRAY}; @@ -188,7 +188,7 @@ static int check_sender_args(int argc, char * const * argv, struct sender_comman return 1; } -int com_sender(struct rc4_context *rc4c, int argc, char * const * argv) +int com_sender(struct stream_cipher_context *scc, int argc, char * const * argv) { int i, ret; char *msg = NULL; @@ -201,7 +201,7 @@ int com_sender(struct rc4_context *rc4c, int argc, char * const * argv) free(msg); msg = tmp; } - ret = rc4_send_buffer(rc4c, msg); + ret = sc_send_buffer(scc, msg); free(msg); return ret; } @@ -210,7 +210,7 @@ int com_sender(struct rc4_context *rc4c, int argc, char * const * argv) if (scd.sender_num < 0) return ret; msg = senders[scd.sender_num].help(); - ret = rc4_send_buffer(rc4c, msg); + ret = sc_send_buffer(scc, msg); free(msg); return ret; } @@ -239,7 +239,7 @@ int com_sender(struct rc4_context *rc4c, int argc, char * const * argv) } /* server info */ -int com_si(struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_si(struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { int i, ret; char *ut; @@ -254,7 +254,7 @@ int com_si(struct rc4_context *rc4c, int argc, __a_unused char * const * argv) free(info); } ut = uptime_str(); - ret = rc4_send_va_buffer(rc4c, "version: " GIT_VERSION "\n" + ret = sc_send_va_buffer(scc, "version: " GIT_VERSION "\n" "up: %s\nplayed: %u\n" "server_pid: %d\n" "afs_pid: %d\n" @@ -279,11 +279,11 @@ int com_si(struct rc4_context *rc4c, int argc, __a_unused char * const * argv) } /* version */ -int com_version(struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_version(struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { if (argc != 1) return -E_COMMAND_SYNTAX; - return rc4_send_buffer(rc4c, VERSION_TEXT("server") + return sc_send_buffer(scc, VERSION_TEXT("server") "built: " BUILD_DATE "\n" UNAME_RS ", " CC_VERSION "\n" ); @@ -345,7 +345,7 @@ static char *empty_status_items(int parser_friendly) #undef EMPTY_STATUS_ITEMS /* stat */ -int com_stat(struct rc4_context *rc4c, int argc, char * const * argv) +int com_stat(struct stream_cipher_context *scc, int argc, char * const * argv) { int i, ret; struct misc_meta_data tmp, *nmmd = &tmp; @@ -380,7 +380,7 @@ int com_stat(struct rc4_context *rc4c, int argc, char * const * argv) for (;;) { mmd_dup(nmmd); s = get_status(nmmd, parser_friendly); - ret = rc4_send_buffer(rc4c, s); + ret = sc_send_buffer(scc, s); free(s); if (ret < 0) goto out; @@ -388,11 +388,11 @@ int com_stat(struct rc4_context *rc4c, int argc, char * const * argv) static char *esi; if (!esi) esi = empty_status_items(parser_friendly); - ret = rc4_send_buffer(rc4c, esi); + ret = sc_send_buffer(scc, esi); if (ret < 0) goto out; } else - send_afs_status(rc4c, parser_friendly); + send_afs_status(scc, parser_friendly); ret = 1; if (num > 0 && !--num) goto out; @@ -404,14 +404,14 @@ out: return ret; } -static int send_list_of_commands(struct rc4_context *rc4c, struct server_command *cmd, +static int send_list_of_commands(struct stream_cipher_context *scc, struct server_command *cmd, const char *handler) { int ret, i; for (i = 1; cmd->name; cmd++, i++) { char *perms = cmd_perms_itohuman(cmd->perms); - ret = rc4_send_va_buffer(rc4c, "%s\t%s\t%s\t%s\n", cmd->name, + ret = sc_send_va_buffer(scc, "%s\t%s\t%s\t%s\n", cmd->name, handler, perms, cmd->description); @@ -444,7 +444,7 @@ static struct server_command *get_cmd_ptr(const char *name, char **handler) } /* help */ -int com_help(struct rc4_context *rc4c, int argc, char * const * argv) +int com_help(struct stream_cipher_context *scc, int argc, char * const * argv) { struct server_command *cmd; char *perms, *handler; @@ -452,16 +452,16 @@ int com_help(struct rc4_context *rc4c, int argc, char * const * argv) if (argc < 2) { /* no argument given, print list of commands */ - if ((ret = send_list_of_commands(rc4c, server_cmds, "server")) < 0) + if ((ret = send_list_of_commands(scc, server_cmds, "server")) < 0) return ret; - return send_list_of_commands(rc4c, afs_cmds, "afs"); + return send_list_of_commands(scc, afs_cmds, "afs"); } /* argument given for help */ cmd = get_cmd_ptr(argv[1], &handler); if (!cmd) return -E_BAD_CMD; perms = cmd_perms_itohuman(cmd->perms); - ret = rc4_send_va_buffer(rc4c, + ret = sc_send_va_buffer(scc, "%s - %s\n\n" "handler: %s\n" "permissions: %s\n" @@ -480,7 +480,7 @@ int com_help(struct rc4_context *rc4c, int argc, char * const * argv) } /* hup */ -int com_hup(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_hup(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -489,7 +489,7 @@ int com_hup(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * con } /* term */ -int com_term(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_term(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -497,7 +497,7 @@ int com_term(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * co return 1; } -int com_play(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_play(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -510,7 +510,7 @@ int com_play(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * co } /* stop */ -int com_stop(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_stop(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -523,7 +523,7 @@ int com_stop(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * co } /* pause */ -int com_pause(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_pause(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -538,7 +538,7 @@ int com_pause(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * c } /* next */ -int com_next(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_next(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -550,7 +550,7 @@ int com_next(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * co } /* nomore */ -int com_nomore(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv) +int com_nomore(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv) { if (argc != 1) return -E_COMMAND_SYNTAX; @@ -562,7 +562,7 @@ int com_nomore(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * } /* ff */ -int com_ff(__a_unused struct rc4_context *rc4c, int argc, char * const * argv) +int com_ff(__a_unused struct stream_cipher_context *scc, int argc, char * const * argv) { long promille; int ret, backwards = 0; @@ -601,7 +601,7 @@ out: } /* jmp */ -int com_jmp(__a_unused struct rc4_context *rc4c, int argc, char * const * argv) +int com_jmp(__a_unused struct stream_cipher_context *scc, int argc, char * const * argv) { long unsigned int i; int ret; @@ -655,7 +655,7 @@ static struct server_command *parse_cmd(const char *cmdstr) return get_cmd_ptr(buf, NULL); } -static int read_command(struct rc4_context *rc4c, char **result) +static int read_command(struct stream_cipher_context *scc, char **result) { int ret; char buf[4096]; @@ -665,7 +665,7 @@ static int read_command(struct rc4_context *rc4c, char **result) size_t numbytes; char *p; - ret = rc4_recv_buffer(rc4c, buf, sizeof(buf)); + ret = sc_recv_buffer(scc, buf, sizeof(buf)); if (ret < 0) goto out; if (!ret) @@ -724,7 +724,7 @@ static void reset_signals(void) * which terminates the function if the connection was not * authenticated when the timeout expires. * - * \sa alarm(2), rc4(3), crypt.c, crypt.h + * \sa alarm(2), crypt.c, crypt.h */ __noreturn void handle_connect(int fd, const char *peername) { @@ -737,7 +737,7 @@ __noreturn void handle_connect(int fd, const char *peername) char **argv = NULL; char *p, *command = NULL; size_t numbytes; - struct rc4_context rc4c = {.fd = fd}; + struct stream_cipher_context scc = {.fd = fd}; reset_signals(); /* we need a blocking fd here as recv() might return EAGAIN otherwise. */ @@ -809,13 +809,12 @@ __noreturn void handle_connect(int fd, const char *peername) alarm(0); PARA_INFO_LOG("good auth for %s\n", u->name); /* init stream cipher keys with the second part of the random buffer */ - rc4c.recv = stream_cipher_new(rand_buf + CHALLENGE_SIZE, RC4_KEY_LEN); - rc4c.send = stream_cipher_new(rand_buf + CHALLENGE_SIZE + RC4_KEY_LEN, - RC4_KEY_LEN); - ret = rc4_send_buffer(&rc4c, PROCEED_MSG); + scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, RC4_KEY_LEN); + scc.send = sc_new(rand_buf + CHALLENGE_SIZE + RC4_KEY_LEN, RC4_KEY_LEN); + ret = sc_send_buffer(&scc, PROCEED_MSG); if (ret < 0) goto net_err; - ret = read_command(&rc4c, &command); + ret = read_command(&scc, &command); if (ret == -E_COMMAND_SYNTAX) goto err_out; if (ret < 0) @@ -835,7 +834,7 @@ __noreturn void handle_connect(int fd, const char *peername) argc = ret; PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cmd->name, u->name, peername); - ret = cmd->handler(&rc4c, argc, argv); + ret = cmd->handler(&scc, argc, argv); free_argv(argv); mutex_lock(mmd_mutex); mmd->num_commands++; @@ -843,13 +842,13 @@ __noreturn void handle_connect(int fd, const char *peername) if (ret >= 0) goto out; err_out: - rc4_send_va_buffer(&rc4c, "%s\n", para_strerror(-ret)); + sc_send_va_buffer(&scc, "%s\n", para_strerror(-ret)); net_err: PARA_NOTICE_LOG("%s\n", para_strerror(-ret)); out: free(command); - stream_cipher_free(rc4c.recv); - stream_cipher_free(rc4c.send); + sc_free(scc.recv); + sc_free(scc.send); mutex_lock(mmd_mutex); if (cmd && (cmd->perms & AFS_WRITE) && ret >= 0) mmd->events++; diff --git a/command.h b/command.h index 347dd81c..fd879829 100644 --- a/command.h +++ b/command.h @@ -7,7 +7,7 @@ struct server_command { /** The name of the command. */ const char *name; /** Pointer to the function that handles the command. */ - int (*handler)(struct rc4_context *, int, char * const * const); + int (*handler)(struct stream_cipher_context *, int, char * const * const); /** The privileges a user must have to execute this command. */ unsigned int perms; /** One-line description of the command. */ diff --git a/crypt.c b/crypt.c index 206b9348..99804470 100644 --- a/crypt.c +++ b/crypt.c @@ -232,7 +232,7 @@ struct stream_cipher { * * \return A new stream cipher structure. */ -struct stream_cipher *stream_cipher_new(const unsigned char *data, int len) +struct stream_cipher *sc_new(const unsigned char *data, int len) { struct stream_cipher *sc = para_malloc(sizeof(*sc)); RC4_set_key(&sc->key, len, data); @@ -242,9 +242,9 @@ struct stream_cipher *stream_cipher_new(const unsigned char *data, int len) /** * Deallocate a stream cipher structure. * - * \param sc A stream cipher previously obtained by stream_cipher_new(). + * \param sc A stream cipher previously obtained by sc_new(). */ -void stream_cipher_free(struct stream_cipher *sc) +void sc_free(struct stream_cipher *sc) { free(sc); } @@ -252,7 +252,7 @@ void stream_cipher_free(struct stream_cipher *sc) /** * Encrypt and send a buffer. * - * \param rc4c The rc4 crypt context. + * \param scc The context. * \param buf The buffer to send. * \param len The size of \a buf in bytes. * @@ -260,7 +260,8 @@ void stream_cipher_free(struct stream_cipher *sc) * * \sa \ref write_all(), RC4(3). */ -int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len) +int sc_send_bin_buffer(struct stream_cipher_context *scc, const char *buf, + size_t len) { int ret; unsigned char *tmp; @@ -269,12 +270,12 @@ int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len) assert(len); tmp = para_malloc(l2); - RC4(&rc4c->send->key, l1, (const unsigned char *)buf, tmp); + RC4(&scc->send->key, l1, (const unsigned char *)buf, tmp); if (len > l1) { memcpy(remainder, buf + l1, len - l1); - RC4(&rc4c->send->key, len - l1, remainder, tmp + l1); + RC4(&scc->send->key, len - l1, remainder, tmp + l1); } - ret = write_all(rc4c->fd, (char *)tmp, &len); + ret = write_all(scc->fd, (char *)tmp, &len); free(tmp); return ret; } @@ -282,31 +283,32 @@ int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len) /** * Encrypt and send a \p NULL-terminated buffer. * - * \param rc4c The rc4 crypt context. + * \param scc The context. * \param buf The buffer to send. * - * \return The return value of the underyling call to rc4_send_bin_buffer(). + * \return The return value of the underyling call to sc_send_bin_buffer(). */ -int rc4_send_buffer(struct rc4_context *rc4c, const char *buf) +int sc_send_buffer(struct stream_cipher_context *scc, const char *buf) { - return rc4_send_bin_buffer(rc4c, buf, strlen(buf)); + return sc_send_bin_buffer(scc, buf, strlen(buf)); } /** * Format, encrypt and send a buffer. * - * \param rc4c The rc4 crypt context. + * \param scc The context. * \param fmt A format string. * - * \return The return value of the underyling call to rc4_send_buffer(). + * \return The return value of the underyling call to sc_send_buffer(). */ -__printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, ...) +__printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc, + const char *fmt, ...) { char *msg; int ret; PARA_VSPRINTF(fmt, msg); - ret = rc4_send_buffer(rc4c, msg); + ret = sc_send_buffer(scc, msg); free(msg); return ret; } @@ -314,7 +316,7 @@ __printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, . /** * Receive a buffer and decrypt it. * - * \param rc4c The rc4 crypt context. + * \param scc The context. * \param buf The buffer to write the decrypted data to. * \param size The size of \a buf. * @@ -323,13 +325,14 @@ __printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, . * * \sa recv(2), RC4(3). */ -int rc4_recv_bin_buffer(struct rc4_context *rc4c, char *buf, size_t size) +int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf, + size_t size) { unsigned char *tmp = para_malloc(size); - ssize_t ret = recv(rc4c->fd, tmp, size, 0); + ssize_t ret = recv(scc->fd, tmp, size, 0); if (ret > 0) - RC4(&rc4c->recv->key, ret, tmp, (unsigned char *)buf); + RC4(&scc->recv->key, ret, tmp, (unsigned char *)buf); else if (ret < 0) ret = -ERRNO_TO_PARA_ERROR(errno); free(tmp); @@ -339,23 +342,22 @@ int rc4_recv_bin_buffer(struct rc4_context *rc4c, char *buf, size_t size) /** * Receive a buffer, decrypt it and write terminating NULL byte. * - * \param rc4c The rc4 crypt context. + * \param scc The context. * \param buf The buffer to write the decrypted data to. * \param size The size of \a buf. * - * Read at most \a size - 1 bytes from file descriptor given by \a rc4c, - * decrypt the received data and write a NULL byte at the end of the decrypted - * data. + * Read at most \a size - 1 bytes from file descriptor given by \a scc, decrypt + * the received data and write a NULL byte at the end of the decrypted data. * * \return The return value of the underlying call to \ref - * rc4_recv_bin_buffer(). + * sc_recv_bin_buffer(). */ -int rc4_recv_buffer(struct rc4_context *rc4c, char *buf, size_t size) +int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size) { int n; assert(size); - n = rc4_recv_bin_buffer(rc4c, buf, size - 1); + n = sc_recv_bin_buffer(scc, buf, size - 1); if (n >= 0) buf[n] = '\0'; else diff --git a/crypt.h b/crypt.h index 13a5505c..b963d105 100644 --- a/crypt.h +++ b/crypt.h @@ -30,7 +30,7 @@ struct stream_cipher; * keys for the stream cipher and the file descriptor for which these keys * should be used. */ -struct rc4_context { +struct stream_cipher_context { /** The socket file descriptor. */ int fd; /** Key used for receiving data. */ @@ -39,14 +39,17 @@ struct rc4_context { struct stream_cipher *send; }; -struct stream_cipher *stream_cipher_new(const unsigned char *data, int len); -void stream_cipher_free(struct stream_cipher *sc); - -int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len); -int rc4_send_buffer(struct rc4_context *rc4c, const char *buf); -__printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, ...); -int rc4_recv_bin_buffer(struct rc4_context *rcc, char *buf, size_t size); -int rc4_recv_buffer(struct rc4_context *rcc, char *buf, size_t size); +struct stream_cipher *sc_new(const unsigned char *data, int len); +void sc_free(struct stream_cipher *sc); + +int sc_send_bin_buffer(struct stream_cipher_context *scc, const char *buf, + size_t len); +int sc_send_buffer(struct stream_cipher_context *scc, const char *buf); +__printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc, + const char *fmt, ...); +int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf, + size_t size); +int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size); /** \cond used to distinguish between loading of private/public key */ #define LOAD_PUBLIC_KEY 0 -- 2.39.5