* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: aes_kat_ctr.s
* Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
* 4150 Network Circle, Santa Clara, California 95054, U.S.A.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* For the avoidance of doubt, and except that if any non-GPL license
* choice is available it will apply instead, Sun elects to use only
* the General Public License version 2 (GPLv2) at this time for any
* software where a choice of GPL license versions is made
* available with the language indicating that GPLv2 or any later version
* may be used, or where a choice of which version of the GPL is applied is
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* ========== Copyright Header End ============================================
#define MAIN_PAGE_HV_ALSO
#define NUM_MODE_PATTERNS 5
#define NUM_PATTERNS 3*NUM_MODE_PATTERNS
/************************************************************************
************************************************************************/
!# setup ASI register to point to SPU
!# Make sure CWQ is currently disabled, not busy, not terminated, no protocol error; else fail
ldxa [%g0 + ASI_SPU_CWQ_CSR] %asi, %l1
!# allocate control word queue (e.g., setup head/tail/first/last registers)
!# write base addr to first, head, and tail ptr
stxa %l6, [%g0 + ASI_SPU_CWQ_FIRST] %asi
ldxa [%g0 + ASI_SPU_CWQ_FIRST] %asi, %l1
!# Mask off upper 16 bits
setx 0x0000ffffffffffff, %l5, %l0
stxa %l6, [%g0 + ASI_SPU_CWQ_HEAD] %asi
ldxa [%g0 + ASI_SPU_CWQ_HEAD] %asi, %l1
stxa %l6, [%g0 + ASI_SPU_CWQ_TAIL] %asi
ldxa [%g0 + ASI_SPU_CWQ_TAIL] %asi, %l1
!# then end of CWQ region to LAST
stxa %l5, [%g0 + ASI_SPU_CWQ_LAST] %asi
ldxa [%g0 + ASI_SPU_CWQ_LAST] %asi, %l1
!# Mask off upper 16 bits
setx 0x0080000000000000, %l1, %g4 !# Encrypt/Decrypt flag (bit in CWQ)
setx plaintext_128, %g1, %l2
setx plaintext_addr, %g1, %l1
setx ciphertext_128, %g1, %l2
setx ciphertext_addr, %g1, %l1
mov 0, %g5 !# Encrypt/Decrypt counter
mov 0, %i4 !# Loop counter
mov 0, %i5 !# For plaintext/cipher/iv offset
mov 0, %i7 !# For key offset
!# Build the first control word, for the first AES vector.
!# For AES, set op = 64, Enc=1, SOB=EOB=1, SFAS=0, Int=CoreID=0, AuthType=0, EncType=13, status=0, Len=15
setx 0x406000001300000f, %l1, %l2
addcc %i4, 0-NUM_MODE_PATTERNS, %g0
addC 0, %g0, %g1 !# Add 1 on 192 bit keys => EncType=17
addcc %i4, 0-NUM_MODE_PATTERNS*2, %g0
addC 0, %g1, %g1 !# Add 2 on 256 bit keys => EncType=1b
!# %l6 points to CWQ_BASE
!# Note: All CWQ entry addresses must be physical!
!# Write source address to next CW field
setx plaintext_addr, %g1, %l2
!# Write 0's to the next 3 CW fields as they are not used
!# Write address of Encryption key
setx aes_key_128, %g1, %o2
setx ctr_iv_128, %g1, %l2
!# Finally write destination address to last CW field
!# Make sure all these stores get to memory before we start
!# Now add 1 (actually 8*8B) to tail pointer
ldxa [%g0 + ASI_SPU_CWQ_TAIL] %asi, %l2
stxa %l2, [%g0 + ASI_SPU_CWQ_TAIL] %asi
ldxa [%g0 + ASI_SPU_CWQ_TAIL] %asi, %l1
!# Kick off the CWQ operation by writing to the CWQ_CSR
!# Set the enabled bit and reset the other bits
stxa %g1, [%g0 + ASI_SPU_CWQ_CSR] %asi
!# Try CWQ_SYNC operation...
ldxa [%g0 + 0x30] %asi, %l1
!# Check for protocol error - Riesling should only have busy bit set
ldxa [%g0 + ASI_SPU_CWQ_CSR] %asi, %l1
!# check the results...first check the data
!# Each AES block is only 16B long (divide by 8 anyway)
!# set %l3 to be base address of result area, and
!# %l4 to be base address of known ciphertext area
setx ciphertext_addr, %g1, %l4
add %l6, 0x40, %l6 !# next CWQ
add %i5, 0x10, %i5 !# next pattern
add %i4, 1, %i4 !# loop counter
cmp %i4, NUM_MODE_PATTERNS
add %i7, 0x10, %i7 !# add offset for 128bit keys in branch delay
add %i7, 0x10, %i7 !# add offset for 192/256 bit keys (keep them aligned!)
!# Swap plain/cipher address
setx plaintext_addr, %g1, %l1
setx ciphertext_addr, %g1, %l2
setx 0x0080000000000000, %l1, %g1 !# Encrypt/Decrypt flag (bit in CWQ)
/************************************************************************
************************************************************************/
!# temporary area for storing expected result
.xword 0xDEADBEEFDEADBEEF, 0xDEADBEEFDEADBEEF
!# CWQ data area, set aside 512 CW's worth
.xword 0x53696E676C652062, 0x6C6F636B206D7367
.xword 0x0001020304050607, 0x08090A0B0C0D0E0F
.xword 0x1011121314151617, 0x18191A1B1C1D1E1F
.xword 0x0001020304050607, 0x08090A0B0C0D0E0F
.xword 0x1011121314151617, 0x18191A1B1C1D1E1F
.xword 0x53696E676C652062, 0x6C6F636B206D7367
.xword 0x0001020304050607, 0x08090A0B0C0D0E0F
.xword 0x1011121314151617, 0x18191A1B1C1D1E1F
.xword 0x0001020304050607, 0x08090A0B0C0D0E0F
.xword 0x1011121314151617, 0x18191A1B1C1D1E1F
.xword 0x53696E676C652062, 0x6C6F636B206D7367
.xword 0x0001020304050607, 0x08090A0B0C0D0E0F
.xword 0x1011121314151617, 0x18191A1B1C1D1E1F
.xword 0x0001020304050607, 0x08090A0B0C0D0E0F
.xword 0x1011121314151617, 0x18191A1B1C1D1E1F
.xword 0xAE6852F8121067CC, 0x4BF7A5765577F39E
.xword 0x7E24067817FAE0D7, 0x43D6CE1F32539163
.xword 0x7E24067817FAE0D7, 0x43D6CE1F32539163
.xword 0x7691BE035E5020A8, 0xAC6E618529F9A0DC
.xword 0x7691BE035E5020A8, 0xAC6E618529F9A0DC
.xword 0x16AF5B145FC9F579, 0xC175F93E3BFB0EED, 0x863D06CCFDB78515, 0x0
.xword 0x7C5CB2401B3DC33C, 0x19E7340819E0F69C, 0x678C3DB8E6F6A91A, 0x0
.xword 0x7C5CB2401B3DC33C, 0x19E7340819E0F69C, 0x678C3DB8E6F6A91A, 0x0
.xword 0x02BF391EE8ECB159, 0xB959617B0965279B, 0xF59B60A786D3E0FE, 0x0
.xword 0x02BF391EE8ECB159, 0xB959617B0965279B, 0xF59B60A786D3E0FE, 0x0
.xword 0x776BEFF2851DB06F, 0x4C8A0542C8696F6C, 0x6A81AF1EEC96B4D3, 0x7FC1D689E6C1C104
.xword 0xF6D66D6BD52D59BB, 0x0796365879EFF886, 0xC66DD51A5B6A9974, 0x4B50590C87A23884
.xword 0xF6D66D6BD52D59BB, 0x0796365879EFF886, 0xC66DD51A5B6A9974, 0x4B50590C87A23884
.xword 0xFF7A617CE69148E4, 0xF1726E2F43581DE2, 0xAA62D9F805532EDF, 0xF1EED687FB54153D
.xword 0xFF7A617CE69148E4, 0xF1726E2F43581DE2, 0xAA62D9F805532EDF, 0xF1EED687FB54153D
.xword 0xE4095D4FB7A7B379, 0x2D6175A3261311B8
.xword 0x5104A106168A72D9, 0x790D41EE8EDAD388
.xword 0xEB2E1EFC46DA57C8, 0xFCE630DF9141BE28
.xword 0xC1CF48A89F2FFDD9, 0xCF4652E9EFDB72D7
.xword 0x4540A42BDE6D7836, 0xD59A5CEAAEF31053
.xword 0x4B55384FE259C9C8, 0x4E7935A003CBE928
.xword 0x453243FC609B2332, 0x7EDFAAFA7131CD9F
.xword 0x8490701C5AD4A79C, 0xFC1FE0FF42F4FB00
.xword 0x96893FC55E5C722F, 0x540B7DD1DDF7E758
.xword 0xD288BC95C6916588, 0x4536C811662F2188
.xword 0x145AD01DBF824EC7, 0x560863DC71E3E0C0
.xword 0xF05E231B3894612C, 0x49EE000B804EB2A9
.xword 0xB8306B508F839D6A, 0x5530831D9344AF1C
.xword 0xEB6C52821D0BBBF7, 0xCE7594462ACA4FAA
.xword 0xB407DF866569FD07, 0xF48CC0B583D6071F
.xword 0x0000003000000000, 0x0000000000000001
.xword 0x006CB6DBC0543B59, 0xDA48D90B00000001
.xword 0x006CB6DBC0543B59, 0xDA48D90B00000002
.xword 0x00E0017B27777F3F, 0x4A1786F000000001
.xword 0x00E0017B27777F3F, 0x4A1786F000000002
.xword 0x0000004836733C14, 0x7D6D93CB00000001
.xword 0x0096B03B020C6EAD, 0xC2CB500D00000001
.xword 0x0096B03B020C6EAD, 0xC2CB500D00000002
.xword 0x0007BDFD5CBD6027, 0x8DCC091200000001
.xword 0x0007BDFD5CBD6027, 0x8DCC091200000002
.xword 0x00000060DB5672C9, 0x7AA8F0B200000001
.xword 0x00FAAC24C1585EF1, 0x5A43D87500000001
.xword 0x00FAAC24C1585EF1, 0x5A43D87500000002
.xword 0x001CC5B751A51D70, 0xA1C1114800000001
.xword 0x001CC5B751A51D70, 0xA1C1114800000002