CSPspEmu.Core.Crypto.Crypto.AES_cbc_encrypt C# (CSharp) Method

AES_cbc_encrypt() public static method

public static AES_cbc_encrypt ( AES_ctx ctx, byte src, byte dst, int size ) : void
ctx AES_ctx
src byte
dst byte
size int
return void
        public static void AES_cbc_encrypt(AES_ctx* ctx, byte* src, byte* dst, int size)
        {
            var _block_buff = new byte[16];
            fixed (byte* block_buff = _block_buff)
            {
                int i;
                for(i = 0; i < size; i+=16)
                {
                    //step 1: copy block to dst
                    memcpy(dst, src, 16);
                    //step 2: XOR with previous block
                    if(i != 0) xor_128(dst, block_buff, dst);
                    //step 3: encrypt the block -> it land in block buffer
                    AES_encrypt(ctx, dst, block_buff);
                    //step 4: copy back the encrypted block to destination
                    memcpy(dst, block_buff, 16);

                    dst += 16;
                    src += 16;
                }
            }
        }

Usage Example

Example #1
0
        public int kirk_CMD4(byte *outbuff, byte *inbuff, int size)
        {
            if (!is_kirk_initialized)
            {
                return(KIRK_NOT_INITIALIZED);
            }

            KIRK_AES128CBC_HEADER *header = (KIRK_AES128CBC_HEADER *)inbuff;

            if (header->Mode != KIRK_MODE_ENCRYPT_CBC)
            {
                return(KIRK_INVALID_MODE);
            }
            if (header->Datasize == 0)
            {
                return(KIRK_DATA_SIZE_ZERO);
            }

            byte *key = kirk_4_7_get_key(header->KeySeed);

            if (key == (byte *)KIRK_INVALID_SIZE)
            {
                return(KIRK_INVALID_SIZE);
            }

            //Set the key
            Crypto.AES_ctx aesKey;
            Crypto.AES_set_key(&aesKey, key, 128);
            Crypto.AES_cbc_encrypt(&aesKey, inbuff + sizeof(KIRK_AES128CBC_HEADER), outbuff, size);

            return(KIRK_OPERATION_SUCCESS);
        }
All Usage Examples Of CSPspEmu.Core.Crypto.Crypto::AES_cbc_encrypt