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

Function esp_init

freebsd/netipsec/xform_esp.c:142–244  ·  view source on GitHub ↗

* esp_init() is called when an SPI is being set up. */

Source from the content-addressed store, hash-verified

140 * esp_init() is called when an SPI is being set up.
141 */
142static int
143esp_init(struct secasvar *sav, struct xformsw *xsp)
144{
145 const struct enc_xform *txform;
146 struct crypto_session_params csp;
147 int keylen;
148 int error;
149
150 txform = enc_algorithm_lookup(sav->alg_enc);
151 if (txform == NULL) {
152 DPRINTF(("%s: unsupported encryption algorithm %d\n",
153 __func__, sav->alg_enc));
154 return EINVAL;
155 }
156 if (sav->key_enc == NULL) {
157 DPRINTF(("%s: no encoding key for %s algorithm\n",
158 __func__, txform->name));
159 return EINVAL;
160 }
161 if ((sav->flags & (SADB_X_EXT_OLD | SADB_X_EXT_IV4B)) ==
162 SADB_X_EXT_IV4B) {
163 DPRINTF(("%s: 4-byte IV not supported with protocol\n",
164 __func__));
165 return EINVAL;
166 }
167
168 /* subtract off the salt, RFC4106, 8.1 and RFC3686, 5.1 */
169 keylen = _KEYLEN(sav->key_enc) - SAV_ISCTRORGCM(sav) * 4;
170 if (txform->minkey > keylen || keylen > txform->maxkey) {
171 DPRINTF(("%s: invalid key length %u, must be in the range "
172 "[%u..%u] for algorithm %s\n", __func__,
173 keylen, txform->minkey, txform->maxkey,
174 txform->name));
175 return EINVAL;
176 }
177
178 if (SAV_ISCTRORGCM(sav))
179 sav->ivlen = 8; /* RFC4106 3.1 and RFC3686 3.1 */
180 else
181 sav->ivlen = txform->ivsize;
182
183 memset(&csp, 0, sizeof(csp));
184
185 /*
186 * Setup AH-related state.
187 */
188 if (sav->alg_auth != 0) {
189 error = ah_init0(sav, xsp, &csp);
190 if (error)
191 return error;
192 }
193
194 /* NB: override anything set in ah_init0 */
195 sav->tdb_xform = xsp;
196 sav->tdb_encalgxform = txform;
197
198 /*
199 * Whenever AES-GCM is used for encryption, one

Callers

nothing calls this directly

Calls 4

enc_algorithm_lookupFunction · 0.85
memsetFunction · 0.85
ah_init0Function · 0.85
crypto_newsessionFunction · 0.85

Tested by

no test coverage detected