[crypto] Force inlining of trivial wrapper functions

Inspection of the generated assembly shows that gcc will often emit
standalone implementations of frequently invoked functions such as
digest_update(), which contain no logic and exist only as syntactic
sugar.

Force inlining of these functions to reduce the overall binary size.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/1158/head
Michael Brown 2024-02-22 12:55:59 +00:00
parent 075292cc2d
commit 582132fe3f
1 changed files with 55 additions and 44 deletions

View File

@ -212,34 +212,37 @@ struct elliptic_curve {
void *result ); void *result );
}; };
static inline void digest_init ( struct digest_algorithm *digest, static inline __attribute__ (( always_inline )) void
void *ctx ) { digest_init ( struct digest_algorithm *digest, void *ctx ) {
digest->init ( ctx ); digest->init ( ctx );
} }
static inline void digest_update ( struct digest_algorithm *digest, static inline __attribute__ (( always_inline )) void
void *ctx, const void *data, size_t len ) { digest_update ( struct digest_algorithm *digest, void *ctx,
const void *data, size_t len ) {
digest->update ( ctx, data, len ); digest->update ( ctx, data, len );
} }
static inline void digest_final ( struct digest_algorithm *digest, static inline __attribute__ (( always_inline )) void
void *ctx, void *out ) { digest_final ( struct digest_algorithm *digest, void *ctx, void *out ) {
digest->final ( ctx, out ); digest->final ( ctx, out );
} }
static inline int cipher_setkey ( struct cipher_algorithm *cipher, static inline __attribute__ (( always_inline )) int
void *ctx, const void *key, size_t keylen ) { cipher_setkey ( struct cipher_algorithm *cipher, void *ctx,
const void *key, size_t keylen ) {
return cipher->setkey ( ctx, key, keylen ); return cipher->setkey ( ctx, key, keylen );
} }
static inline void cipher_setiv ( struct cipher_algorithm *cipher, static inline __attribute__ (( always_inline )) void
void *ctx, const void *iv, size_t ivlen ) { cipher_setiv ( struct cipher_algorithm *cipher, void *ctx,
const void *iv, size_t ivlen ) {
cipher->setiv ( ctx, iv, ivlen ); cipher->setiv ( ctx, iv, ivlen );
} }
static inline void cipher_encrypt ( struct cipher_algorithm *cipher, static inline __attribute__ (( always_inline )) void
void *ctx, const void *src, void *dst, cipher_encrypt ( struct cipher_algorithm *cipher, void *ctx,
size_t len ) { const void *src, void *dst, size_t len ) {
cipher->encrypt ( ctx, src, dst, len ); cipher->encrypt ( ctx, src, dst, len );
} }
#define cipher_encrypt( cipher, ctx, src, dst, len ) do { \ #define cipher_encrypt( cipher, ctx, src, dst, len ) do { \
@ -247,9 +250,9 @@ static inline void cipher_encrypt ( struct cipher_algorithm *cipher,
cipher_encrypt ( (cipher), (ctx), (src), (dst), (len) ); \ cipher_encrypt ( (cipher), (ctx), (src), (dst), (len) ); \
} while ( 0 ) } while ( 0 )
static inline void cipher_decrypt ( struct cipher_algorithm *cipher, static inline __attribute__ (( always_inline )) void
void *ctx, const void *src, void *dst, cipher_decrypt ( struct cipher_algorithm *cipher, void *ctx,
size_t len ) { const void *src, void *dst, size_t len ) {
cipher->decrypt ( ctx, src, dst, len ); cipher->decrypt ( ctx, src, dst, len );
} }
#define cipher_decrypt( cipher, ctx, src, dst, len ) do { \ #define cipher_decrypt( cipher, ctx, src, dst, len ) do { \
@ -257,71 +260,79 @@ static inline void cipher_decrypt ( struct cipher_algorithm *cipher,
cipher_decrypt ( (cipher), (ctx), (src), (dst), (len) ); \ cipher_decrypt ( (cipher), (ctx), (src), (dst), (len) ); \
} while ( 0 ) } while ( 0 )
static inline void cipher_auth ( struct cipher_algorithm *cipher, void *ctx, static inline __attribute__ (( always_inline )) void
void *auth ) { cipher_auth ( struct cipher_algorithm *cipher, void *ctx, void *auth ) {
cipher->auth ( ctx, auth ); cipher->auth ( ctx, auth );
} }
static inline int is_stream_cipher ( struct cipher_algorithm *cipher ) { static inline __attribute__ (( always_inline )) int
is_stream_cipher ( struct cipher_algorithm *cipher ) {
return ( cipher->blocksize == 1 ); return ( cipher->blocksize == 1 );
} }
static inline int is_block_cipher ( struct cipher_algorithm *cipher ) { static inline __attribute__ (( always_inline )) int
is_block_cipher ( struct cipher_algorithm *cipher ) {
return ( cipher->blocksize > 1 ); return ( cipher->blocksize > 1 );
} }
static inline int is_auth_cipher ( struct cipher_algorithm *cipher ) { static inline __attribute__ (( always_inline )) int
is_auth_cipher ( struct cipher_algorithm *cipher ) {
return cipher->authsize; return cipher->authsize;
} }
static inline int pubkey_init ( struct pubkey_algorithm *pubkey, void *ctx, static inline __attribute__ (( always_inline )) int
const void *key, size_t key_len ) { pubkey_init ( struct pubkey_algorithm *pubkey, void *ctx,
const void *key, size_t key_len ) {
return pubkey->init ( ctx, key, key_len ); return pubkey->init ( ctx, key, key_len );
} }
static inline size_t pubkey_max_len ( struct pubkey_algorithm *pubkey, static inline __attribute__ (( always_inline )) size_t
void *ctx ) { pubkey_max_len ( struct pubkey_algorithm *pubkey, void *ctx ) {
return pubkey->max_len ( ctx ); return pubkey->max_len ( ctx );
} }
static inline int pubkey_encrypt ( struct pubkey_algorithm *pubkey, void *ctx, static inline __attribute__ (( always_inline )) int
const void *data, size_t len, void *out ) { pubkey_encrypt ( struct pubkey_algorithm *pubkey, void *ctx,
const void *data, size_t len, void *out ) {
return pubkey->encrypt ( ctx, data, len, out ); return pubkey->encrypt ( ctx, data, len, out );
} }
static inline int pubkey_decrypt ( struct pubkey_algorithm *pubkey, void *ctx, static inline __attribute__ (( always_inline )) int
const void *data, size_t len, void *out ) { pubkey_decrypt ( struct pubkey_algorithm *pubkey, void *ctx,
const void *data, size_t len, void *out ) {
return pubkey->decrypt ( ctx, data, len, out ); return pubkey->decrypt ( ctx, data, len, out );
} }
static inline int pubkey_sign ( struct pubkey_algorithm *pubkey, void *ctx, static inline __attribute__ (( always_inline )) int
struct digest_algorithm *digest, pubkey_sign ( struct pubkey_algorithm *pubkey, void *ctx,
const void *value, void *signature ) { struct digest_algorithm *digest, const void *value,
void *signature ) {
return pubkey->sign ( ctx, digest, value, signature ); return pubkey->sign ( ctx, digest, value, signature );
} }
static inline int pubkey_verify ( struct pubkey_algorithm *pubkey, void *ctx, static inline __attribute__ (( always_inline )) int
struct digest_algorithm *digest, pubkey_verify ( struct pubkey_algorithm *pubkey, void *ctx,
const void *value, const void *signature, struct digest_algorithm *digest, const void *value,
size_t signature_len ) { const void *signature, size_t signature_len ) {
return pubkey->verify ( ctx, digest, value, signature, signature_len ); return pubkey->verify ( ctx, digest, value, signature, signature_len );
} }
static inline void pubkey_final ( struct pubkey_algorithm *pubkey, void *ctx ) { static inline __attribute__ (( always_inline )) void
pubkey_final ( struct pubkey_algorithm *pubkey, void *ctx ) {
pubkey->final ( ctx ); pubkey->final ( ctx );
} }
static inline int pubkey_match ( struct pubkey_algorithm *pubkey, static inline __attribute__ (( always_inline )) int
const void *private_key, pubkey_match ( struct pubkey_algorithm *pubkey,
size_t private_key_len, const void *public_key, const void *private_key, size_t private_key_len,
size_t public_key_len ) { const void *public_key, size_t public_key_len ) {
return pubkey->match ( private_key, private_key_len, public_key, return pubkey->match ( private_key, private_key_len, public_key,
public_key_len ); public_key_len );
} }
static inline int elliptic_multiply ( struct elliptic_curve *curve, static inline __attribute__ (( always_inline )) int
const void *base, const void *scalar, elliptic_multiply ( struct elliptic_curve *curve,
void *result ) { const void *base, const void *scalar, void *result ) {
return curve->multiply ( base, scalar, result ); return curve->multiply ( base, scalar, result );
} }