Print this page
fixup .text where possible
7127  remove -Wno-missing-braces from Makefile.uts


  38 /*
  39  * The sha2 module is created with two modlinkages:
  40  * - a modlmisc that allows consumers to directly call the entry points
  41  *   SHA2Init, SHA2Update, and SHA2Final.
  42  * - a modlcrypto that allows the module to register with the Kernel
  43  *   Cryptographic Framework (KCF) as a software provider for the SHA2
  44  *   mechanisms.
  45  */
  46 
  47 static struct modlmisc modlmisc = {
  48         &mod_miscops,
  49         "SHA2 Message-Digest Algorithm"
  50 };
  51 
  52 static struct modlcrypto modlcrypto = {
  53         &mod_cryptoops,
  54         "SHA2 Kernel SW Provider"
  55 };
  56 
  57 static struct modlinkage modlinkage = {
  58         MODREV_1, &modlmisc, &modlcrypto, NULL
  59 };
  60 
  61 /*
  62  * Macros to access the SHA2 or SHA2-HMAC contexts from a context passed
  63  * by KCF to one of the entry points.
  64  */
  65 
  66 #define PROV_SHA2_CTX(ctx)      ((sha2_ctx_t *)(ctx)->cc_provider_private)
  67 #define PROV_SHA2_HMAC_CTX(ctx) ((sha2_hmac_ctx_t *)(ctx)->cc_provider_private)
  68 
  69 /* to extract the digest length passed as mechanism parameter */
  70 #define PROV_SHA2_GET_DIGEST_LEN(m, len) {                              \
  71         if (IS_P2ALIGNED((m)->cm_param, sizeof (ulong_t)))           \
  72                 (len) = (uint32_t)*((ulong_t *)(void *)(m)->cm_param);       \
  73         else {                                                          \
  74                 ulong_t tmp_ulong;                                      \
  75                 bcopy((m)->cm_param, &tmp_ulong, sizeof (ulong_t));      \
  76                 (len) = (uint32_t)tmp_ulong;                            \
  77         }                                                               \
  78 }


 173 static crypto_mac_ops_t sha2_mac_ops = {
 174         sha2_mac_init,
 175         NULL,
 176         sha2_mac_update,
 177         sha2_mac_final,
 178         sha2_mac_atomic,
 179         sha2_mac_verify_atomic
 180 };
 181 
 182 static int sha2_create_ctx_template(crypto_provider_handle_t,
 183     crypto_mechanism_t *, crypto_key_t *, crypto_spi_ctx_template_t *,
 184     size_t *, crypto_req_handle_t);
 185 static int sha2_free_context(crypto_ctx_t *);
 186 
 187 static crypto_ctx_ops_t sha2_ctx_ops = {
 188         sha2_create_ctx_template,
 189         sha2_free_context
 190 };
 191 
 192 static crypto_ops_t sha2_crypto_ops = {
 193         &sha2_control_ops,
 194         &sha2_digest_ops,
 195         NULL,
 196         &sha2_mac_ops,
 197         NULL,
 198         NULL,
 199         NULL,
 200         NULL,
 201         NULL,
 202         NULL,
 203         NULL,
 204         NULL,
 205         NULL,
 206         &sha2_ctx_ops,
 207         NULL,
 208         NULL,
 209         NULL,
 210 };
 211 
 212 static crypto_provider_info_t sha2_prov_info = {
 213         CRYPTO_SPI_VERSION_4,
 214         "SHA2 Software Provider",
 215         CRYPTO_SW_PROVIDER,
 216         {&modlinkage},
 217         NULL,
 218         &sha2_crypto_ops,
 219         sizeof (sha2_mech_info_tab)/sizeof (crypto_mech_info_t),
 220         sha2_mech_info_tab
 221 };
 222 
 223 static crypto_kcf_provider_handle_t sha2_prov_handle = NULL;
 224 
 225 int
 226 _init()
 227 {
 228         int ret;
 229 
 230         if ((ret = mod_install(&modlinkage)) != 0)
 231                 return (ret);
 232 
 233         /*
 234          * Register with KCF. If the registration fails, do not uninstall the
 235          * module, since the functionality provided by misc/sha2 should still
 236          * be available.
 237          */
 238         (void) crypto_register_provider(&sha2_prov_info, &sha2_prov_handle);
 239 
 240         return (0);
 241 }




  38 /*
  39  * The sha2 module is created with two modlinkages:
  40  * - a modlmisc that allows consumers to directly call the entry points
  41  *   SHA2Init, SHA2Update, and SHA2Final.
  42  * - a modlcrypto that allows the module to register with the Kernel
  43  *   Cryptographic Framework (KCF) as a software provider for the SHA2
  44  *   mechanisms.
  45  */
  46 
  47 static struct modlmisc modlmisc = {
  48         &mod_miscops,
  49         "SHA2 Message-Digest Algorithm"
  50 };
  51 
  52 static struct modlcrypto modlcrypto = {
  53         &mod_cryptoops,
  54         "SHA2 Kernel SW Provider"
  55 };
  56 
  57 static struct modlinkage modlinkage = {
  58         MODREV_1, { &modlmisc, &modlcrypto, NULL }
  59 };
  60 
  61 /*
  62  * Macros to access the SHA2 or SHA2-HMAC contexts from a context passed
  63  * by KCF to one of the entry points.
  64  */
  65 
  66 #define PROV_SHA2_CTX(ctx)      ((sha2_ctx_t *)(ctx)->cc_provider_private)
  67 #define PROV_SHA2_HMAC_CTX(ctx) ((sha2_hmac_ctx_t *)(ctx)->cc_provider_private)
  68 
  69 /* to extract the digest length passed as mechanism parameter */
  70 #define PROV_SHA2_GET_DIGEST_LEN(m, len) {                              \
  71         if (IS_P2ALIGNED((m)->cm_param, sizeof (ulong_t)))           \
  72                 (len) = (uint32_t)*((ulong_t *)(void *)(m)->cm_param);       \
  73         else {                                                          \
  74                 ulong_t tmp_ulong;                                      \
  75                 bcopy((m)->cm_param, &tmp_ulong, sizeof (ulong_t));      \
  76                 (len) = (uint32_t)tmp_ulong;                            \
  77         }                                                               \
  78 }


 173 static crypto_mac_ops_t sha2_mac_ops = {
 174         sha2_mac_init,
 175         NULL,
 176         sha2_mac_update,
 177         sha2_mac_final,
 178         sha2_mac_atomic,
 179         sha2_mac_verify_atomic
 180 };
 181 
 182 static int sha2_create_ctx_template(crypto_provider_handle_t,
 183     crypto_mechanism_t *, crypto_key_t *, crypto_spi_ctx_template_t *,
 184     size_t *, crypto_req_handle_t);
 185 static int sha2_free_context(crypto_ctx_t *);
 186 
 187 static crypto_ctx_ops_t sha2_ctx_ops = {
 188         sha2_create_ctx_template,
 189         sha2_free_context
 190 };
 191 
 192 static crypto_ops_t sha2_crypto_ops = {
 193         .co_control_ops = &sha2_control_ops,
 194         .co_digest_ops = &sha2_digest_ops,
 195         .co_mac_ops = &sha2_mac_ops,
 196         .co_ctx_ops = &sha2_ctx_ops













 197 };
 198 
 199 static crypto_provider_info_t sha2_prov_info = {{{{
 200         CRYPTO_SPI_VERSION_4,
 201         "SHA2 Software Provider",
 202         CRYPTO_SW_PROVIDER,
 203         {&modlinkage},
 204         NULL,
 205         &sha2_crypto_ops,
 206         sizeof (sha2_mech_info_tab)/sizeof (crypto_mech_info_t),
 207         sha2_mech_info_tab
 208 }}}};
 209 
 210 static crypto_kcf_provider_handle_t sha2_prov_handle = NULL;
 211 
 212 int
 213 _init()
 214 {
 215         int ret;
 216 
 217         if ((ret = mod_install(&modlinkage)) != 0)
 218                 return (ret);
 219 
 220         /*
 221          * Register with KCF. If the registration fails, do not uninstall the
 222          * module, since the functionality provided by misc/sha2 should still
 223          * be available.
 224          */
 225         (void) crypto_register_provider(&sha2_prov_info, &sha2_prov_handle);
 226 
 227         return (0);
 228 }