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