include/crypto/sha3.h

Source file repositories/reference/linux-study-clean/include/crypto/sha3.h

File Facts

System
Linux kernel
Corpus path
include/crypto/sha3.h
Extension
.h
Size
10500 bytes
Lines
347
Domain
Repository Root And Misc
Bucket
include
Inferred role
Repository Root And Misc: implementation source
Status
source implementation candidate

Why This File Exists

Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.

Dependency Surface

Detected Declarations

Annotated Snippet

struct sha3_state {
	union {
		__le64 words[SHA3_STATE_SIZE / 8];
		u8 bytes[SHA3_STATE_SIZE];

		u64 native_words[SHA3_STATE_SIZE / 8]; /* see comment above */
	};
};

/* Internal context, shared by the digests (SHA3-*) and the XOFs (SHAKE*) */
struct __sha3_ctx {
	struct sha3_state state;
	u8 digest_size;		/* Digests only: the digest size in bytes */
	u8 block_size;		/* Block size in bytes */
	u8 absorb_offset;	/* Index of next state byte to absorb into */
	u8 squeeze_offset;	/* XOFs only: index of next state byte to extract */
};

void __sha3_update(struct __sha3_ctx *ctx, const u8 *in, size_t in_len);

/**
 * struct sha3_ctx - Context for SHA3-224, SHA3-256, SHA3-384, or SHA3-512
 * @ctx: private
 */
struct sha3_ctx {
	struct __sha3_ctx ctx;
};

/**
 * sha3_zeroize_ctx() - Zeroize a SHA-3 context
 * @ctx: The context to zeroize
 *
 * This is already called by sha3_final().  Call this explicitly when abandoning
 * a context without calling sha3_final().
 */
static inline void sha3_zeroize_ctx(struct sha3_ctx *ctx)
{
	memzero_explicit(ctx, sizeof(*ctx));
}

/**
 * struct shake_ctx - Context for SHAKE128 or SHAKE256
 * @ctx: private
 */
struct shake_ctx {
	struct __sha3_ctx ctx;
};

/**
 * shake_zeroize_ctx() - Zeroize a SHAKE context
 * @ctx: The context to zeroize
 *
 * Call this after the last squeeze.
 */
static inline void shake_zeroize_ctx(struct shake_ctx *ctx)
{
	memzero_explicit(ctx, sizeof(*ctx));
}

/**
 * sha3_224_init() - Initialize a context for SHA3-224
 * @ctx: The context to initialize
 *
 * This begins a new SHA3-224 message digest computation.
 *
 * Context: Any context.
 */
static inline void sha3_224_init(struct sha3_ctx *ctx)
{
	*ctx = (struct sha3_ctx){
		.ctx.digest_size = SHA3_224_DIGEST_SIZE,
		.ctx.block_size = SHA3_224_BLOCK_SIZE,
	};
}

/**
 * sha3_256_init() - Initialize a context for SHA3-256
 * @ctx: The context to initialize
 *
 * This begins a new SHA3-256 message digest computation.
 *
 * Context: Any context.
 */
static inline void sha3_256_init(struct sha3_ctx *ctx)
{
	*ctx = (struct sha3_ctx){
		.ctx.digest_size = SHA3_256_DIGEST_SIZE,
		.ctx.block_size = SHA3_256_BLOCK_SIZE,
	};
}

Annotation

Implementation Notes