GL4Dummies  0.1.7
Référence du fichier aes.h

Utilisée pour décrypter des shaders données en archive cryptée AES. Plus de détails...

Ce graphe montre quels fichiers incluent directement ou indirectement ce fichier :

Aller au code source de ce fichier.

Structures de données

struct  aes_context
 AES context structure. Plus de détails...
 

Fonctions

void aes_set_key (aes_context *ctx, unsigned char *key, int keysize)
 AES key schedule. Plus de détails...
 
void aes_encrypt (aes_context *ctx, unsigned char input[16], unsigned char output[16])
 AES block encryption (ECB mode) Plus de détails...
 
void aes_decrypt (aes_context *ctx, unsigned char input[16], unsigned char output[16])
 AES block decryption (ECB mode) Plus de détails...
 
void aes_cbc_encrypt (aes_context *ctx, unsigned char iv[16], unsigned char *input, unsigned char *output, int len)
 AES-CBC buffer encryption. Plus de détails...
 
void aes_cbc_decrypt (aes_context *ctx, unsigned char iv[16], unsigned char *input, unsigned char *output, int len)
 AES-CBC buffer decryption. Plus de détails...
 
void vaetvient (unsigned char *data, int len, int vaouvient)
 
char * aes_from_tar (const char *file)
 
int aes_self_test (void)
 Checkup routine. Plus de détails...
 

Description détaillée

Utilisée pour décrypter des shaders données en archive cryptée AES.

FIPS-197 compliant AES implementation
Copyright (C) 2003-2006 Christophe Devine
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
The AES block cipher was designed by Vincent Rijmen and Joan Daemen.
http://csrc.nist.gov/encryption/aes/rijndael/Rijndael.pdf (broken link)
http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf (broken link)
See also: https://comparite.ch/encryption-types

Auteur
Christophe Devine

Définition dans le fichier aes.h.

Documentation des fonctions

◆ aes_cbc_decrypt()

void aes_cbc_decrypt ( aes_context ctx,
unsigned char  iv[16],
unsigned char *  input,
unsigned char *  output,
int  len 
)

AES-CBC buffer decryption.

Paramètres
ctxAES context
ivinitialization vector (modified after use)
inputbuffer holding the ciphertext
outputbuffer holding the plaintext
lenlength of the data to be decrypted
842 {
843  int i;
844  unsigned char temp[16];
845 
846  while( len > 0 )
847  {
848  memcpy( temp, input, 16 );
849  aes_decrypt( ctx, input, output );
850 
851  for( i = 0; i < 16; i++ )
852  output[i] = output[i] ^ iv[i];
853 
854  memcpy( iv, temp, 16 );
855 
856  input += 16;
857  output += 16;
858  len -= 16;
859  }
860 }

Références aes_decrypt().

◆ aes_cbc_encrypt()

void aes_cbc_encrypt ( aes_context ctx,
unsigned char  iv[16],
unsigned char *  input,
unsigned char *  output,
int  len 
)

AES-CBC buffer encryption.

Paramètres
ctxAES context
ivinitialization vector (modified after use)
inputbuffer holding the plaintext
outputbuffer holding the ciphertext
lenlength of the data to be encrypted
817 {
818  int i;
819 
820  while( len > 0 )
821  {
822  for( i = 0; i < 16; i++ )
823  output[i] = input[i] ^ iv[i];
824 
825  aes_encrypt( ctx, output, output );
826  memcpy( iv, output, 16 );
827 
828  input += 16;
829  output += 16;
830  len -= 16;
831  }
832 }

Références aes_encrypt().

◆ aes_decrypt()

void aes_decrypt ( aes_context ctx,
unsigned char  input[16],
unsigned char  output[16] 
)

AES block decryption (ECB mode)

