streamcipher_descriptor.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* streamcipher_descriptor.h */
  2. /*
  3. This file is part of the ARM-Crypto-Lib.
  4. Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /**
  17. * \file stremcipher_descriptor.h
  18. * \author Daniel Otte
  19. * \date 2011-01-15
  20. *
  21. * \license GPLv3 or later
  22. *
  23. */
  24. #ifndef STREAMCIPHER_DESCRIPTOR_H_
  25. #define STREAMCIPHER_DESCRIPTOR_H_
  26. #include <stdint.h>
  27. #ifndef VOID_FPT
  28. #define VOID_FPT
  29. typedef void(*void_fpt)(void);
  30. #endif
  31. typedef void(*sc_init1_fpt)(const void*, void*); /* key of fixed length, no IV*/
  32. typedef void(*sc_init2_fpt)(const void*, const void*, void*); /* key and IV of fixed length */
  33. typedef void(*sc_init3_fpt)(const void*, uint16_t,void*); /* key of variable length, no IV */
  34. typedef void(*sc_init4_fpt)(const void*, uint16_t,const void*, void*); /* key of variable length, IV of fixed length */
  35. typedef void(*sc_init5_fpt)(const void*, uint16_t,const void*, uint16_t, void*); /* key and IV of variable length */
  36. typedef uint8_t(*sc_gen1_fpt)(void*); /* return keystream data */
  37. typedef void(*sc_gen2_fpt)(void*, void*); /* write keystream data to buffer */
  38. typedef uint8_t(*sc_genra1_fpt)(void*, uint64_t); /* return keystream data */
  39. typedef void(*sc_genra2_fpt)(void*, void*, uint64_t); /* write keystream data to buffer */
  40. typedef void(*sc_free_fpt)(void*);
  41. typedef union{
  42. void_fpt initvoid;
  43. sc_init1_fpt init1;
  44. sc_init2_fpt init2;
  45. sc_init3_fpt init3;
  46. sc_init4_fpt init4;
  47. sc_init5_fpt init5;
  48. } sc_init_fpt;
  49. typedef union{
  50. void_fpt genvoid;
  51. sc_gen1_fpt gen1;
  52. sc_gen2_fpt gen2;
  53. } sc_gen_fpt;
  54. typedef union{
  55. void_fpt genravoid;
  56. sc_genra1_fpt genra1;
  57. sc_genra2_fpt genra2;
  58. } sc_genra_fpt;
  59. #define SC_INIT_TYPE 0x07
  60. #define SC_INIT_TYPE_1 0x00 /* key of fixed length, no IV*/
  61. #define SC_INIT_TYPE_2 0x02 /* key and IV of fixed length */
  62. #define SC_INIT_TYPE_3 0x03 /* key of variable length, no IV */
  63. #define SC_INIT_TYPE_4 0x04 /* key of variable length, IV of fixed length */
  64. #define SC_INIT_TYPE_5 0x05 /* key and IV of variable length */
  65. #define SC_GEN_TYPE 0x08
  66. #define SC_GEN_TYPE_1 0x00 /* return data stream byte */
  67. #define SC_GEN_TYPE_2 0x08 /* write data stream block into buffer */
  68. #define SCDESC_TYPE_STREAMCIPHER 0x03
  69. typedef struct {
  70. uint8_t type; /* 3==streamcipher */
  71. uint8_t flags;
  72. const char* name;
  73. uint16_t ctxsize_B;
  74. uint16_t gensize_b;
  75. sc_init_fpt init;
  76. sc_gen_fpt gen;
  77. sc_genra_fpt genra;
  78. sc_free_fpt free;
  79. const void* valid_keysize_desc;
  80. const void* valid_ivsize_desc;
  81. } scdesc_t; /* streamcipher descriptor type */
  82. typedef struct{
  83. const scdesc_t* desc_ptr;
  84. uint16_t keysize;
  85. uint16_t ivsize;
  86. uint16_t index;
  87. uint8_t* buffer;
  88. void* ctx;
  89. } scgen_ctx_t;
  90. #endif /* STREAMCIPHER_DESCRIPTOR_H_ */