cipher.h 3.9 KB

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