Paramètres
ctxAES context
inputciphertext block
outputplaintext block
724 {
725  uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
726 
727  RK = ctx->drk;
728 
729  GET_UINT32_BE( X0, input, 0 ); X0 ^= RK[0];
730  GET_UINT32_BE( X1, input, 4 ); X1 ^= RK[1];
731  GET_UINT32_BE( X2, input, 8 ); X2 ^= RK[2];
732  GET_UINT32_BE( X3, input, 12 ); X3 ^= RK[3];
733 
734 #define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
735 { \
736  RK += 4; \
737  \
738  X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^ \
739  RT1[ (uint8) ( Y3 >> 16 ) ] ^ \
740  RT2[ (uint8) ( Y2 >> 8 ) ] ^ \
741  RT3[ (uint8) ( Y1 ) ]; \
742  \
743  X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^ \
744  RT1[ (uint8) ( Y0 >> 16 ) ] ^ \
745  RT2[ (uint8) ( Y3 >> 8 ) ] ^ \
746  RT3[ (uint8) ( Y2 ) ]; \
747  \
748  X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^ \
749  RT1[ (uint8) ( Y1 >> 16 ) ] ^ \
750  RT2[ (uint8) ( Y0 >> 8 ) ] ^ \
751  RT3[ (uint8) ( Y3 ) ]; \
752  \
753  X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^ \
754  RT1[ (uint8) ( Y2 >> 16 ) ] ^ \
755  RT2[ (uint8) ( Y1 >> 8 ) ] ^ \
756  RT3[ (uint8) ( Y0 ) ]; \
757 }
758 
759  AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
760  AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
761  AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
762  AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
763  AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
764  AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
765  AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
766  AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
767  AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
768 
769  if( ctx->nr > 10 )
770  {
771  AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
772  AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
773  }
774 
775  if( ctx->nr > 12 )
776  {
777  AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
778  AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
779  }
780 
781  RK += 4;
782 
783  X0 = RK[0] ^ ( RSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
784  ( RSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
785  ( RSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^
786  ( RSb[ (uint8) ( Y1 ) ] );
787 
788  X1 = RK[1] ^ ( RSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
789  ( RSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
790  ( RSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^
791  ( RSb[ (uint8) ( Y2 ) ] );
792 
793  X2 = RK[2] ^ ( RSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
794  ( RSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
795  ( RSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^
796  ( RSb[ (uint8) ( Y3 ) ] );
797 
798  X3 = RK[3] ^ ( RSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
799  ( RSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
800  ( RSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^
801  ( RSb[ (uint8) ( Y0 ) ] );
802 
803  PUT_UINT32_BE( X0, output, 0 );
804  PUT_UINT32_BE( X1, output, 4 );
805  PUT_UINT32_BE( X2, output, 8 );
806  PUT_UINT32_BE( X3, output, 12 );
807 }

Références AES_RROUND, aes_context::drk, GET_UINT32_BE, aes_context::nr, PUT_UINT32_BE, RSb, uint32, et uint8.

Référencé par aes_cbc_decrypt(), et vaetvient().

◆ aes_encrypt()

void aes_encrypt ( aes_context ctx,
unsigned char  input[16],
unsigned char  output[16] 
)

AES block encryption (ECB mode)

Paramètres
ctxAES context
inputplaintext block
outputciphertext block

AES block encryption (ECB mode)

633 {
634  uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
635 
636  RK = ctx->erk;
637 
638  GET_UINT32_BE( X0, input, 0 ); X0 ^= RK[0];
639  GET_UINT32_BE( X1, input, 4 ); X1 ^= RK[1];
640  GET_UINT32_BE( X2, input, 8 ); X2 ^= RK[2];
641  GET_UINT32_BE( X3, input, 12 ); X3 ^= RK[3];
642 
643 #define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \
644 { \
645  RK += 4; \
646  \
647  X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^ \
648  FT1[ (uint8) ( Y1 >> 16 ) ] ^ \
649  FT2[ (uint8) ( Y2 >> 8 ) ] ^ \
650  FT3[ (uint8) ( Y3 ) ]; \
651  \
652  X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^ \
653  FT1[ (uint8) ( Y2 >> 16 ) ] ^ \
654  FT2[ (uint8) ( Y3 >> 8 ) ] ^ \
655  FT3[ (uint8) ( Y0 ) ]; \
656  \
657  X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^ \
658  FT1[ (uint8) ( Y3 >> 16 ) ] ^ \
659  FT2[ (uint8) ( Y0 >> 8 ) ] ^ \
660  FT3[ (uint8) ( Y1 ) ]; \
661  \
662  X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^ \
663  FT1[ (uint8) ( Y0 >> 16 ) ] ^ \
664  FT2[ (uint8) ( Y1 >> 8 ) ] ^ \
665  FT3[ (uint8) ( Y2 ) ]; \
666 }
667 
668  AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
669  AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
670  AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
671  AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
672  AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
673  AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
674  AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
675  AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
676  AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
677 
678  if( ctx->nr > 10 )
679  {
680  AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
681  AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
682  }
683 
684  if( ctx->nr > 12 )
685  {
686  AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
687  AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
688  }
689 
690  RK += 4;
691 
692  X0 = RK[0] ^ ( FSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^
693  ( FSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^
694  ( FSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^
695  ( FSb[ (uint8) ( Y3 ) ] );
696 
697  X1 = RK[1] ^ ( FSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^
698  ( FSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^
699  ( FSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^
700  ( FSb[ (uint8) ( Y0 ) ] );
701 
702  X2 = RK[2] ^ ( FSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^
703  ( FSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^
704  ( FSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^
705  ( FSb[ (uint8) ( Y1 ) ] );
706 
707  X3 = RK[3] ^ ( FSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^
708  ( FSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^
709  ( FSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^
710  ( FSb[ (uint8) ( Y2 ) ] );
711 
712  PUT_UINT32_BE( X0, output, 0 );
713  PUT_UINT32_BE( X1, output, 4 );
714  PUT_UINT32_BE( X2, output, 8 );
715  PUT_UINT32_BE( X3, output, 12 );
716 }

Références AES_FROUND, aes_context::erk, FSb, GET_UINT32_BE, aes_context::nr, PUT_UINT32_BE, uint32, et uint8.

Référencé par aes_cbc_encrypt(), et vaetvient().

◆ aes_from_tar()

char* aes_from_tar ( const char *  file)
899  {
900  size_t l = 0;
901  char * data = NULL;
902  FILE * f;
903  struct stat buf;
904  if(stat(file, &buf) != 0) {
905  fprintf(stderr, "%s:%d: erreur %d: %s\n", __FILE__, __LINE__, errno, strerror(errno));
906  return NULL;
907  }
908  data = malloc( (buf.st_size + 1) * sizeof * data );
909  assert(data);
910  if( (f = fopen(file, "rb")) == NULL ) {
911  fprintf(stderr, "%s:%d: erreur %d: %s\n", __FILE__, __LINE__, errno, strerror(errno));
912  free(data);
913  return NULL;
914  }
915  if( (l = fread(data, sizeof * data, buf.st_size, f)) != (size_t)buf.st_size) {
916  fprintf(stderr, "%s:%d:In %s: une erreur s'est produite lors de la lecture du fichier %s\n",
917  __FILE__, __LINE__, __func__, file);
918  free(data);
919  fclose(f);
920  return NULL;
921  }
922  fclose(f);
923  vaetvient((unsigned char *)data, (int)l, 1);
924  return data;
925 }

Références vaetvient().

Référencé par gl4duCreateProgramFED().

◆ aes_self_test()

int aes_self_test ( void  )

Checkup routine.

Renvoie
0 if successful, or 1 if the test failed
969  {
970  return 0;
971 }

◆ aes_set_key()

void aes_set_key ( aes_context ctx,
unsigned char *  key,
int  keysize 
)

AES key schedule.

Paramètres
ctxAES context to be initialized
keythe secret key
keysizemust be 128, 192 or 256

◆ vaetvient()

void vaetvient ( unsigned char *  data,
int  len,
int  vaouvient 
)
862  {
863  int i;
864  static aes_context ctx;
865  static int ft = 1;
866  static unsigned char buf[32] = { 0xAA, 0x99, 0x55, 0x51, 0x25, 0x76, 0x58, 0x8C,
867  0xFA, 0x10, 0x54, 0x11, 0xCA, 0xCD, 0xDD, 0xAD,
868  0x21, 0x30, 0xAB, 0xB5, 0x5D, 0x2B, 0x3C, 0x7A,
869  0xDC, 0x24, 0xCD, 0xA1, 0xF3, 0x39, 0x95, 0x00 };
870  if(ft) {
871  aes_set_key( &ctx, buf, 256 );
872  for(i = 0; i < 15; i++)
873  aes_encrypt(&ctx, buf, buf);
874  aes_set_key( &ctx, buf, 256 );
875  ft = 0;
876  }
877  i = 0;
878  if(vaouvient == 0) {
879  while(i < len) {
880  aes_encrypt(&ctx, &data[i], &data[i]);
881  i += 16;
882  }
883  } else {
884  while(i < len) {
885  aes_decrypt(&ctx, &data[i], &data[i]);
886  i += 16;
887  }
888  }
889 }

Références aes_decrypt(), aes_encrypt(), et aes_set_key().

Référencé par aes_from_tar().

FSb
static uint8 FSb[256]
Definition: aes.c:86
aes_context
AES context structure.
Definition: aes.h:41
aes_set_key
void aes_set_key(aes_context *ctx, uint8 *key, int keysize)
Definition: aes.c:472
RSb
static uint8 RSb[256]
Definition: aes.c:95
AES_RROUND
#define AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3)
aes_context::nr
int nr
Definition: aes.h:45
aes_decrypt
void aes_decrypt(aes_context *ctx, unsigned char input[16], unsigned char output[16])
AES block decryption (ECB mode)
Definition: aes.c:721
vaetvient
void vaetvient(unsigned char *data, int len, int vaouvient)
Definition: aes.c:862
uint32
#define uint32
Definition: aes.c:49
aes_context::erk
unsigned long erk[64]
Definition: aes.h:43
AES_FROUND
#define AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3)
aes_encrypt
void aes_encrypt(aes_context *ctx, unsigned char input[16], unsigned char output[16])
AES block encryption (ECB mode)
Definition: aes.c:630
PUT_UINT32_BE
#define PUT_UINT32_BE(n, b, i)
Definition: aes.c:65
GET_UINT32_BE
#define GET_UINT32_BE(n, b, i)
Definition: aes.c:56
aes_context::drk
unsigned long drk[64]
Definition: aes.h:44
uint8
#define uint8
Definition: aes.c:45