Grid Community Toolkit  6.2.1705709074 (tag: v6.2.20240202)
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cipher.h
1 /* $OpenBSD: cipher.h,v 1.55 2020/01/23 10:24:29 dtucker Exp $ */
2 
3 /*
4  * Author: Tatu Ylonen <[email protected]>
5  * Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
6  * All rights reserved
7  *
8  * As far as I am concerned, the code I have written for this software
9  * can be used freely for any purpose. Any derived versions of this
10  * software must be clearly marked as such, and if the derived work is
11  * incompatible with the protocol description in the RFC file, it must be
12  * called by a name other than "ssh" or "Secure Shell".
13  *
14  * Copyright (c) 2000 Markus Friedl. All rights reserved.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef CIPHER_H
38 #define CIPHER_H
39 
40 #include <sys/types.h>
41 #ifdef WITH_OPENSSL
42 #include <openssl/evp.h>
43 #endif
44 #include "cipher-chachapoly.h"
45 #include "cipher-aesctr.h"
46 
47 #define CIPHER_ENCRYPT 1
48 #define CIPHER_DECRYPT 0
49 
50 struct sshcipher {
51  char *name;
52  u_int block_size;
53  u_int key_len;
54  u_int iv_len; /* defaults to block_size */
55  u_int auth_len;
56  u_int flags;
57 #define CFLAG_CBC (1<<0)
58 #define CFLAG_CHACHAPOLY (1<<1)
59 #define CFLAG_AESCTR (1<<2)
60 #define CFLAG_NONE (1<<3)
61 #define CFLAG_INTERNAL CFLAG_NONE /* Don't use "none" for packets */
62 #ifdef WITH_OPENSSL
63  const EVP_CIPHER *(*evptype)(void);
64 #else
65  void *ignored;
66 #endif
67 };
68 
69 struct sshcipher_ctx;
70 
71 void ssh_aes_ctr_thread_destroy(EVP_CIPHER_CTX *ctx); // defined in cipher-ctr-mt.c
72 void ssh_aes_ctr_thread_reconstruction(EVP_CIPHER_CTX *ctx);
73 struct sshcipher *cipher_by_name(const char *);
74 const char *cipher_warning_message(const struct sshcipher_ctx *);
75 int ciphers_valid(const char *);
76 char *cipher_alg_list(char, int);
77 const char *compression_alg_list(int);
78 int cipher_init(struct sshcipher_ctx **, const struct sshcipher *,
79  const u_char *, u_int, const u_char *, u_int, int);
80 int cipher_crypt(struct sshcipher_ctx *, u_int, u_char *, const u_char *,
81  u_int, u_int, u_int);
82 int cipher_get_length(struct sshcipher_ctx *, u_int *, u_int,
83  const u_char *, u_int);
84 void cipher_free(struct sshcipher_ctx *);
85 u_int cipher_blocksize(const struct sshcipher *);
86 u_int cipher_keylen(const struct sshcipher *);
87 u_int cipher_seclen(const struct sshcipher *);
88 u_int cipher_authlen(const struct sshcipher *);
89 u_int cipher_ivlen(const struct sshcipher *);
90 u_int cipher_is_cbc(const struct sshcipher *);
91 void cipher_reset_multithreaded(void);
92 const char *cipher_ctx_name(const struct sshcipher_ctx *);
93 
94 u_int cipher_ctx_is_plaintext(struct sshcipher_ctx *);
95 
96 int cipher_get_keyiv(struct sshcipher_ctx *, u_char *, size_t);
97 int cipher_set_keyiv(struct sshcipher_ctx *, const u_char *, size_t);
98 int cipher_get_keyiv_len(const struct sshcipher_ctx *);
99 
100 #endif /* CIPHER_H */