blob: cb0bf736c39dfa08bea33e6951da909b4a16d7ec [file] [log] [blame]
Damien Miller4f0fe682004-01-27 21:19:21 +11001/*
2 * Copyright (c) 2004 The OpenBSD project
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "includes.h"
Damien Millerb8fe89c2006-07-24 14:51:00 +100018
Damien Miller4f0fe682004-01-27 21:19:21 +110019#include <openssl/evp.h>
20
Damien Millerb8fe89c2006-07-24 14:51:00 +100021#include <string.h>
22
Darren Tucker6977fe72004-02-06 15:26:10 +110023#if !defined(EVP_CTRL_SET_ACSS_MODE) && (OPENSSL_VERSION_NUMBER >= 0x00907000L)
Damien Miller4f0fe682004-01-27 21:19:21 +110024
25#include "acss.h"
26
27#define data(ctx) ((EVP_ACSS_KEY *)(ctx)->cipher_data)
28
29typedef struct {
30 ACSS_KEY ks;
31} EVP_ACSS_KEY;
32
33#define EVP_CTRL_SET_ACSS_MODE 0xff06
34#define EVP_CTRL_SET_ACSS_SUBKEY 0xff07
35
36static int
Damien Miller94cf4c82005-07-17 17:04:47 +100037acss_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
Damien Miller4f0fe682004-01-27 21:19:21 +110038 const unsigned char *iv, int enc)
39{
40 acss_setkey(&data(ctx)->ks,key,enc,ACSS_DATA);
41 return 1;
42}
43
44static int
Damien Miller94cf4c82005-07-17 17:04:47 +100045acss_ciph(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in,
Damien Miller4f0fe682004-01-27 21:19:21 +110046 unsigned int inl)
47{
48 acss(&data(ctx)->ks,inl,in,out);
49 return 1;
50}
51
52static int
53acss_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
54{
55 switch(type) {
56 case EVP_CTRL_SET_ACSS_MODE:
57 data(ctx)->ks.mode = arg;
58 return 1;
59 case EVP_CTRL_SET_ACSS_SUBKEY:
60 acss_setsubkey(&data(ctx)->ks,(unsigned char *)ptr);
61 return 1;
62 default:
63 return -1;
64 }
65}
66
67const EVP_CIPHER *
68evp_acss(void)
69{
70 static EVP_CIPHER acss_cipher;
71
72 memset(&acss_cipher, 0, sizeof(EVP_CIPHER));
73
74 acss_cipher.nid = NID_undef;
75 acss_cipher.block_size = 1;
76 acss_cipher.key_len = 5;
77 acss_cipher.init = acss_init_key;
78 acss_cipher.do_cipher = acss_ciph;
79 acss_cipher.ctx_size = sizeof(EVP_ACSS_KEY);
80 acss_cipher.ctrl = acss_ctrl;
81
82 return (&acss_cipher);
83}
84#endif
85