42 lines
1.4 KiB
C
42 lines
1.4 KiB
C
/* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
|
source code may only be used and distributed under the Widevine Master
|
|
License Agreement. */
|
|
|
|
#ifndef OEMCRYPTO_TA_OEMCRYPTO_NONCE_TABLE_H_
|
|
#define OEMCRYPTO_TA_OEMCRYPTO_NONCE_TABLE_H_
|
|
|
|
#include "stdbool.h"
|
|
#include "stdint.h"
|
|
|
|
#define NONCE_TABLE_SIZE 4
|
|
|
|
typedef enum NonceTableState {
|
|
NT_STATE_INVALID = 0x73624fe4,
|
|
NT_STATE_VALID = 0x7fb3983a,
|
|
NT_STATE_FLUSH_PENDING = 0x1b9654ae,
|
|
} NonceTableState;
|
|
|
|
typedef struct NonceTable {
|
|
NonceTableState state[NONCE_TABLE_SIZE];
|
|
uint32_t age[NONCE_TABLE_SIZE];
|
|
uint32_t nonces[NONCE_TABLE_SIZE];
|
|
} NonceTable;
|
|
|
|
/* Adds |nonce| to the |nonce_table|. Flushes any nonces that have already been
|
|
checked and then either adds it to the nonce table or replaces the oldest
|
|
valid nonce in the table. */
|
|
void AddNonce(NonceTable* nonce_table, uint32_t nonce);
|
|
|
|
/* Checks the |nonce| exists in the |nonce_table|. Marks the nonce as ready to
|
|
be flushed if it exists.
|
|
Returns false if it does not exist in the table. */
|
|
bool CheckNonce(NonceTable* nonce_table, uint32_t nonce);
|
|
|
|
/* Verify that the nonce is not the same as any in |nonce_table|. */
|
|
bool NonceCollision(NonceTable* nonce_table, uint32_t nonce);
|
|
|
|
/* Flush any nonces that have been checked in |nonce_table|. */
|
|
void FlushNonces(NonceTable* nonce_table);
|
|
|
|
#endif // OEMCRYPTO_TA_OEMCRYPTO_NONCE_TABLE_H_
|