Commit c99bec6e authored by Jon Grimm's avatar Jon Grimm Committed by Sridhar Samudrala

[SCTP] Add wrappers for sctp with no crypto support.

parent 8d0df569
...@@ -328,6 +328,18 @@ static inline void sctp_v6_exit(void) { return; } ...@@ -328,6 +328,18 @@ static inline void sctp_v6_exit(void) { return; }
#endif /* #if defined(CONFIG_IPV6) */ #endif /* #if defined(CONFIG_IPV6) */
/* Some wrappers, in case crypto not available. */
#if defined (CONFIG_CRYPTO_HMAC)
#define sctp_crypto_alloc_tfm crypto_alloc_tfm
#define sctp_crypto_free_tfm crypto_free_tfm
#define sctp_crypto_hmac crypto_hmac
#else
#define sctp_crypto_alloc_tfm(x...) NULL
#define sctp_crypto_free_tfm(x...)
#define sctp_crypto_hmac(x...)
#endif
/* Map an association to an assoc_id. */ /* Map an association to an assoc_id. */
static inline sctp_assoc_t sctp_assoc2id(const sctp_association_t *asoc) static inline sctp_assoc_t sctp_assoc2id(const sctp_association_t *asoc)
{ {
......
...@@ -203,7 +203,7 @@ void sctp_endpoint_destroy(struct sctp_endpoint *ep) ...@@ -203,7 +203,7 @@ void sctp_endpoint_destroy(struct sctp_endpoint *ep)
/* Free up the HMAC transform. */ /* Free up the HMAC transform. */
if (sctp_sk(ep->base.sk)->hmac) if (sctp_sk(ep->base.sk)->hmac)
crypto_free_tfm(sctp_sk(ep->base.sk)->hmac); sctp_crypto_free_tfm(sctp_sk(ep->base.sk)->hmac);
/* Cleanup. */ /* Cleanup. */
sctp_inq_free(&ep->base.inqueue); sctp_inq_free(&ep->base.inqueue);
......
...@@ -1358,7 +1358,7 @@ sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep, ...@@ -1358,7 +1358,7 @@ sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
sctp_signed_cookie_t *cookie; sctp_signed_cookie_t *cookie;
struct scatterlist sg; struct scatterlist sg;
int headersize, bodysize; int headersize, bodysize;
unsigned int keylen = SCTP_SECRET_SIZE; unsigned int keylen;
char *key; char *key;
headersize = sizeof(sctp_paramhdr_t) + SCTP_SECRET_SIZE; headersize = sizeof(sctp_paramhdr_t) + SCTP_SECRET_SIZE;
...@@ -1412,10 +1412,11 @@ sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep, ...@@ -1412,10 +1412,11 @@ sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
sg.page = virt_to_page(&cookie->c); sg.page = virt_to_page(&cookie->c);
sg.offset = (unsigned long)(&cookie->c) % PAGE_SIZE; sg.offset = (unsigned long)(&cookie->c) % PAGE_SIZE;
sg.length = bodysize; sg.length = bodysize;
keylen = SCTP_SECRET_SIZE;
key = (char *)ep->secret_key[ep->current_key]; key = (char *)ep->secret_key[ep->current_key];
crypto_hmac(sctp_sk(ep->base.sk)->hmac, key, &keylen, &sg, 1, sctp_crypto_hmac(sctp_sk(ep->base.sk)->hmac, key, &keylen,
cookie->signature); &sg, 1, cookie->signature);
} }
nodata: nodata:
...@@ -1471,14 +1472,15 @@ struct sctp_association *sctp_unpack_cookie( ...@@ -1471,14 +1472,15 @@ struct sctp_association *sctp_unpack_cookie(
key = (char *)ep->secret_key[ep->current_key]; key = (char *)ep->secret_key[ep->current_key];
memset(digest, 0x00, sizeof(digest)); memset(digest, 0x00, sizeof(digest));
crypto_hmac(sctp_sk(ep->base.sk)->hmac, key, &keylen, &sg, 1, digest); sctp_crypto_hmac(sctp_sk(ep->base.sk)->hmac, key, &keylen, &sg,
1, digest);
if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) { if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) {
/* Try the previous key. */ /* Try the previous key. */
key = (char *)ep->secret_key[ep->last_key]; key = (char *)ep->secret_key[ep->last_key];
memset(digest, 0x00, sizeof(digest)); memset(digest, 0x00, sizeof(digest));
crypto_hmac(sctp_sk(ep->base.sk)->hmac, key, &keylen, &sg, 1, sctp_crypto_hmac(sctp_sk(ep->base.sk)->hmac, key, &keylen,
digest); &sg, 1, digest);
if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) { if (memcmp(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) {
/* Yikes! Still bad signature! */ /* Yikes! Still bad signature! */
......
...@@ -2745,7 +2745,7 @@ int sctp_inet_listen(struct socket *sock, int backlog) ...@@ -2745,7 +2745,7 @@ int sctp_inet_listen(struct socket *sock, int backlog)
/* Allocate HMAC for generating cookie. */ /* Allocate HMAC for generating cookie. */
if (sctp_hmac_alg) { if (sctp_hmac_alg) {
tfm = crypto_alloc_tfm(sctp_hmac_alg, 0); tfm = sctp_crypto_alloc_tfm(sctp_hmac_alg, 0);
if (!tfm) { if (!tfm) {
err = -ENOSYS; err = -ENOSYS;
goto out; goto out;
...@@ -2772,7 +2772,7 @@ int sctp_inet_listen(struct socket *sock, int backlog) ...@@ -2772,7 +2772,7 @@ int sctp_inet_listen(struct socket *sock, int backlog)
return err; return err;
cleanup: cleanup:
if (tfm) if (tfm)
crypto_free_tfm(tfm); sctp_crypto_free_tfm(tfm);
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment