/** DryGascon_le32 Sebastien Riou, January 6th 2019 c99 little endian 32 bit implementation meant to fit in the supercop framework */ #ifndef __DRYGASCON_H__ #define __DRYGASCON_H__ #include typedef uint64_t DRYSPONGE_EXT_t; #define DRYSPONGE_EXT #include "drysponge_common.h" //input width for one round of MixPhaseRound #define DRYSPONGE_MPR_INPUT_MASK ((((uint64_t)1)<16 #error "DRYSPONGE_XSIZE32>16" #endif #if DRYSPONGE_XSIZE32 == 4 #define DRYSPONGE_X_IDX_WIDTH 2 #endif #if DRYSPONGE_MPR_INPUT_WIDTH == 10 #define DRYSPONGE_RANK_BYTES 2 typedef uint32_t permut_rank_t; #endif #if DRYSPONGE_MPR_INPUT_WIDTH == 18 #define DRYSPONGE_RANK_BYTES 3 typedef uint32_t permut_rank_t; #endif #define DRYSPONGE_X_IDX_MASK ((1<>shift) & DRYSPONGE_MPR_INPUT_MASK; r^=ext; for(unsigned int j=0;j> DRYSPONGE_X_IDX_WIDTH; c64[j]^=x32[i]; } } #endif struct DRYSPONGE_struct_t; typedef struct DRYSPONGE_struct_t DRYSPONGE_t ; DRYSPONGE_FUNC void DRYSPONGE_MixPhase( DRYSPONGE_t *const ctx, const uint8_t *const in ); DRYSPONGE_FUNC void DRYSPONGE_CoreRound( DRYSPONGE_t *const ctx, unsigned int r ); #include "drysponge_le32.h" #ifndef DRYSPONGE_OPT_F DRYSPONGE_FUNC void DRYSPONGE_MixPhase( DRYSPONGE_t *const ctx, const uint8_t *const in ){ unsigned int bitidx=0; #if DRYSPONGE_MPR_ROUNDS > 1 for(unsigned int i=0;i= 4 printf("Mix phase MixPhaseRound entry %lu:\n",i); DRYSPONGE_print_state(ctx); #endif DRYSPONGE_EXT_t ext=0; #if ((DRYSPONGE_MPR_ROUNDS-1)*(DRYSPONGE_MPR_INPUT_WIDTH))>(DRYSPONGE_BLOCKSIZE*8) if((ctx->ext) && (i==(DRYSPONGE_MPR_ROUNDS-2))){ //DS info is split accross this block and the last one ext = ctx->ext; ctx->ext = ctx->ext >> ((DRYSPONGE_BLOCKSIZE*8)%DRYSPONGE_MPR_INPUT_WIDTH); ctx->ext = ctx->ext >> ((((DRYSPONGE_MPR_ROUNDS-1)*DRYSPONGE_MPR_INPUT_WIDTH))-(DRYSPONGE_BLOCKSIZE*8)); } #endif DRYSPONGE_MixPhaseRound(ext,ctx->c,ctx->x,in,bitidx,DRYSPONGE_BLOCKSIZE); bitidx+=DRYSPONGE_MPR_INPUT_WIDTH; #if DRYSPONGE_DBG_EN >= 4 printf("Mix phase CoreRound entry %lu:\n",i); DRYSPONGE_print_state(ctx); #endif DRYSPONGE_CoreRound(ctx,0); } #endif #if DRYSPONGE_DBG_EN >= 4 printf("Mix phase MixPhaseRound entry %lu:\n",DRYSPONGE_MPR_ROUNDS-1); DRYSPONGE_print_state(ctx); #endif DRYSPONGE_MixPhaseRound(ctx->ext,ctx->c,ctx->x,in,bitidx,DRYSPONGE_BLOCKSIZE); ctx->ext=0; } #endif //#ifndef DRYSPONGE_OPT_G //keep for now, needed for key init DRYSPONGE_FUNC void gascon_sboxes(uint64_t * const x, unsigned int nw){ uint64_t t[DRYSPONGE_CAPACITYSIZE64]; const unsigned int mid = nw/2; for(unsigned int i=0;i 5 x[5] ^= gascon_rotr64_interleaved(x[5], 31) ^ gascon_rotr64_interleaved(x[5], 26); x[6] ^= gascon_rotr64_interleaved(x[6], 53) ^ gascon_rotr64_interleaved(x[6], 58); x[7] ^= gascon_rotr64_interleaved(x[7], 9) ^ gascon_rotr64_interleaved(x[7], 46); x[8] ^= gascon_rotr64_interleaved(x[8], 43) ^ gascon_rotr64_interleaved(x[8], 50); #endif } DRYSPONGE_FUNC void gascon_permutation_round(uint64_t* S, unsigned int round) { (void)DRYSPONGE_rotr64; // addition of round constant gascon_add_cst(S, round); // substitution layer gascon_sboxes(S,DRYSPONGE_CAPACITYSIZE64); // linear diffusion layer gascon_lin_layer(S); } DRYSPONGE_FUNC void DRYSPONGE_CoreRound( DRYSPONGE_t *const ctx, unsigned int r ){ gascon_permutation_round(ctx->c, r); } #endif