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