diff mbox series

[API-NEXT,4/4] api: crypto: enforce deprecated API status

Message ID 1487859248-23273-4-git-send-email-petri.savolainen@linaro.org
State New
Headers show
Series [API-NEXT,1/4] api: hints: remove ODP_DEPRECATED from API | expand

Commit Message

Petri Savolainen Feb. 23, 2017, 2:14 p.m. UTC
Used ODP_DEPRECATED to control if deprecated API definitions are
visible in the API or not.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
 include/odp/api/spec/crypto.h       | 16 +++++++++++--
 platform/linux-generic/odp_crypto.c | 45 +++++++++++++++++++++++++------------
 2 files changed, 45 insertions(+), 16 deletions(-)

-- 
2.8.1
diff mbox series

Patch

diff --git a/include/odp/api/spec/crypto.h b/include/odp/api/spec/crypto.h
index 9855bf9..bba1c08 100644
--- a/include/odp/api/spec/crypto.h
+++ b/include/odp/api/spec/crypto.h
@@ -15,6 +15,8 @@ 
 #define ODP_API_CRYPTO_H_
 #include <odp/visibility_begin.h>
 
+#include <odp/api/deprecated.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -81,11 +83,13 @@  typedef enum {
 	 */
 	ODP_CIPHER_ALG_AES_GCM,
 
+#if ODP_DEPRECATED
 	/** @deprecated  Use ODP_CIPHER_ALG_AES_CBC instead */
 	ODP_CIPHER_ALG_AES128_CBC,
 
 	/** @deprecated  Use ODP_CIPHER_ALG_AES_GCM instead */
 	ODP_CIPHER_ALG_AES128_GCM
+#endif
 
 } odp_cipher_alg_t;
 
@@ -114,6 +118,7 @@  typedef enum {
 	 */
 	ODP_AUTH_ALG_AES_GCM,
 
+#if ODP_DEPRECATED
 	/** @deprecated  Use ODP_AUTH_ALG_MD5_HMAC instead */
 	ODP_AUTH_ALG_MD5_96,
 
@@ -122,6 +127,7 @@  typedef enum {
 
 	/** @deprecated  Use ODP_AUTH_ALG_AES_GCM instead */
 	ODP_AUTH_ALG_AES128_GCM
+#endif
 } odp_auth_alg_t;
 
 /**
@@ -144,12 +150,13 @@  typedef union odp_crypto_cipher_algos_t {
 
 		/** ODP_CIPHER_ALG_AES_GCM */
 		uint32_t aes_gcm     : 1;
-
+#if ODP_DEPRECATED
 		/** @deprecated  Use aes_cbc instead */
 		uint32_t aes128_cbc  : 1;
 
 		/** @deprecated  Use aes_gcm instead */
 		uint32_t aes128_gcm  : 1;
+#endif
 	} bit;
 
 	/** All bits of the bit field structure
@@ -176,7 +183,7 @@  typedef union odp_crypto_auth_algos_t {
 
 		/** ODP_AUTH_ALG_AES_GCM */
 		uint32_t aes_gcm     : 1;
-
+#if ODP_DEPRECATED
 		/** @deprecated  Use md5_hmac instead */
 		uint32_t md5_96      : 1;
 
@@ -185,6 +192,7 @@  typedef union odp_crypto_auth_algos_t {
 
 		/** @deprecated  Use aes_gcm instead */
 		uint32_t aes128_gcm  : 1;
+#endif
 	} bit;
 
 	/** All bits of the bit field structure
@@ -298,8 +306,10 @@  typedef struct odp_crypto_session_param_t {
 
 } odp_crypto_session_param_t;
 
+#if ODP_DEPRECATED
 /** @deprecated  Use odp_crypto_session_param_t instead */
 typedef odp_crypto_session_param_t odp_crypto_session_params_t;
+#endif
 
 /**
  * Crypto API per packet operation parameters
@@ -354,8 +364,10 @@  typedef struct odp_crypto_op_param_t {
 
 } odp_crypto_op_param_t;
 
+#if ODP_DEPRECATED
 /** @deprecated  Use odp_crypto_op_param_t instead */
 typedef odp_crypto_op_param_t odp_crypto_op_params_t;
+#endif
 
 /**
  * Crypto API session creation return code
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index b53b0fc..de03e7e 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -642,12 +642,13 @@  int odp_crypto_capability(odp_crypto_capability_t *capa)
 	capa->auths.bit.sha256_hmac  = 1;
 	capa->auths.bit.aes_gcm      = 1;
 
-	/* Deprecated */
+#if ODP_DEPRECATED
 	capa->ciphers.bit.aes128_cbc = 1;
 	capa->ciphers.bit.aes128_gcm = 1;
 	capa->auths.bit.md5_96       = 1;
 	capa->auths.bit.sha256_128   = 1;
 	capa->auths.bit.aes128_gcm   = 1;
