MCPcopy Create free account
hub / github.com/F-Stack/f-stack / swcr_setup_auth

Function swcr_setup_auth

freebsd/opencrypto/cryptosoft.c:1002–1084  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1000}
1001
1002static int
1003swcr_setup_auth(struct swcr_session *ses,
1004 const struct crypto_session_params *csp)
1005{
1006 struct swcr_auth *swa;
1007 struct auth_hash *axf;
1008
1009 swa = &ses->swcr_auth;
1010
1011 axf = crypto_auth_hash(csp);
1012 swa->sw_axf = axf;
1013 if (csp->csp_auth_mlen < 0 || csp->csp_auth_mlen > axf->hashsize)
1014 return (EINVAL);
1015 if (csp->csp_auth_mlen == 0)
1016 swa->sw_mlen = axf->hashsize;
1017 else
1018 swa->sw_mlen = csp->csp_auth_mlen;
1019 swa->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA, M_NOWAIT);
1020 if (swa->sw_ictx == NULL)
1021 return (ENOBUFS);
1022
1023 switch (csp->csp_auth_alg) {
1024 case CRYPTO_SHA1_HMAC:
1025 case CRYPTO_SHA2_224_HMAC:
1026 case CRYPTO_SHA2_256_HMAC:
1027 case CRYPTO_SHA2_384_HMAC:
1028 case CRYPTO_SHA2_512_HMAC:
1029 case CRYPTO_NULL_HMAC:
1030 case CRYPTO_RIPEMD160_HMAC:
1031 swa->sw_octx = malloc(axf->ctxsize, M_CRYPTO_DATA,
1032 M_NOWAIT);
1033 if (swa->sw_octx == NULL)
1034 return (ENOBUFS);
1035
1036 if (csp->csp_auth_key != NULL) {
1037 swcr_authprepare(axf, swa, csp->csp_auth_key,
1038 csp->csp_auth_klen);
1039 }
1040
1041 if (csp->csp_mode == CSP_MODE_DIGEST)
1042 ses->swcr_process = swcr_authcompute;
1043 break;
1044 case CRYPTO_SHA1:
1045 case CRYPTO_SHA2_224:
1046 case CRYPTO_SHA2_256:
1047 case CRYPTO_SHA2_384:
1048 case CRYPTO_SHA2_512:
1049 axf->Init(swa->sw_ictx);
1050 if (csp->csp_mode == CSP_MODE_DIGEST)
1051 ses->swcr_process = swcr_authcompute;
1052 break;
1053 case CRYPTO_AES_NIST_GMAC:
1054 axf->Init(swa->sw_ictx);
1055 axf->Setkey(swa->sw_ictx, csp->csp_auth_key,
1056 csp->csp_auth_klen);
1057 if (csp->csp_mode == CSP_MODE_DIGEST)
1058 ses->swcr_process = swcr_gmac;
1059 break;

Callers 1

swcr_newsessionFunction · 0.85

Calls 4

crypto_auth_hashFunction · 0.85
mallocFunction · 0.85
swcr_authprepareFunction · 0.85
InitMethod · 0.80

Tested by

no test coverage detected