|
Tomas Mraz |
017c65 |
diff -up openssh-5.9p1/ctr-cavstest.c.ctr-cavs openssh-5.9p1/ctr-cavstest.c
|
|
Tomas Mraz |
017c65 |
--- openssh-5.9p1/ctr-cavstest.c.ctr-cavs 2012-01-13 15:59:06.584283289 +0100
|
|
Tomas Mraz |
017c65 |
+++ openssh-5.9p1/ctr-cavstest.c 2012-01-13 18:21:33.791941027 +0100
|
|
Tomas Mraz |
017c65 |
@@ -0,0 +1,208 @@
|
|
Tomas Mraz |
017c65 |
+/*
|
|
Tomas Mraz |
017c65 |
+ *
|
|
Tomas Mraz |
017c65 |
+ * invocation (all of the following are equal):
|
|
Tomas Mraz |
017c65 |
+ * ./ctr-cavstest --algo aes128-ctr --key 987212980144b6a632e864031f52dacc --mode encrypt --data a6deca405eef2e8e4609abf3c3ccf4a6
|
|
Tomas Mraz |
017c65 |
+ * ./ctr-cavstest --algo aes128-ctr --key 987212980144b6a632e864031f52dacc --mode encrypt --data a6deca405eef2e8e4609abf3c3ccf4a6 --iv 00000000000000000000000000000000
|
|
Tomas Mraz |
017c65 |
+ * echo -n a6deca405eef2e8e4609abf3c3ccf4a6 | ./ctr-cavstest --algo aes128-ctr --key 987212980144b6a632e864031f52dacc --mode encrypt
|
|
Tomas Mraz |
017c65 |
+ */
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+#include "includes.h"
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+#include <sys/types.h>
|
|
Tomas Mraz |
017c65 |
+#include <sys/param.h>
|
|
Tomas Mraz |
017c65 |
+#include <stdarg.h>
|
|
Tomas Mraz |
017c65 |
+#include <stdio.h>
|
|
Tomas Mraz |
017c65 |
+#include <stdlib.h>
|
|
Tomas Mraz |
017c65 |
+#include <string.h>
|
|
Tomas Mraz |
017c65 |
+#include <ctype.h>
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+#include "xmalloc.h"
|
|
Tomas Mraz |
017c65 |
+#include "log.h"
|
|
Tomas Mraz |
017c65 |
+#include "cipher.h"
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+/* compatibility with old or broken OpenSSL versions */
|
|
Tomas Mraz |
017c65 |
+#include "openbsd-compat/openssl-compat.h"
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+void usage(void) {
|
|
Tomas Mraz |
017c65 |
+ fprintf(stderr, "Usage: ctr-cavstest --algo <ssh-crypto-algorithm>\n"
|
|
Tomas Mraz |
017c65 |
+ " --key <hexadecimal-key> --mode <encrypt|decrypt>\n"
|
|
Tomas Mraz |
017c65 |
+ " [--iv <hexadecimal-iv>] --data <hexadecimal-data>\n\n"
|
|
Tomas Mraz |
017c65 |
+ "Hexadecimal output is printed to stdout.\n"
|
|
Tomas Mraz |
017c65 |
+ "Hexadecimal input data can be alternatively read from stdin.\n");
|
|
Tomas Mraz |
017c65 |
+ exit(1);
|
|
Tomas Mraz |
017c65 |
+}
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+void *fromhex(char *hex, size_t *len)
|
|
Tomas Mraz |
017c65 |
+{
|
|
Tomas Mraz |
017c65 |
+ unsigned char *bin;
|
|
Tomas Mraz |
017c65 |
+ char *p;
|
|
Tomas Mraz |
017c65 |
+ size_t n = 0;
|
|
Tomas Mraz |
017c65 |
+ int shift = 4;
|
|
Tomas Mraz |
017c65 |
+ unsigned char out = 0;
|
|
Tomas Mraz |
017c65 |
+ unsigned char *optr;
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ bin = xmalloc(strlen(hex)/2);
|
|
Tomas Mraz |
017c65 |
+ optr = bin;
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ for (p = hex; *p != '\0'; ++p) {
|
|
Tomas Mraz |
017c65 |
+ unsigned char c;
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ c = *p;
|
|
Tomas Mraz |
017c65 |
+ if (isspace(c))
|
|
Tomas Mraz |
017c65 |
+ continue;
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ if (c >= '0' && c <= '9') {
|
|
Tomas Mraz |
017c65 |
+ c = c - '0';
|
|
Tomas Mraz |
017c65 |
+ } else if (c >= 'A' && c <= 'F') {
|
|
Tomas Mraz |
017c65 |
+ c = c - 'A' + 10;
|
|
Tomas Mraz |
017c65 |
+ } else if (c >= 'a' && c <= 'f') {
|
|
Tomas Mraz |
017c65 |
+ c = c - 'a' + 10;
|
|
Tomas Mraz |
017c65 |
+ } else {
|
|
Tomas Mraz |
017c65 |
+ /* truncate on nonhex cipher */
|
|
Tomas Mraz |
017c65 |
+ break;
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ out |= c << shift;
|
|
Tomas Mraz |
017c65 |
+ shift = (shift + 4) % 8;
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ if (shift) {
|
|
Tomas Mraz |
017c65 |
+ *(optr++) = out;
|
|
Tomas Mraz |
017c65 |
+ out = 0;
|
|
Tomas Mraz |
017c65 |
+ ++n;
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ *len = n;
|
|
Tomas Mraz |
017c65 |
+ return bin;
|
|
Tomas Mraz |
017c65 |
+}
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+#define READ_CHUNK 4096
|
|
Tomas Mraz |
017c65 |
+#define MAX_READ_SIZE 1024*1024*100
|
|
Tomas Mraz |
017c65 |
+char *read_stdin(void)
|
|
Tomas Mraz |
017c65 |
+{
|
|
Tomas Mraz |
017c65 |
+ char *buf;
|
|
Tomas Mraz |
017c65 |
+ size_t n, total = 0;
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ buf = xmalloc(READ_CHUNK);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ do {
|
|
Tomas Mraz |
017c65 |
+ n = fread(buf + total, 1, READ_CHUNK, stdin);
|
|
Tomas Mraz |
017c65 |
+ if (n < READ_CHUNK) /* terminate on short read */
|
|
Tomas Mraz |
017c65 |
+ break;
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ total += n;
|
|
Tomas Mraz |
017c65 |
+ buf = xrealloc(buf, total + READ_CHUNK, 1);
|
|
Tomas Mraz |
017c65 |
+ } while(total < MAX_READ_SIZE);
|
|
Tomas Mraz |
017c65 |
+ return buf;
|
|
Tomas Mraz |
017c65 |
+}
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+int main (int argc, char *argv[])
|
|
Tomas Mraz |
017c65 |
+{
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ Cipher *c;
|
|
Tomas Mraz |
017c65 |
+ CipherContext cc;
|
|
Tomas Mraz |
017c65 |
+ char *algo = "aes128-ctr";
|
|
Tomas Mraz |
017c65 |
+ char *hexkey = NULL;
|
|
Tomas Mraz |
017c65 |
+ char *hexiv = "00000000000000000000000000000000";
|
|
Tomas Mraz |
017c65 |
+ char *hexdata = NULL;
|
|
Tomas Mraz |
017c65 |
+ char *p;
|
|
Tomas Mraz |
017c65 |
+ int i;
|
|
Tomas Mraz |
017c65 |
+ int encrypt = 1;
|
|
Tomas Mraz |
017c65 |
+ void *key;
|
|
Tomas Mraz |
017c65 |
+ size_t keylen;
|
|
Tomas Mraz |
017c65 |
+ void *iv;
|
|
Tomas Mraz |
017c65 |
+ size_t ivlen;
|
|
Tomas Mraz |
017c65 |
+ void *data;
|
|
Tomas Mraz |
017c65 |
+ size_t datalen;
|
|
Tomas Mraz |
017c65 |
+ void *outdata;
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ for (i = 1; i < argc; ++i) {
|
|
Tomas Mraz |
017c65 |
+ if (strcmp(argv[i], "--algo") == 0) {
|
|
Tomas Mraz |
017c65 |
+ algo = argv[++i];
|
|
Tomas Mraz |
017c65 |
+ } else if (strcmp(argv[i], "--key") == 0) {
|
|
Tomas Mraz |
017c65 |
+ hexkey = argv[++i];
|
|
Tomas Mraz |
017c65 |
+ } else if (strcmp(argv[i], "--mode") == 0) {
|
|
Tomas Mraz |
017c65 |
+ ++i;
|
|
Tomas Mraz |
017c65 |
+ if (argv[i] == NULL) {
|
|
Tomas Mraz |
017c65 |
+ usage();
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+ if (strncmp(argv[i], "enc", 3) == 0) {
|
|
Tomas Mraz |
017c65 |
+ encrypt = 1;
|
|
Tomas Mraz |
017c65 |
+ } else if (strncmp(argv[i], "dec", 3) == 0) {
|
|
Tomas Mraz |
017c65 |
+ encrypt = 0;
|
|
Tomas Mraz |
017c65 |
+ } else {
|
|
Tomas Mraz |
017c65 |
+ usage();
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+ } else if (strcmp(argv[i], "--iv") == 0) {
|
|
Tomas Mraz |
017c65 |
+ hexiv = argv[++i];
|
|
Tomas Mraz |
017c65 |
+ } else if (strcmp(argv[i], "--data") == 0) {
|
|
Tomas Mraz |
017c65 |
+ hexdata = argv[++i];
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ if (hexkey == NULL || algo == NULL) {
|
|
Tomas Mraz |
017c65 |
+ usage();
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ SSLeay_add_all_algorithms();
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ c = cipher_by_name(algo);
|
|
Tomas Mraz |
017c65 |
+ if (c == NULL) {
|
|
Tomas Mraz |
017c65 |
+ fprintf(stderr, "Error: unknown algorithm\n");
|
|
Tomas Mraz |
017c65 |
+ return 2;
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ if (hexdata == NULL) {
|
|
Tomas Mraz |
017c65 |
+ hexdata = read_stdin();
|
|
Tomas Mraz |
017c65 |
+ } else {
|
|
Tomas Mraz |
017c65 |
+ hexdata = xstrdup(hexdata);
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ key = fromhex(hexkey, &keylen);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ if (keylen != 16 && keylen != 24 && keylen == 32) {
|
|
Tomas Mraz |
017c65 |
+ fprintf(stderr, "Error: unsupported key length\n");
|
|
Tomas Mraz |
017c65 |
+ return 2;
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ iv = fromhex(hexiv, &ivlen);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ if (ivlen != 16) {
|
|
Tomas Mraz |
017c65 |
+ fprintf(stderr, "Error: unsupported iv length\n");
|
|
Tomas Mraz |
017c65 |
+ return 2;
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ data = fromhex(hexdata, &datalen);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ if (data == NULL || datalen == 0) {
|
|
Tomas Mraz |
017c65 |
+ fprintf(stderr, "Error: no data to encrypt/decrypt\n");
|
|
Tomas Mraz |
017c65 |
+ return 2;
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ cipher_init(&cc, c, key, keylen, iv, ivlen, encrypt);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ xfree(key);
|
|
Tomas Mraz |
017c65 |
+ xfree(iv);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ outdata = malloc(datalen);
|
|
Tomas Mraz |
017c65 |
+ if(outdata == NULL) {
|
|
Tomas Mraz |
017c65 |
+ fprintf(stderr, "Error: memory allocation failure\n");
|
|
Tomas Mraz |
017c65 |
+ return 2;
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ cipher_crypt(&cc, outdata, data, datalen);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ xfree(data);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ cipher_cleanup(&cc);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ for (p = outdata; datalen > 0; ++p, --datalen) {
|
|
Tomas Mraz |
017c65 |
+ printf("%02X", (unsigned char)*p);
|
|
Tomas Mraz |
017c65 |
+ }
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ xfree(outdata);
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
+ printf("\n");
|
|
Tomas Mraz |
017c65 |
+ return 0;
|
|
Tomas Mraz |
017c65 |
+}
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
diff -up openssh-5.9p1/Makefile.in.ctr-cavs openssh-5.9p1/Makefile.in
|
|
Tomas Mraz |
017c65 |
--- openssh-5.9p1/Makefile.in.ctr-cavs 2012-01-13 15:59:06.539282357 +0100
|
|
Tomas Mraz |
017c65 |
+++ openssh-5.9p1/Makefile.in 2012-01-13 15:59:06.588283373 +0100
|
|
Tomas Mraz |
017c65 |
@@ -28,6 +28,7 @@ SSH_KEYSIGN=$(libexecdir)/ssh-keysign
|
|
Tomas Mraz |
017c65 |
SSH_LDAP_HELPER=$(libexecdir)/ssh-ldap-helper
|
|
Tomas Mraz |
017c65 |
SSH_LDAP_WRAPPER=$(libexecdir)/ssh-ldap-wrapper
|
|
Tomas Mraz |
017c65 |
SSH_KEYCAT=$(libexecdir)/ssh-keycat
|
|
Tomas Mraz |
017c65 |
+CTR_CAVSTEST=$(libexecdir)/ctr-cavstest
|
|
Tomas Mraz |
017c65 |
SSH_PKCS11_HELPER=$(libexecdir)/ssh-pkcs11-helper
|
|
Tomas Mraz |
017c65 |
PRIVSEP_PATH=@PRIVSEP_PATH@
|
|
Tomas Mraz |
017c65 |
SSH_PRIVSEP_USER=@SSH_PRIVSEP_USER@
|
|
Tomas Mraz |
017c65 |
@@ -63,7 +64,7 @@ EXEEXT=@EXEEXT@
|
|
Tomas Mraz |
017c65 |
MANFMT=@MANFMT@
|
|
Tomas Mraz |
017c65 |
INSTALL_SSH_LDAP_HELPER=@INSTALL_SSH_LDAP_HELPER@
|
|
Tomas Mraz |
017c65 |
|
|
Tomas Mraz |
017c65 |
-TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-ldap-helper$(EXEEXT) ssh-keycat$(EXEEXT)
|
|
Tomas Mraz |
017c65 |
+TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-ldap-helper$(EXEEXT) ssh-keycat$(EXEEXT) ctr-cavstest$(EXEEXT)
|
|
Tomas Mraz |
017c65 |
|
|
Tomas Mraz |
017c65 |
LIBSSH_OBJS=acss.o authfd.o authfile.o bufaux.o bufbn.o buffer.o \
|
|
Tomas Mraz |
017c65 |
canohost.o channels.o cipher.o cipher-acss.o cipher-aes.o \
|
|
Tomas Mraz |
017c65 |
@@ -171,6 +172,9 @@ ssh-ldap-helper$(EXEEXT): $(LIBCOMPAT) l
|
|
Tomas Mraz |
017c65 |
ssh-keycat$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keycat.o
|
|
Tomas Mraz |
017c65 |
$(LD) -o $@ ssh-keycat.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(SSHDLIBS)
|
|
Tomas Mraz |
017c65 |
|
|
Tomas Mraz |
017c65 |
+ctr-cavstest$(EXEEXT): $(LIBCOMPAT) libssh.a ctr-cavstest.o
|
|
Tomas Mraz |
017c65 |
+ $(LD) -o $@ ctr-cavstest.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
|
|
Tomas Mraz |
017c65 |
+
|
|
Tomas Mraz |
017c65 |
ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o roaming_dummy.o
|
|
Tomas Mraz |
017c65 |
$(LD) -o $@ ssh-keyscan.o roaming_dummy.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lfipscheck $(LIBS)
|
|
Tomas Mraz |
017c65 |
|
|
Tomas Mraz |
017c65 |
@@ -271,6 +275,7 @@ install-files:
|
|
Tomas Mraz |
017c65 |
$(INSTALL) -m 0700 ssh-ldap-wrapper $(DESTDIR)$(SSH_LDAP_WRAPPER) ; \
|
|
Tomas Mraz |
017c65 |
fi
|
|
Tomas Mraz |
017c65 |
$(INSTALL) -m 0755 $(STRIP_OPT) ssh-keycat$(EXEEXT) $(DESTDIR)$(libexecdir)/ssh-keycat$(EXEEXT)
|
|
Tomas Mraz |
017c65 |
+ $(INSTALL) -m 0755 $(STRIP_OPT) ctr-cavstest$(EXEEXT) $(DESTDIR)$(libexecdir)/ctr-cavstest$(EXEEXT)
|
|
Tomas Mraz |
017c65 |
$(INSTALL) -m 0755 $(STRIP_OPT) sftp$(EXEEXT) $(DESTDIR)$(bindir)/sftp$(EXEEXT)
|
|
Tomas Mraz |
017c65 |
$(INSTALL) -m 0755 $(STRIP_OPT) sftp-server$(EXEEXT) $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
|
|
Tomas Mraz |
017c65 |
$(INSTALL) -m 644 ssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1
|