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

Function check_csp

freebsd/opencrypto/crypto.c:746–881  ·  view source on GitHub ↗

Various sanity checks on crypto session parameters. */

Source from the content-addressed store, hash-verified

744
745/* Various sanity checks on crypto session parameters. */
746static bool
747check_csp(const struct crypto_session_params *csp)
748{
749 struct auth_hash *axf;
750
751 /* Mode-independent checks. */
752 if ((csp->csp_flags & ~(SUPPORTED_SES)) != 0)
753 return (false);
754 if (csp->csp_ivlen < 0 || csp->csp_cipher_klen < 0 ||
755 csp->csp_auth_klen < 0 || csp->csp_auth_mlen < 0)
756 return (false);
757 if (csp->csp_auth_key != NULL && csp->csp_auth_klen == 0)
758 return (false);
759 if (csp->csp_cipher_key != NULL && csp->csp_cipher_klen == 0)
760 return (false);
761
762 switch (csp->csp_mode) {
763 case CSP_MODE_COMPRESS:
764 if (!alg_is_compression(csp->csp_cipher_alg))
765 return (false);
766 if (csp->csp_flags & CSP_F_SEPARATE_OUTPUT)
767 return (false);
768 if (csp->csp_flags & CSP_F_SEPARATE_AAD)
769 return (false);
770 if (csp->csp_cipher_klen != 0 || csp->csp_ivlen != 0 ||
771 csp->csp_auth_alg != 0 || csp->csp_auth_klen != 0 ||
772 csp->csp_auth_mlen != 0)
773 return (false);
774 break;
775 case CSP_MODE_CIPHER:
776 if (!alg_is_cipher(csp->csp_cipher_alg))
777 return (false);
778 if (csp->csp_flags & CSP_F_SEPARATE_AAD)
779 return (false);
780 if (csp->csp_cipher_alg != CRYPTO_NULL_CBC) {
781 if (csp->csp_cipher_klen == 0)
782 return (false);
783 if (csp->csp_ivlen == 0)
784 return (false);
785 }
786 if (csp->csp_ivlen >= EALG_MAX_BLOCK_LEN)
787 return (false);
788 if (csp->csp_auth_alg != 0 || csp->csp_auth_klen != 0 ||
789 csp->csp_auth_mlen != 0)
790 return (false);
791 break;
792 case CSP_MODE_DIGEST:
793 if (csp->csp_cipher_alg != 0 || csp->csp_cipher_klen != 0)
794 return (false);
795
796 if (csp->csp_flags & CSP_F_SEPARATE_AAD)
797 return (false);
798
799 /* IV is optional for digests (e.g. GMAC). */
800 if (csp->csp_ivlen >= EALG_MAX_BLOCK_LEN)
801 return (false);
802 if (!alg_is_digest(csp->csp_auth_alg))
803 return (false);

Callers 1

crypto_newsessionFunction · 0.85

Calls 6

alg_is_compressionFunction · 0.85
alg_is_cipherFunction · 0.85
alg_is_digestFunction · 0.85
alg_is_keyed_digestFunction · 0.85
crypto_auth_hashFunction · 0.85
alg_is_aeadFunction · 0.85

Tested by

no test coverage detected