hw_zencod.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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, unsigned char *data);
  41. typedef unsigned long t_zencod_bytes2bits (unsigned char *n, unsigned long bytes);
  42. typedef unsigned long t_zencod_bits2bytes (unsigned long bits);
  43. /*
  44. * RSA API
  45. */
  46. /* Compute modular exponential : y = x**e | n */
  47. typedef int t_zencod_rsa_mod_exp (KEY *y, KEY *x, KEY *n, KEY *e);
  48. /* Compute modular exponential : y1 = (x | p)**edp | p, y2 = (x | p)**edp | p, y = y2 + (qinv * (y1 - y2) | p) * q */
  49. typedef int t_zencod_rsa_mod_exp_crt (KEY *y, KEY *x, KEY *p, KEY *q,
  50. KEY *edp, KEY *edq, KEY *qinv);
  51. /*
  52. * DSA API
  53. */
  54. typedef int t_zencod_dsa_do_sign (unsigned int hash, KEY *data, KEY *random,
  55. KEY *p, KEY *q, KEY *g, KEY *x, KEY *r, KEY *s);
  56. typedef int t_zencod_dsa_do_verify (unsigned int hash, KEY *data,
  57. KEY *p, KEY *q, KEY *g, KEY *y,
  58. KEY *r, KEY *s, KEY *v);
  59. /*
  60. * DH API
  61. */
  62. /* Key generation : compute public value y = g**x | n */
  63. typedef int t_zencod_dh_generate_key (KEY *y, KEY *x, KEY *g, KEY *n, int gen_x);
  64. typedef int t_zencod_dh_compute_key (KEY *k, KEY *y, KEY *x, KEY *n);
  65. /*
  66. * RNG API
  67. */
  68. #define ZENBRIDGE_RNG_DIRECT 0
  69. #define ZENBRIDGE_RNG_SHA1 1
  70. typedef int t_zencod_rand_bytes (KEY *rand, unsigned int flags);
  71. /*
  72. * Math API
  73. */
  74. typedef int t_zencod_math_mod_exp (KEY *r, KEY *a, KEY *e, KEY *n);
  75. /*
  76. * Symetric API
  77. */
  78. /* Define a data structure for digests operations */
  79. typedef struct ZEN_data_st
  80. {
  81. unsigned int HashBufferSize ;
  82. unsigned char *HashBuffer ;
  83. } ZEN_MD_DATA ;
  84. /*
  85. * Functions for Digest (MD5, SHA1) stuff
  86. */
  87. /* output : output data buffer */
  88. /* input : input data buffer */
  89. /* algo : hash algorithm, MD5 or SHA1 */
  90. /* typedef int t_zencod_hash ( KEY *output, const KEY *input, int algo ) ;
  91. * typedef int t_zencod_sha_hash ( KEY *output, const KEY *input, int algo ) ;
  92. */
  93. /* For now separate this stuff that mad it easier to test */
  94. typedef int t_zencod_md5_init ( ZEN_MD_DATA *data ) ;
  95. typedef int t_zencod_md5_update ( ZEN_MD_DATA *data, const KEY *input ) ;
  96. typedef int t_zencod_md5_do_final ( ZEN_MD_DATA *data, KEY *output ) ;
  97. typedef int t_zencod_sha1_init ( ZEN_MD_DATA *data ) ;
  98. typedef int t_zencod_sha1_update ( ZEN_MD_DATA *data, const KEY *input ) ;
  99. typedef int t_zencod_sha1_do_final ( ZEN_MD_DATA *data, KEY *output ) ;
  100. /*
  101. * Functions for Cipher (RC4, DES, 3DES) stuff
  102. */
  103. /* output : output data buffer */
  104. /* input : input data buffer */
  105. /* key : rc4 key data */
  106. /* index_1 : value of index x from RC4 key structure */
  107. /* index_2 : value of index y from RC4 key structure */
  108. /* Be carefull : RC4 key should be expanded before calling this method (Should we provide an expand function ??) */
  109. typedef int t_zencod_rc4_cipher ( KEY *output, const KEY *input, const KEY *key,
  110. unsigned char *index_1, unsigned char *index_2, int mode ) ;
  111. /* output : output data buffer */
  112. /* input : input data buffer */
  113. /* key_1 : des first key data */
  114. /* key_2 : des second key data */
  115. /* key_3 : des third key data */
  116. /* iv : initial vector */
  117. /* mode : xdes mode (encrypt or decrypt) */
  118. /* Be carefull : In DES mode key_1 = key_2 = key_3 (as far as i can see !!) */
  119. typedef int t_zencod_xdes_cipher ( KEY *output, const KEY *input, const KEY *key_1,
  120. const KEY *key_2, const KEY *key_3, const KEY *iv, int mode ) ;
  121. #undef KEY
  122. #ifdef __cplusplus
  123. }
  124. #endif /* __cplusplus */
  125. #endif /* !_HW_ZENCOD_H_ */