Damien Miller | 4f0fe68 | 2004-01-27 21:19:21 +1100 | [diff] [blame] | 1 | /* |
| 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" |
| 18 | #include <openssl/evp.h> |
| 19 | |
Darren Tucker | 6977fe7 | 2004-02-06 15:26:10 +1100 | [diff] [blame] | 20 | #if !defined(EVP_CTRL_SET_ACSS_MODE) && (OPENSSL_VERSION_NUMBER >= 0x00907000L) |
Damien Miller | 4f0fe68 | 2004-01-27 21:19:21 +1100 | [diff] [blame] | 21 | |
| 22 | #include "acss.h" |
| 23 | |
| 24 | #define data(ctx) ((EVP_ACSS_KEY *)(ctx)->cipher_data) |
| 25 | |
| 26 | typedef struct { |
| 27 | ACSS_KEY ks; |
| 28 | } EVP_ACSS_KEY; |
| 29 | |
| 30 | #define EVP_CTRL_SET_ACSS_MODE 0xff06 |
| 31 | #define EVP_CTRL_SET_ACSS_SUBKEY 0xff07 |
| 32 | |
| 33 | static int |
Damien Miller | 94cf4c8 | 2005-07-17 17:04:47 +1000 | [diff] [blame] | 34 | acss_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
Damien Miller | 4f0fe68 | 2004-01-27 21:19:21 +1100 | [diff] [blame] | 35 | const unsigned char *iv, int enc) |
| 36 | { |
| 37 | acss_setkey(&data(ctx)->ks,key,enc,ACSS_DATA); |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | static int |
Damien Miller | 94cf4c8 | 2005-07-17 17:04:47 +1000 | [diff] [blame] | 42 | acss_ciph(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, |
Damien Miller | 4f0fe68 | 2004-01-27 21:19:21 +1100 | [diff] [blame] | 43 | unsigned int inl) |
| 44 | { |
| 45 | acss(&data(ctx)->ks,inl,in,out); |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | static int |
| 50 | acss_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) |
| 51 | { |
| 52 | switch(type) { |
| 53 | case EVP_CTRL_SET_ACSS_MODE: |
| 54 | data(ctx)->ks.mode = arg; |
| 55 | return 1; |
| 56 | case EVP_CTRL_SET_ACSS_SUBKEY: |
| 57 | acss_setsubkey(&data(ctx)->ks,(unsigned char *)ptr); |
| 58 | return 1; |
| 59 | default: |
| 60 | return -1; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const EVP_CIPHER * |
| 65 | evp_acss(void) |
| 66 | { |
| 67 | static EVP_CIPHER acss_cipher; |
| 68 | |
| 69 | memset(&acss_cipher, 0, sizeof(EVP_CIPHER)); |
| 70 | |
| 71 | acss_cipher.nid = NID_undef; |
| 72 | acss_cipher.block_size = 1; |
| 73 | acss_cipher.key_len = 5; |
| 74 | acss_cipher.init = acss_init_key; |
| 75 | acss_cipher.do_cipher = acss_ciph; |
| 76 | acss_cipher.ctx_size = sizeof(EVP_ACSS_KEY); |
| 77 | acss_cipher.ctrl = acss_ctrl; |
| 78 | |
| 79 | return (&acss_cipher); |
| 80 | } |
| 81 | #endif |
| 82 | |