hw_zencod.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* File : /crypto/engine/vendor_defns/hw_zencod.h */
  2. /* ====================================================================
  3. * Written by Donnat Frederic (frederic.donnat@zencod.com) from ZENCOD
  4. * for "zencod" ENGINE integration in OpenSSL project.
  5. */
  6. #ifndef _HW_ZENCOD_H_
  7. # define _HW_ZENCOD_H_
  8. # include <stdio.h>
  9. # ifdef __cplusplus
  10. extern "C" {
  11. # endif /* __cplusplus */
  12. # define ZENBRIDGE_MAX_KEYSIZE_RSA 2048
  13. # define ZENBRIDGE_MAX_KEYSIZE_RSA_CRT 1024
  14. # define ZENBRIDGE_MAX_KEYSIZE_DSA_SIGN 1024
  15. # define ZENBRIDGE_MAX_KEYSIZE_DSA_VRFY 1024
  16. /* Library version computation */
  17. # define ZENBRIDGE_VERSION_MAJOR(x) (((x) >> 16) | 0xff)
  18. # define ZENBRIDGE_VERSION_MINOR(x) (((x) >> 8) | 0xff)
  19. # define ZENBRIDGE_VERSION_PATCH(x) (((x) >> 0) | 0xff)
  20. # define ZENBRIDGE_VERSION(x, y, z) ((x) << 16 | (y) << 8 | (z))
  21. /*
  22. * Memory type
  23. */
  24. typedef struct zencod_number_s {
  25. unsigned long len;
  26. unsigned char *data;
  27. } zen_nb_t;
  28. # define KEY zen_nb_t
  29. /*
  30. * Misc
  31. */
  32. typedef int t_zencod_lib_version(void);
  33. typedef int t_zencod_hw_version(void);
  34. typedef int t_zencod_test(void);
  35. typedef int t_zencod_dump_key(FILE *stream, char *msg, KEY * key);
  36. /*
  37. * Key management tools
  38. */
  39. typedef KEY *t_zencod_new_number(unsigned long len, unsigned char *data);
  40. typedef int t_zencod_init_number(KEY * n, unsigned long len,
  41. unsigned char *data);
  42. typedef unsigned long t_zencod_bytes2bits(unsigned char *n,
  43. unsigned long bytes);
  44. typedef unsigned long t_zencod_bits2bytes(unsigned long bits);
  45. /*
  46. * RSA API
  47. */
  48. /* Compute modular exponential : y = x**e | n */
  49. typedef int t_zencod_rsa_mod_exp(KEY * y, KEY * x, KEY * n, KEY * e);
  50. /*
  51. * Compute modular exponential : y1 = (x | p)**edp | p, y2 = (x | p)**edp
  52. * | p, y = y2 + (qinv * (y1 - y2) | p) * q
  53. */
  54. typedef int t_zencod_rsa_mod_exp_crt(KEY * y, KEY * x, KEY * p, KEY * q,
  55. KEY * edp, KEY * edq, KEY * qinv);
  56. /*
  57. * DSA API
  58. */
  59. typedef int t_zencod_dsa_do_sign(unsigned int hash, KEY * data,
  60. KEY * random, KEY * p, KEY * q, KEY * g,
  61. KEY * x, KEY * r, KEY * s);
  62. typedef int t_zencod_dsa_do_verify(unsigned int hash, KEY * data, KEY * p,
  63. KEY * q, KEY * g, KEY * y, KEY * r,
  64. KEY * s, KEY * v);
  65. /*
  66. * DH API
  67. */
  68. /* Key generation : compute public value y = g**x | n */
  69. typedef int t_zencod_dh_generate_key(KEY * y, KEY * x, KEY * g, KEY * n,
  70. int gen_x);
  71. typedef int t_zencod_dh_compute_key(KEY * k, KEY * y, KEY * x, KEY * n);
  72. /*
  73. * RNG API
  74. */
  75. # define ZENBRIDGE_RNG_DIRECT 0
  76. # define ZENBRIDGE_RNG_SHA1 1
  77. typedef int t_zencod_rand_bytes(KEY * rand, unsigned int flags);
  78. /*
  79. * Math API
  80. */
  81. typedef int t_zencod_math_mod_exp(KEY * r, KEY * a, KEY * e, KEY * n);
  82. /*
  83. * Symetric API
  84. */
  85. /* Define a data structure for digests operations */
  86. typedef struct ZEN_data_st {
  87. unsigned int HashBufferSize;
  88. unsigned char *HashBuffer;
  89. } ZEN_MD_DATA;
  90. /*
  91. * Functions for Digest (MD5, SHA1) stuff
  92. */
  93. /* output : output data buffer */
  94. /* input : input data buffer */
  95. /* algo : hash algorithm, MD5 or SHA1 */
  96. /*-
  97. * typedef int t_zencod_hash ( KEY *output, const KEY *input, int algo ) ;
  98. * typedef int t_zencod_sha_hash ( KEY *output, const KEY *input, int algo ) ;
  99. */
  100. /* For now separate this stuff that mad it easier to test */
  101. typedef int t_zencod_md5_init(ZEN_MD_DATA *data);
  102. typedef int t_zencod_md5_update(ZEN_MD_DATA *data, const KEY * input);
  103. typedef int t_zencod_md5_do_final(ZEN_MD_DATA *data, KEY * output);
  104. typedef int t_zencod_sha1_init(ZEN_MD_DATA *data);
  105. typedef int t_zencod_sha1_update(ZEN_MD_DATA *data, const KEY * input);
  106. typedef int t_zencod_sha1_do_final(ZEN_MD_DATA *data, KEY * output);
  107. /*
  108. * Functions for Cipher (RC4, DES, 3DES) stuff
  109. */
  110. /* output : output data buffer */
  111. /* input : input data buffer */
  112. /* key : rc4 key data */
  113. /* index_1 : value of index x from RC4 key structure */
  114. /* index_2 : value of index y from RC4 key structure */
  115. /*
  116. * Be careful : RC4 key should be expanded before calling this method
  117. * (Should we provide an expand function ??)
  118. */
  119. typedef int t_zencod_rc4_cipher(KEY * output, const KEY * input,
  120. const KEY * key, unsigned char *index_1,
  121. unsigned char *index_2, int mode);
  122. /* output : output data buffer */
  123. /* input : input data buffer */
  124. /* key_1 : des first key data */
  125. /* key_2 : des second key data */
  126. /* key_3 : des third key data */
  127. /* iv : initial vector */
  128. /* mode : xdes mode (encrypt or decrypt) */
  129. /* Be careful : In DES mode key_1 = key_2 = key_3 (as far as i can see !!) */
  130. typedef int t_zencod_xdes_cipher(KEY * output, const KEY * input,
  131. const KEY * key_1, const KEY * key_2,
  132. const KEY * key_3, const KEY * iv,
  133. int mode);
  134. # undef KEY
  135. # ifdef __cplusplus
  136. }
  137. # endif /* __cplusplus */
  138. #endif /* !_HW_ZENCOD_H_ */