+#endif
 
 	capa->max_sessions = MAX_SESSIONS;
 
@@ -738,6 +739,7 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 {
 	int rc;
 	odp_crypto_generic_session_t *session;
+	int aes_gcm = 0;
 
 	/* Default to successful result */
 	*status = ODP_CRYPTO_SES_CREATE_ERR_NONE;
@@ -780,17 +782,21 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 		rc = process_des_param(session);
 		break;
 	case ODP_CIPHER_ALG_AES_CBC:
-	     /* deprecated */
+#if ODP_DEPRECATED
 	case ODP_CIPHER_ALG_AES128_CBC:
+#endif
 		rc = process_aes_param(session);
 		break;
-	case ODP_CIPHER_ALG_AES_GCM:
-	     /* deprecated */
+#if ODP_DEPRECATED
 	case ODP_CIPHER_ALG_AES128_GCM:
+		if (param->auth_alg == ODP_AUTH_ALG_AES128_GCM)
+			aes_gcm = 1;
+		/* Fallthrough */
+#endif
+	case ODP_CIPHER_ALG_AES_GCM:
 		/* AES-GCM requires to do both auth and
 		 * cipher at the same time */
-		if (param->auth_alg == ODP_AUTH_ALG_AES_GCM ||
-		    param->auth_alg == ODP_AUTH_ALG_AES128_GCM)
+		if (param->auth_alg == ODP_AUTH_ALG_AES_GCM || aes_gcm)
 			rc = process_aes_gcm_param(session);
 		else
 			rc = -1;
@@ -805,6 +811,8 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 		return -1;
 	}
 
+	aes_gcm = 0;
+
 	/* Process based on auth */
 	switch (param->auth_alg) {
 	case ODP_AUTH_ALG_NULL:
@@ -812,22 +820,27 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 		rc = 0;
 		break;
 	case ODP_AUTH_ALG_MD5_HMAC:
-	     /* deprecated */
+#if ODP_DEPRECATED
 	case ODP_AUTH_ALG_MD5_96:
+#endif
 		rc = process_md5_param(session, 96);
 		break;
 	case ODP_AUTH_ALG_SHA256_HMAC:
-	     /* deprecated */
+#if ODP_DEPRECATED
 	case ODP_AUTH_ALG_SHA256_128:
+#endif
 		rc = process_sha256_param(session, 128);
 		break;
-	case ODP_AUTH_ALG_AES_GCM:
-	     /* deprecated */
+#if ODP_DEPRECATED
 	case ODP_AUTH_ALG_AES128_GCM:
+		if (param->cipher_alg == ODP_CIPHER_ALG_AES128_GCM)
+			aes_gcm = 1;
+		/* Fallthrough */
+#endif
+	case ODP_AUTH_ALG_AES_GCM:
 		/* AES-GCM requires to do both auth and
 		 * cipher at the same time */
-		if (param->cipher_alg == ODP_CIPHER_ALG_AES_GCM ||
-		    param->cipher_alg == ODP_CIPHER_ALG_AES128_GCM) {
+		if (param->cipher_alg == ODP_CIPHER_ALG_AES_GCM || aes_gcm) {
 			session->auth.func = null_crypto_routine;
 			rc = 0;
 		} else {
@@ -852,10 +865,14 @@  odp_crypto_session_create(odp_crypto_session_param_t *param,
 int odp_crypto_session_destroy(odp_crypto_session_t session)
 {
 	odp_crypto_generic_session_t *generic;
+	int aes_gcm = 0;
 
 	generic = (odp_crypto_generic_session_t *)(intptr_t)session;
-	if (generic->p.cipher_alg == ODP_CIPHER_ALG_AES128_GCM ||
-	    generic->p.cipher_alg == ODP_CIPHER_ALG_AES_GCM)
+#if ODP_DEPRECATED
+	if (generic->p.cipher_alg == ODP_CIPHER_ALG_AES128_GCM)
+		aes_gcm = 1;
+#endif
+	if (generic->p.cipher_alg == ODP_CIPHER_ALG_AES_GCM || aes_gcm)
 		EVP_CIPHER_CTX_free(generic->cipher.data.aes_gcm.ctx);
 	memset(generic, 0, sizeof(*generic));
 	free_session(generic);