Ejemplo n.º 1
0
Archivo: firm.c Proyecto: TiniVi/AHPCFW
int firm_setup(void){
	if (strncmp((char *)FIRM, "FIRM", 4) != 0) return -1; //if not firm
	
	u8* arm9bin = (void*)FIRM + FIRM[0xA0/4];
	
	if (arm9bin[0] != 0xA7 || arm9bin[1] != 0x38) return 0; //if o3ds firm
	
	if (arm9bin[0x800] != 0x70 || arm9bin[0x801] != 0x47){ //if encrypted
		if (arm9bin[0x50] != 0xFF && arm9bin[0x61] != 0xA9){ //if 9.6^ firm
			keydata_init(0x1B, 0);
			keydata_init(0x11, 1);
		}
		else keydata_init(0x11, 0);
		
		u8 keyslot = arm9bin[0x50] != 0xFF ? 0x16 : 0x15; //keyslot changed on 9.5
		u8* keyX = arm9bin + (arm9bin[0x50] != 0xFF ? 0x60 : 0);
		
		set_keyslot(0x11);
		aes(keyX, keyX, NULL, 1, AES_ECB_DECRYPT); //keyX is encrypted with aes ecb
		
		set_keyX(keyslot, keyX);
		set_keyY(keyslot, arm9bin+0x10); //keyY must be set last
		
		set_keyslot(keyslot);
		aes(arm9bin+0x800, arm9bin+0x800, arm9bin+0x20, atoi((const char *)(arm9bin+0x30))/0x10, AES_CTR_DECRYPT);
	}
	
	return 0;
}
Ejemplo n.º 2
0
/* initial key derivation */
void aes_key_derivation(const TAES* key)
{
    /* use base key to derieve needed keys */
    memcpy(g_encrypt.key, key, sizeof(g_encrypt.key));

    /* create site-signature key */
    memset(g_encrypt.in, AES_KEYID_SIGNATURE, sizeof(g_encrypt.in));
    aes(&g_encrypt);
    memcpy(g_signature.key, g_encrypt.out, sizeof(g_signature.key));

    /* finally, create site-encryption key */
    memset(g_encrypt.in, AES_KEYID_ENCRYPTION, sizeof(g_encrypt.in));
    aes(&g_encrypt);
    memcpy(g_encrypt.key, g_encrypt.out, sizeof(g_encrypt.key));
}
Ejemplo n.º 3
0
void AES_CTR_Encrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
{
	SecByteBlock key = HexDecodeString(hexKey);
	SecByteBlock iv = HexDecodeString(hexIV);
	CTR_Mode<AES>::Encryption aes(key, key.size(), iv);
	FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile)));
}
Ejemplo n.º 4
0
void JSWindowActor::ReceiveRawMessage(const JSWindowActorMessageMeta& aMetadata,
                                      ipc::StructuredCloneData&& aData) {
  AutoEntryScript aes(xpc::PrivilegedJunkScope(),
                      "JSWindowActor message handler");
  JSContext* cx = aes.cx();

  // Read the message into a JS object from IPC.
  ErrorResult error;
  JS::Rooted<JS::Value> data(cx);
  aData.Read(cx, &data, error);
  if (NS_WARN_IF(error.Failed())) {
    MOZ_ALWAYS_TRUE(error.MaybeSetPendingException(cx));
    return;
  }

  switch (aMetadata.kind()) {
    case JSWindowActorMessageKind::QueryResolve:
    case JSWindowActorMessageKind::QueryReject:
      ReceiveQueryReply(cx, aMetadata, data, error);
      break;

    case JSWindowActorMessageKind::Message:
    case JSWindowActorMessageKind::Query:
      ReceiveMessageOrQuery(cx, aMetadata, data, error);
      break;

    default:
      MOZ_ASSERT_UNREACHABLE();
  }

  if (NS_WARN_IF(error.Failed())) {
    MOZ_ALWAYS_TRUE(error.MaybeSetPendingException(cx));
  }
}
Ejemplo n.º 5
0
int16 mt_fslx_set_flags( const int16 flags, int16 *oldval, GlobalArray *globl )
{
	/* AES-Datenblock anlegen */
	static int16 contrl[] = {195, 2, 2, 0, 0};
	AESData data;
	
	/* Das contrl-Array initialisieren */
	CTRLCPY(data.contrl, contrl);
	
	/* Die Arrays anlegen */
	
	/* Das globl-Array eintragen */
	data.globl = globl;
	
	/* Die Arrays f�llen */
	data.intin[0] = 0;
	data.intin[1] = flags;
	
	/* Ab in die AES... */
	aes(data.contrl, data.globl, data.intin, data.intout, data.addrin, data.addrout);
	
	if( oldval!=NULL )
		*oldval = data.intout[1];
	
	return data.intout[0];
}
Ejemplo n.º 6
0
int16 mt_fslx_evnt( void *fsd, EVNT *events, char *path, char *fname, int16 *button,
				int16 *nfiles, int16 *sort_mode, char **pattern, GlobalArray *globl )
{
	/* AES-Datenblock anlegen */
	static int16 contrl[] = {193, 0, 4, 4, 1};
	AESData data;
	
	/* Das contrl-Array initialisieren */
	CTRLCPY(data.contrl, contrl);
	
	/* Die Arrays anlegen */
	
	/* Das globl-Array eintragen */
	data.globl = globl;
	
	/* Die Arrays f�llen */
	data.addrin[0] = fsd;
	data.addrin[1] = events;
	data.addrin[2] = path;
	data.addrin[3] = fname;
	
	/* Ab in die AES... */
	aes(data.contrl, data.globl, data.intin, data.intout, data.addrin, data.addrout);
	
	if( button!=NULL )
		*button = data.intout[1];
	if( nfiles!=NULL )
		*nfiles = data.intout[2];
	if( sort_mode!=NULL )
		*sort_mode = data.intout[3];
	if( pattern!=NULL )
		*pattern = data.addrout[0];
	
	return data.intout[0];
}
Ejemplo n.º 7
0
/* menu_bar() is here so that menu_owner() works on AES < 4.0 */
int
menu_bar(OBJECT *m, int show)
{
	showing = int_in[0] = show;
	addr_in[0] = m;
	return aes(MENU_BAR);
}
Ejemplo n.º 8
0
int wind_get(int handle, int field, ... )
{
	va_list args;
	int parms, i;

	va_start(args, field);

	_GemParBlk.contrl[0] = 0x68;
	_GemParBlk.contrl[1] = 2;
	_GemParBlk.contrl[2] = 5;
	_GemParBlk.contrl[3] = 0;
	_GemParBlk.contrl[4] = 0;

	_GemParBlk.intin[0] = handle;
	_GemParBlk.intin[1] = field;

	aes();

	parms = argtab[(field - 1) & 0x1F];

	for(i = 0; i < parms; i++)
		*(va_arg(args, int *)) = _GemParBlk.intout[i + 1];

	va_end(args);

	return _GemParBlk.intout[0];
}
Ejemplo n.º 9
0
TEST(AESTest, WrongInputBlockSize)
{
  AES aes(Decode(AESCTRTestVectors[0].key)) ;
  ASSERT_THROW(aes.Encode(Decode("")), std::string) ;
  ASSERT_THROW(aes.Encode(Decode("01234567890123456789")), std::string) ;
  ASSERT_THROW(aes.Encode(Decode("0123456789012345678901234567890123456789012345678901234567890123456789")), std::string) ;
}
Ejemplo n.º 10
0
int16 mt_wind_setGRECT( const int16 handle, const int16 what, const GRECT *xywh,
				GlobalArray *globl )
{
	/* AES-Datenblock anlegen */
	static int16 contrl[] = {105, 6, 1, 0, 0};
	AESData data;
	
	/* Das contrl-Array initialisieren */
	CTRLCPY(data.contrl, contrl);
	
	/* Das globl-Array eintragen */
	data.globl = globl;
	
	/* Die Arrays f�llen */
	data.intin[0] = handle;
	data.intin[1] = what;
	data.intin[2] = xywh->g_x;
	data.intin[3] = xywh->g_y;
	data.intin[4] = xywh->g_w;
	data.intin[5] = xywh->g_h;
	
	/* Ab in die AES... */
	aes(data.contrl, data.globl, data.intin, data.intout, data.addrin, data.addrout);
	
	return data.intout[0];
Ejemplo n.º 11
0
int16 mt_wind_calcGRECT( const int16 wtype, const int16 kind, const GRECT *input,
				GRECT *output, GlobalArray *globl )
{
	/* AES-Datenblock anlegen */
	static int16 contrl[] = {108, 6, 5, 0, 0};
	AESData data;
	
	/* Das contrl-Array initialisieren */
	CTRLCPY(data.contrl, contrl);
	
	/* Das globl-Array eintragen */
	data.globl = globl;
	
	/* Die Arrays f�llen */
	data.intin[0] = wtype;
	data.intin[1] = kind;
	data.intin[2] = input->g_x;
	data.intin[3] = input->g_y;
	data.intin[4] = input->g_w;
	data.intin[5] = input->g_h;
	
	/* Ab in die AES... */
	aes(data.contrl, data.globl, data.intin, data.intout, data.addrin, data.addrout);
	
	/* Die Werte verteilen */
	if( output!=NULL )
	{
		output->g_x = data.intout[1];
		output->g_y = data.intout[2];
		output->g_w = data.intout[3];
		output->g_h = data.intout[4];
	}
	
	return data.intout[0];
Ejemplo n.º 12
0
TEST(BlockCipherAdapterTest, WrongIvLength)
{
  AES aes(Decode(AESCTRTestVectors[0].key)) ;
  ASSERT_THROW(BlockCipherAdapter(&aes, Decode(""), BlockCipherAdapter::Mode::CTR), std::string) ;
  ASSERT_THROW(BlockCipherAdapter(&aes, Decode("01234567890123456789"), BlockCipherAdapter::Mode::CTR), std::string) ;
  ASSERT_THROW(BlockCipherAdapter(&aes, Decode("0123456789012345678901234567890123456789012345678901234567890123456789"), BlockCipherAdapter::Mode::CTR), std::string) ;
}
Ejemplo n.º 13
0
int16 mt_wind_set( const int16 handle, const int16 what, const int16 value1,
				const int16 value2, const int16 value3, const int16 value4, GlobalArray *globl )
{
	/* AES-Datenblock anlegen */
	static int16 contrl[] = {105, 6, 1, 0, 0};
	int16 max = (what>=0 && what<AnzMaxParmsWindGetSet ? MaxParmsWindGetSet[what][1] : 4);
	AESData data;
	
	/* Das contrl-Array initialisieren */
	CTRLCPY(data.contrl, contrl);
	
	/* Bei Wert -1 wird abgebrochen! */
	if( max<0 )
		return 0;
	
	/* Das globl-Array eintragen */
	data.globl = globl;
	
	/* Die Arrays f�llen */
	data.intin[0] = handle;
	data.intin[1] = what;
	data.intin[2] = (max>0 ? value1 : 0);
	data.intin[3] = (max>1 ? value2 : 0);
	data.intin[4] = (max>2 ? value3 : 0);
	data.intin[5] = (max>4 ? value4 : 0);
	
	/* Ab in die AES... */
	aes(data.contrl, data.globl, data.intin, data.intout, data.addrin, data.addrout);
	
	return data.intout[0];
Ejemplo n.º 14
0
void aes_indep_enc(uint8_t * pt)
{
	uint8_t * result = aes(pt, enckey);
	for(uint8_t i=0; i < 16; i++){
		pt[i] = result[i];
	}
}
Ejemplo n.º 15
0
int16 mt_wind_get_grect( const int16 handle, int16 what, GRECT *r, GlobalArray *globl )
{
	/* AES-Datenblock anlegen */
	static int16 contrl[] = {104, 2, 5, 0, 0};
	AESData data;
	
	/* Das contrl-Array initialisieren */
	CTRLCPY(data.contrl, contrl);
	
	/* Das globl-Array eintragen */
	data.globl = globl;
	
	/* Die Arrays f�llen */
	data.intin[0] = handle;
	data.intin[1] = what;
	
	/* Sicherheitshalber intout mit 0 initiaisieren */
	data.intout[0] = data.intout[1] = data.intout[2] = data.intout[3] = data.intout[4] = 0;
	
	/* Ab in die AES... */
	aes(data.contrl, data.globl, data.intin, data.intout, data.addrin, data.addrout);
	
	/* Die Werte verteilen */
	if( r!=NULL )
	{
		r->g_x = data.intout[1];
		r->g_y = data.intout[2];
		r->g_w = data.intout[3];
		r->g_h = data.intout[4];
	}
	
	return data.intout[0];
Ejemplo n.º 16
0
int16 mt_wind_open( const int16 handle, const int16 x, const int16 y,
				const int16 w, const int16 h, GlobalArray *globl )
{
	/* AES-Datenblock anlegen */
	static int16 contrl[] = {101, 5, 1, 0, 0};
	AESData data;
	
	/* Das contrl-Array initialisieren */
	CTRLCPY(data.contrl, contrl);
	
	/* Das globl-Array eintragen */
	data.globl = globl;
	
	/* Die Arrays f�llen */
	data.intin[0] = handle;
	data.intin[1] = x;
	data.intin[2] = y;
	data.intin[3] = w;
	data.intin[4] = h;
	
	/* Ab in die AES... */
	aes(data.contrl, data.globl, data.intin, data.intout, data.addrin, data.addrout);
	
	return data.intout[0];
}
Ejemplo n.º 17
0
int16 mt_wind_create( const int16 kind, const int16 max_x, const int16 max_y,
				const int16 max_w, const int16 max_h, GlobalArray *globl )
{
	/* AES-Datenblock anlegen */
	static int16 contrl[] = {100, 5, 1, 0, 0};
	AESData data;
	
	/* Das contrl-Array initialisieren */
	CTRLCPY(data.contrl, contrl);
	
	/* Das globl-Array eintragen */
	data.globl = globl;
	
	/* Die Arrays f�llen */
	data.intin[0] = kind;
	data.intin[1] = max_x;
	data.intin[2] = max_y;
	data.intin[3] = max_w;
	data.intin[4] = max_h;
	
	/* Ab in die AES... */
	aes(data.contrl, data.globl, data.intin, data.intout, data.addrin, data.addrout);
	
	return data.intout[0];
}
Ejemplo n.º 18
0
TAES* aes_sign(const void* data, uint32_t length)
{
    uint8_t i, t, *src;

    /* reset signature buffer */
    memset(g_signature.out, 0xFF, sizeof(g_signature.out));

    /* sign data */
    src = (uint8_t*)data;
    while(length)
    {
        /* process data block by block */
        t = (length>=AES_BLOCK_SIZE) ? AES_BLOCK_SIZE : length;
        length -= t;

        /* XOR previous AES output data in */
        for(i=0; i<t; i++)
            g_signature.in[i] = g_signature.out[i] ^ *src++;

        /* pad block if needed */
        if(t<AES_BLOCK_SIZE)
            memset(&g_signature.in[t], 0xFF, AES_BLOCK_SIZE-t);

        /* AES hash block, result in 'out' */
        aes(&g_signature);
    }

    /* return full AES signature */
    return &g_signature.out;
}
Ejemplo n.º 19
0
/*
 * Set string values: WF_INFO, WF_NAME
 */
void
wind_sstr(int handle, int which, char *p)
{
	int_in[0] = handle;
	int_in[1] = which;
	*(char **)&int_in[2] = p;
	aes(WIND_SET);
}
Ejemplo n.º 20
0
/*
 * Set new desktop
 */
void
wind_sdesk(OBJECT *tree, int obj)
{
	int_in[0] = 0;
	int_in[1] = WF_NEWDESK;
	*(OBJECT **)&int_in[2] = tree;
	int_in[4] = obj;
	aes(WIND_SET);
}
Ejemplo n.º 21
0
ByteArray::size_type Aes256::decrypt(const ByteArray& key, const ByteArray& encrypted, ByteArray& plain)
{
    Aes256 aes(key);

    aes.decrypt_start(encrypted.size());
    aes.decrypt_continue(encrypted, plain);
    aes.decrypt_end(plain);

    return plain.size();
}
Ejemplo n.º 22
0
ByteArray::size_type Aes256::decrypt(const ByteArray& key, const unsigned char* encrypted, const ByteArray::size_type encrypted_length, ByteArray& plain)
{
    Aes256 aes(key);

    aes.decrypt_start(encrypted_length);
    aes.decrypt_continue(encrypted, encrypted_length, plain);
    aes.decrypt_end(plain);

    return plain.size();
}
Ejemplo n.º 23
0
ByteArray::size_type Aes256::encrypt(const ByteArray& key, const ByteArray& plain, ByteArray& encrypted)
{
    Aes256 aes(key);

    aes.encrypt_start(plain.size(), encrypted);
    aes.encrypt_continue(plain, encrypted);
    aes.encrypt_end(encrypted);

    return encrypted.size();
}
Ejemplo n.º 24
0
ByteArray::size_type Aes256::encrypt(const ByteArray& key, const unsigned char* plain, const ByteArray::size_type plain_length, ByteArray& encrypted)
{
    Aes256 aes(key);

    aes.encrypt_start(plain_length, encrypted);
    aes.encrypt_continue(plain, plain_length, encrypted);
    aes.encrypt_end(encrypted);

    return encrypted.size();
}
Ejemplo n.º 25
0
/* shel_copyenv(): copy len bytes of AES environment string into buf.
 *-----------------------------------------------------------------------
 * On AES < 4.0, returns AESERR (-1).
 * On AES >= 4.0, returns the number of bytes not copied.
 */
int
shel_copyenv(char *buf, short len)
{
	if (!isAES4()) return AESERR;
	int_in[0] = 8;
	int_in[1] = 1;
	int_in[2] = len;
	addr_in[0] = buf;
	return aes(SHEL_WRITE);
}
Ejemplo n.º 26
0
/* wind_bevent(): set/get a window's button event status.
 *-----------------------------------------------------------------------
 * If set == -1, returns 1 if the window gets button events when it's
 * untopped, or 0 if the window gets topped events when it's untopped.
 * If set >= 0 on AES < 4.0, returns -1.
 * If set >= 0 on AES >= 4.0, sets the window to get button events (set==1)
 * or topped events (set==0) when it is untopped, and returns 1.
 */
int
wind_bevent(int handle, int set)
{
	int func;
	if (!isAES4()) return (set == -1) ? 0 : AESERR;
	int_in[0] = handle;
	int_in[1] = WF_BEVENT;
	int_in[2] = set;
	func = (set < 0) ? WIND_GET : WIND_SET;
	return aes(func);
}
Ejemplo n.º 27
0
/* menu_popup(): handle a popup menu.
 *-----------------------------------------------------------------------
 * On AES < 4.0, returns AESERR (-1).
 * On AES >= 4.0, returns AESFAIL (0) if the user didn't click on an
 * enabled item, or 1 if the information in mdata is valid.
 */
int
menu_popup(const MENU *menu, int left_x, int top_y, MENU *mdata)
{
	if (!isAES33()) return AESERR;

	int_in[0] = left_x;
	int_in[1] = top_y;
	addr_in[0] = (void *)menu;
	addr_in[1] = mdata;
	return aes(MENU_POPUP);
}
Ejemplo n.º 28
0
// Encrypt/decrypt an entire input stream, writing to the given output stream
void Aes_ctr_encryptor::process_stream (std::istream& in, std::ostream& out, const unsigned char* key, const unsigned char* nonce)
{
	Aes_ctr_encryptor	aes(key, nonce);

	unsigned char		buffer[1024];
	while (in) {
		in.read(reinterpret_cast<char*>(buffer), sizeof(buffer));
		aes.process(buffer, buffer, in.gcount());
		out.write(reinterpret_cast<char*>(buffer), in.gcount());
	}
}
Ejemplo n.º 29
0
/* shel_run(): run a program concurrently
 *-----------------------------------------------------------------------
 * On AES < 4.0, returns AESERR (-1)
 * On AES >= 4.0, returns child process' AES id, or AESFAIL (0).
 */
int
shel_run(int mode, int isgem, int useargv, SH_RUN *p, const char *args)
{
	if (!isAES4()) return AESERR;
	int_in[0] = mode;
	int_in[1] = isgem;
	int_in[2] = useargv;
	addr_in[0] = (mode & 0xff00) ? (void *)p : (void *)p->cmd;
	addr_in[1] = (char *)args;
	return aes(SHEL_WRITE);
}
Ejemplo n.º 30
0
TEST_P(BlockCipherAdapter_AESCTR, AESCTR)
{
  int cases = std::min(GetParam().plain.size(), GetParam().cipher.size()) ;
  ASSERT_GT(cases, 0) << "No plain/cipher to test" ;

  AES aes(Decode(GetParam().key)) ;
  BlockCipherAdapter adapter(&aes, Decode(GetParam().iv), BlockCipherAdapter::Mode::CTR) ;

  for(int i=0;i<cases;i++)
    ASSERT_EQ(Decode(GetParam().cipher[i]), adapter.Encode(Decode(GetParam().plain[i]))) ;
}