2018-02-27 22:01:25

by Hernán Gonzalez

[permalink] [raw]
Subject: [PATCH 1/4] crypto: bcm: Remove unused variable (char *tag_to_hash_idx[])

Note: this is compile only tested.
Variable was not used anywhere in the code, remove it and save 20 bytes.

add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-20 (-20)
Function old new delta
tag_to_hash_idx 20 - -20
Total: Before=9185256, After=9185236, chg -0.00%

Signed-off-by: Hernán Gonzalez <[email protected]>
---
drivers/crypto/bcm/spu.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/crypto/bcm/spu.c b/drivers/crypto/bcm/spu.c
index dbb5c03..c3d177d 100644
--- a/drivers/crypto/bcm/spu.c
+++ b/drivers/crypto/bcm/spu.c
@@ -23,8 +23,6 @@
#include "cipher.h"

/* This array is based on the hash algo type supported in spu.h */
-char *tag_to_hash_idx[] = { "none", "md5", "sha1", "sha224", "sha256" };
-
char *hash_alg_name[] = { "None", "md5", "sha1", "sha224", "sha256", "aes",
"sha384", "sha512", "sha3_224", "sha3_256", "sha3_384", "sha3_512" };

--
2.7.4


2018-02-27 22:01:26

by Hernán Gonzalez

[permalink] [raw]
Subject: [PATCH 2/4] crypto: bcm: Move *aead_alg_name[] from spu.c to util.c. Constify too.

Note: This is compile only tested.
Move variable to where it is actually used. No gain from this except for
some self-documenting.

Signed-off-by: Hernán Gonzalez <[email protected]>
---
drivers/crypto/bcm/spu.c | 2 --
drivers/crypto/bcm/spu.h | 1 -
drivers/crypto/bcm/util.c | 2 ++
3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/bcm/spu.c b/drivers/crypto/bcm/spu.c
index c3d177d..efaf3cf 100644
--- a/drivers/crypto/bcm/spu.c
+++ b/drivers/crypto/bcm/spu.c
@@ -26,8 +26,6 @@
char *hash_alg_name[] = { "None", "md5", "sha1", "sha224", "sha256", "aes",
"sha384", "sha512", "sha3_224", "sha3_256", "sha3_384", "sha3_512" };

