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