Skip to content

support cipher none #2993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,42 @@ entropy_check(void)
#endif
}

#ifndef ATTR_UNUSED
#define ATTR_UNUSED __attribute__((unused))
#endif

static int none_encrypt_all(ATTR_UNUSED buffer_t *a, ATTR_UNUSED cipher_t *b, ATTR_UNUSED size_t c) {
return CRYPTO_OK;
}

static int none_decrypt_all(ATTR_UNUSED buffer_t *a, ATTR_UNUSED cipher_t *b, ATTR_UNUSED size_t c) {
return CRYPTO_OK;
}

static int none_encrypt(ATTR_UNUSED buffer_t *a, ATTR_UNUSED cipher_ctx_t *b, ATTR_UNUSED size_t c) {
return CRYPTO_OK;
}

static int none_decrypt(ATTR_UNUSED buffer_t *a, ATTR_UNUSED cipher_ctx_t *b, ATTR_UNUSED size_t c) {
return CRYPTO_OK;
}

static void none_ctx_init(ATTR_UNUSED cipher_t *a, ATTR_UNUSED cipher_ctx_t *b, ATTR_UNUSED int c) {
}

static void none_ctx_release(ATTR_UNUSED cipher_ctx_t *a) {
}

static crypto_t none_crypt = {
.cipher = NULL,
.encrypt_all = &none_encrypt_all,
.decrypt_all = &none_decrypt_all,
.encrypt = &none_encrypt,
.decrypt = &none_decrypt,
.ctx_init = &none_ctx_init,
.ctx_release = &none_ctx_release,
};

crypto_t *
crypto_init(const char *password, const char *key, const char *method)
{
Expand All @@ -150,6 +186,10 @@ crypto_init(const char *password, const char *key, const char *method)
#endif

if (method != NULL) {
if (strcmp(method, "none") == 0) {
return &none_crypt;
}

for (i = 0; i < STREAM_CIPHER_NUM; i++)
if (strcmp(method, supported_stream_ciphers[i]) == 0) {
m = i;
Expand Down
2 changes: 1 addition & 1 deletion src/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
#endif
if (!password && !key) {
if (!password && !key && strcmp(method, "none")) {
fprintf(stderr, "both password and key are NULL\n");
exit(EXIT_FAILURE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/redir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ main(int argc, char **argv)
}

if (remote_num == 0 || remote_port == NULL || local_port == NULL
|| (password == NULL && key == NULL)) {
|| (password == NULL && key == NULL && strcmp(method, "none"))) {
usage();
exit(EXIT_FAILURE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ main(int argc, char **argv)
}

if (server_num == 0 || server_port == NULL
|| (password == NULL && key == NULL)) {
|| (password == NULL && key == NULL && strcmp(method, "none"))) {
usage();
exit(EXIT_FAILURE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ main(int argc, char **argv)
}

if (remote_num == 0 || remote_port == NULL || tunnel_addr_str == NULL
|| local_port == NULL || (password == NULL && key == NULL)) {
|| local_port == NULL || (password == NULL && key == NULL && strcmp(method, "none"))) {
usage();
exit(EXIT_FAILURE);
}
Expand Down