-char *aead_alg_name[] = { "ccm(aes)", "gcm(aes)", "authenc" };
-
/* Assumes SPU-M messages are in big endian */
void spum_dump_msg_hdr(u8 *buf, unsigned int buf_len)
{
diff --git a/drivers/crypto/bcm/spu.h b/drivers/crypto/bcm/spu.h
index aa6fc38..f252367 100644
--- a/drivers/crypto/bcm/spu.h
+++ b/drivers/crypto/bcm/spu.h
@@ -112,7 +112,6 @@ enum aead_type {
};

extern char *hash_alg_name[HASH_ALG_LAST];
-extern char *aead_alg_name[AEAD_TYPE_LAST];

struct spu_request_opts {
bool is_inbound;
diff --git a/drivers/crypto/bcm/util.c b/drivers/crypto/bcm/util.c
index d543c01..fa6161a 100644
--- a/drivers/crypto/bcm/util.c
+++ b/drivers/crypto/bcm/util.c
@@ -23,6 +23,8 @@
#define SPU_OFIFO_CTRL 0x40
#define SPU_FIFO_WATERMARK 0x1FF

+static char const * const aead_alg_name[] = { "ccm(aes)", "gcm(aes)", "authenc" };
+
/**
* spu_sg_at_offset() - Find the scatterlist entry at a given distance from the
* start of a scatterlist.
--
2.7.4

2018-02-27 22:01:27

by Hernán Gonzalez

[permalink] [raw]
Subject: [PATCH 3/4] crypto: bcm: Constify *hash_alg_name[]

Note: This is compile only tested.
No gain from this except some self-documenting.

Signed-off-by: Hernán Gonzalez <[email protected]>
---
drivers/crypto/bcm/spu.c | 5 +++--
drivers/crypto/bcm/spu.h | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/bcm/spu.c b/drivers/crypto/bcm/spu.c
index efaf3cf..c7bb79e 100644
--- a/drivers/crypto/bcm/spu.c
+++ b/drivers/crypto/bcm/spu.c
@@ -23,8 +23,9 @@
#include "cipher.h"

/* This array is based on the hash algo type supported in spu.h */
-char *hash_alg_name[] = { "None", "md5", "sha1", "sha224", "sha256", "aes",
- "sha384", "sha512", "sha3_224", "sha3_256", "sha3_384", "sha3_512" };
+char const * const hash_alg_name[] = { "None", "md5", "sha1", "sha224",
+ "sha256", "aes", "sha384", "sha512", "sha3_224", "sha3_256", "sha3_384",
+ "sha3_512" };

/* Assumes SPU-M messages are in big endian */
void spum_dump_msg_hdr(u8 *buf, unsigned int buf_len)
diff --git a/drivers/crypto/bcm/spu.h b/drivers/crypto/bcm/spu.h
index f252367..71cf6b5 100644
--- a/drivers/crypto/bcm/spu.h
+++ b/drivers/crypto/bcm/spu.h
@@ -111,7 +111,7 @@ enum aead_type {
AEAD_TYPE_LAST
};

-extern char *hash_alg_name[HASH_ALG_LAST];
+extern const char * const hash_alg_name[HASH_ALG_LAST];

struct spu_request_opts {
bool is_inbound;
--
2.7.4

2018-02-27 22:01:28

by Hernán Gonzalez

[permalink] [raw]
Subject: [PATCH 4/4] crypto: bcm: Constify variables in spu2.c

Note: This is compile only tested.
Variables constified:
*spu2_cipher_type_names
*spu2_hash_mode_names
*spu2_cipher_mode_names
*spu2_hash_type_names

Constifying and declaring as static saves 160 bytes.

add/remove: 0/4 grow/shrink: 0/0 up/down: 0/-160 (-160)
Function old new delta
spu2_cipher_type_names 24 - -24
spu2_hash_mode_names 32 - -32
spu2_cipher_mode_names 32 - -32
spu2_hash_type_names 72 - -72
Total: Before=9185236, After=9185076, chg -0.00%

Signed-off-by: Hernán Gonzalez <[email protected]>
---
drivers/crypto/bcm/spu2.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/bcm/spu2.c b/drivers/crypto/bcm/spu2.c
index bf7ac62..fcf3885 100644
--- a/drivers/crypto/bcm/spu2.c
+++ b/drivers/crypto/bcm/spu2.c
@@ -49,22 +49,22 @@ enum spu2_proto_sel {
SPU2_DTLS_AEAD = 10
};

-char *spu2_cipher_type_names[] = { "None", "AES128", "AES192", "AES256",
- "DES", "3DES"
+static char * const spu2_cipher_type_names[] = { "None", "AES128", "AES192",
+ "AES256", "DES", "3DES"
};

-char *spu2_cipher_mode_names[] = { "ECB", "CBC", "CTR", "CFB", "OFB", "XTS",
- "CCM", "GCM"
+static char * const spu2_cipher_mode_names[] = { "ECB", "CBC", "CTR", "CFB",
+ "OFB", "XTS", "CCM", "GCM"
};

-char *spu2_hash_type_names[] = { "None", "AES128", "AES192", "AES256",
- "Reserved", "Reserved", "MD5", "SHA1", "SHA224", "SHA256", "SHA384",
- "SHA512", "SHA512/224", "SHA512/256", "SHA3-224", "SHA3-256",
+static char * const spu2_hash_type_names[] = { "None", "AES128", "AES192",
+ "AES256", "Reserved", "Reserved", "MD5", "SHA1", "SHA224", "SHA256",
+ "SHA384", "SHA512", "SHA512/224", "SHA512/256", "SHA3-224", "SHA3-256",
"SHA3-384", "SHA3-512"
};

-char *spu2_hash_mode_names[] = { "CMAC", "CBC-MAC", "XCBC-MAC", "HMAC",
- "Rabin", "CCM", "GCM", "Reserved"
+static char * const spu2_hash_mode_names[] = { "CMAC", "CBC-MAC", "XCBC-MAC",
+ "HMAC", "Rabin", "CCM", "GCM", "Reserved"
};

static char *spu2_ciph_type_name(enum spu2_cipher_type cipher_type)
--
2.7.4

2018-03-09 14:29:55

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 3/4] crypto: bcm: Constify *hash_alg_name[]

On Tue, Feb 27, 2018 at 07:01:27PM -0300, Hern?n Gonzalez wrote:
> Note: This is compile only tested.
> No gain from this except some self-documenting.
>
> Signed-off-by: Hern?n Gonzalez <[email protected]>
> ---
> drivers/crypto/bcm/spu.c | 5 +++--
> drivers/crypto/bcm/spu.h | 2 +-
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/crypto/bcm/spu.c b/drivers/crypto/bcm/spu.c
> index efaf3cf..c7bb79e 100644
> --- a/drivers/crypto/bcm/spu.c
> +++ b/drivers/crypto/bcm/spu.c
> @@ -23,8 +23,9 @@
> #include "cipher.h"
>
> /* This array is based on the hash algo type supported in spu.h */
> -char *hash_alg_name[] = { "None", "md5", "sha1", "sha224", "sha256", "aes",
> - "sha384", "sha512", "sha3_224", "sha3_256", "sha3_384", "sha3_512" };
> +char const * const hash_alg_name[] = { "None", "md5", "sha1", "sha224",

Please make that

const char *const

Ditto with patch 4.

Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2018-03-09 14:35:35

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 3/4] crypto: bcm: Constify *hash_alg_name[]

On Fri, 2018-03-09 at 22:29 +0800, Herbert Xu wrote:
> On Tue, Feb 27, 2018 at 07:01:27PM -0300, Hern?n Gonzalez wrote:
> > Note: This is compile only tested.
> > No gain from this except some self-documenting.
[]
> > diff --git a/drivers/crypto/bcm/spu.c b/drivers/crypto/bcm/spu.c
[]
> > @@ -23,8 +23,9 @@
> > #include "cipher.h"
> >
> > /* This array is based on the hash algo type supported in spu.h */
> > -char *hash_alg_name[] = { "None", "md5", "sha1", "sha224", "sha256", "aes",
> > - "sha384", "sha512", "sha3_224", "sha3_256", "sha3_384", "sha3_512" };
> > +char const * const hash_alg_name[] = { "None", "md5", "sha1", "sha224",
>
> Please make that
>
> const char *const
>
> Ditto with patch 4.
>
> Thanks,

and likely, as this is a global name, it should
be something like crypto_hash_alg_name

2018-03-09 15:04:10

by Kamil Konieczny

[permalink] [raw]
Subject: Re: [PATCH 3/4] crypto: bcm: Constify *hash_alg_name[]



On 27.02.2018 23:01, Hernán Gonzalez wrote:
> Note: This is compile only tested.
> No gain from this except some self-documenting.
>
> Signed-off-by: Hernán Gonzalez <[email protected]>
> ---
> drivers/crypto/bcm/spu.c | 5 +++--
> drivers/crypto/bcm/spu.h | 2 +-
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/crypto/bcm/spu.c b/drivers/crypto/bcm/spu.c
> index efaf3cf..c7bb79e 100644
> --- a/drivers/crypto/bcm/spu.c
> +++ b/drivers/crypto/bcm/spu.c
> @@ -23,8 +23,9 @@
> #include "cipher.h"
>
> /* This array is based on the hash algo type supported in spu.h */
> -char *hash_alg_name[] = { "None", "md5", "sha1", "sha224", "sha256", "aes",

------------------------------------------------------------------------ ^^^

'aes' is not hash, so either remove 'aes' or change array name to crypto_alg_name

Or maybe I am missing something, or is it hardcoded in silicon ?

> - "sha384", "sha512", "sha3_224", "sha3_256", "sha3_384", "sha3_512" };
> +char const * const hash_alg_name[] = { "None", "md5", "sha1", "sha224",
> + "sha256", "aes", "sha384", "sha512", "sha3_224", "sha3_256", "sha3_384",
> + "sha3_512" };
>
> /* Assumes SPU-M messages are in big endian */
> void spum_dump_msg_hdr(u8 *buf, unsigned int buf_len)
> diff --git a/drivers/crypto/bcm/spu.h b/drivers/crypto/bcm/spu.h
> index f252367..71cf6b5 100644
> --- a/drivers/crypto/bcm/spu.h
> +++ b/drivers/crypto/bcm/spu.h
> @@ -111,7 +111,7 @@ enum aead_type {
> AEAD_TYPE_LAST
> };
>
> -extern char *hash_alg_name[HASH_ALG_LAST];
> +extern const char * const hash_alg_name[HASH_ALG_LAST];
>
> struct spu_request_opts {
> bool is_inbound;
>

--
Best regards,
Kamil Konieczny
Samsung R&D Institute Poland

2018-03-09 15:04:11

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 3/4] crypto: bcm: Constify *hash_alg_name[]

On Fri, Mar 09, 2018 at 06:35:35AM -0800, Joe Perches wrote:
>
> and likely, as this is a global name, it should
> be something like crypto_hash_alg_name

crypto_ is not a good prefix here. Perhaps crypto_bcm_.

Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt