Deleted Added
full compact
cipher-ctr.c (181111) cipher-ctr.c (221420)
1/* $OpenBSD: cipher-ctr.c,v 1.10 2006/08/03 03:34:42 deraadt Exp $ */
1/* $OpenBSD: cipher-ctr.c,v 1.11 2010/10/01 23:05:32 djm Exp $ */
2/*
3 * Copyright (c) 2003 Markus Friedl <markus@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

--- 19 unchanged lines hidden (view full) ---

29/* compatibility with old or broken OpenSSL versions */
30#include "openbsd-compat/openssl-compat.h"
31
32#ifndef USE_BUILTIN_RIJNDAEL
33#include <openssl/aes.h>
34#endif
35
36const EVP_CIPHER *evp_aes_128_ctr(void);
2/*
3 * Copyright (c) 2003 Markus Friedl <markus@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

--- 19 unchanged lines hidden (view full) ---

29/* compatibility with old or broken OpenSSL versions */
30#include "openbsd-compat/openssl-compat.h"
31
32#ifndef USE_BUILTIN_RIJNDAEL
33#include <openssl/aes.h>
34#endif
35
36const EVP_CIPHER *evp_aes_128_ctr(void);
37void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, u_int);
37void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t);
38
39struct ssh_aes_ctr_ctx
40{
41 AES_KEY aes_ctx;
42 u_char aes_counter[AES_BLOCK_SIZE];
43};
44
45/*
46 * increment counter 'ctr',
47 * the counter is of size 'len' bytes and stored in network-byte-order.
48 * (LSB at ctr[len-1], MSB at ctr[0])
49 */
50static void
38
39struct ssh_aes_ctr_ctx
40{
41 AES_KEY aes_ctx;
42 u_char aes_counter[AES_BLOCK_SIZE];
43};
44
45/*
46 * increment counter 'ctr',
47 * the counter is of size 'len' bytes and stored in network-byte-order.
48 * (LSB at ctr[len-1], MSB at ctr[0])
49 */
50static void
51ssh_ctr_inc(u_char *ctr, u_int len)
51ssh_ctr_inc(u_char *ctr, size_t len)
52{
53 int i;
54
55 for (i = len - 1; i >= 0; i--)
56 if (++ctr[i]) /* continue on overflow */
57 return;
58}
59
60static int
61ssh_aes_ctr(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src,
52{
53 int i;
54
55 for (i = len - 1; i >= 0; i--)
56 if (++ctr[i]) /* continue on overflow */
57 return;
58}
59
60static int
61ssh_aes_ctr(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src,
62 u_int len)
62 LIBCRYPTO_EVP_INL_TYPE len)
63{
64 struct ssh_aes_ctr_ctx *c;
63{
64 struct ssh_aes_ctr_ctx *c;
65 u_int n = 0;
65 size_t n = 0;
66 u_char buf[AES_BLOCK_SIZE];
67
68 if (len == 0)
69 return (1);
70 if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL)
71 return (0);
72
73 while ((len--) > 0) {

--- 34 unchanged lines hidden (view full) ---

108 memset(c, 0, sizeof(*c));
109 xfree(c);
110 EVP_CIPHER_CTX_set_app_data(ctx, NULL);
111 }
112 return (1);
113}
114
115void
66 u_char buf[AES_BLOCK_SIZE];
67
68 if (len == 0)
69 return (1);
70 if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL)
71 return (0);
72
73 while ((len--) > 0) {

--- 34 unchanged lines hidden (view full) ---

108 memset(c, 0, sizeof(*c));
109 xfree(c);
110 EVP_CIPHER_CTX_set_app_data(ctx, NULL);
111 }
112 return (1);
113}
114
115void
116ssh_aes_ctr_iv(EVP_CIPHER_CTX *evp, int doset, u_char * iv, u_int len)
116ssh_aes_ctr_iv(EVP_CIPHER_CTX *evp, int doset, u_char * iv, size_t len)
117{
118 struct ssh_aes_ctr_ctx *c;
119
120 if ((c = EVP_CIPHER_CTX_get_app_data(evp)) == NULL)
121 fatal("ssh_aes_ctr_iv: no context");
122 if (doset)
123 memcpy(c->aes_counter, iv, len);
124 else

--- 22 unchanged lines hidden ---
117{
118 struct ssh_aes_ctr_ctx *c;
119
120 if ((c = EVP_CIPHER_CTX_get_app_data(evp)) == NULL)
121 fatal("ssh_aes_ctr_iv: no context");
122 if (doset)
123 memcpy(c->aes_counter, iv, len);
124 else

--- 22 unchanged lines hidden ---