⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 des_driver_size.s

📁 ATMEL XMEGA crypto program-task2.
💻 S
📖 第 1 页 / 共 2 页
字号:
// ----------
// This routine is called by several other routines, and contains common code
// for executing single/triple DES encryption.
//
// Note: The data need to be preloaded and R16 must be set to triple or single DES.
//       This function only load the keys and do the encryption.
//
// Input:
//    - R21:R20 - pointer to key buffer.
//    - R16 - if non-zero, triple DES is performed.
//
// Register usage during DES_Encryption:
//
// During execution:
//   - R31:R30 (Z) is used for misc memory pointing and is not preserved.
//   - R16 contains a variable that is non-zero for doing 3DES, zero for single DES.
//   - R15 - R8 contains current key being processed.
//   - R7  - R0 contains the data (plaintext or ciphertext).
// ----------
DES_INTERNAL_DES_Encrypt:
	// Load pointer to first key into Z pointer and store the key to R15-R8
	movw	r30, r20
	rcall	DES_INTERNAL_Load_Into_R15_R8

	clh
	rcall	DES_INTERNAL_DES_Routine

	// Test if register is zero, and go to end if single encryption only.
	tst	r16
	breq	DES_INTERNAL_DES_Single_Encrypt

	// Load pointer to second key into Z pointer and store the key to R15-R8
	movw	r30, r20
	adiw	r30, 8
	rcall	DES_INTERNAL_Load_Into_R15_R8

	seh
	rcall	DES_INTERNAL_DES_Routine

	// Load pointer to third key into Z pointer and store the key to R15-R8
	movw	r30, r20
	adiw	r30, 16
	rcall	DES_INTERNAL_Load_Into_R15_R8

	clh
	rcall	DES_INTERNAL_DES_Routine

DES_INTERNAL_DES_Single_Encrypt:
	ret


// ----------
// This routine is called by several other routines, and contains common code
// for executing single/triple DES decryption.
//
// Note: The data need to be preloaded and R16 must be set to triple or single DES.
//       This function only load the keys and do the decryption.
//
// Input:
//    - R21:R20 - pointer to key buffer.
//    - R16 - if non-zero, triple DES is performed.
//
// Register usage during DES_Decryption:
//
// During execution:
//   - R31:R30 (Z) is used for misc memory pointing and is not preserved.
//   - R16 contains a variable that is non-zero for doing 3DES, zero for single DES.
//   - R15 - R8 contains current key being processed.
//   - R7  - R0 contains the data (plaintext or ciphertext).
// ----------
DES_INTERNAL_DES_Decrypt:
	
	// Test if register is zero. Go to single decryption if zero.
	tst	r16
	breq	DES_INTERNAL_DES_Single_Decrypt

	// Load pointer to third key into Z pointer and store the key to R15-R8
	movw	r30, r20
	adiw	r30, 16
	rcall	DES_INTERNAL_Load_Into_R15_R8

	seh
	rcall	DES_INTERNAL_DES_Routine

	// Load pointer to second key into Z pointer and store the key to R15-R8
	movw	r30, r20
	adiw	r30, 8
	rcall	DES_INTERNAL_Load_Into_R15_R8

	clh
	rcall	DES_INTERNAL_DES_Routine

DES_INTERNAL_DES_Single_Decrypt:

	// Load pointer to first key into Z pointer and store the key to R15-R8
	movw	r30, r20
	rcall	DES_INTERNAL_Load_Into_R15_R8

	seh
	rcall	DES_INTERNAL_DES_Routine

	ret


// ----------
// This routine is called by several other routines, and contains common code
// for loading data to R7-R0.
//
// Input:
//    - R25:R24 - pointer to input buffer.
//
// Register usage during DES_INTERNAL_Load_Data:
//
// During execution:
//   - R31:R30 (Z) is used for misc memory pointing and is not preserved.
//   - R7 - R0 contains the data (plaintext or ciphertext)
//
// Returns:
//     R25:R24 - updated input pointer.
// ----------
DES_INTERNAL_Load_Data:
	movw	r30, r24
	ld	r7, Z+
	ld	r6, Z+
	ld	r5, Z+
	ld	r4, Z+
	ld	r3, Z+
	ld	r2, Z+
	ld	r1, Z+
	ld	r0, Z+
	movw	r24, r30
	ret


// ----------
// This routine is called by several other routines, and contains common code
// for loading data to R15-R8.
//
// Input:
//    - R31:R30 - pointer to data buffer.
//
// Register usage during DES_INTERNAL_Load_Into_R15_R8:
//
// During execution:
//   - R31:R30 (Z) is used for misc memory pointing and is not preserved.
//   - R15 - R8 contains the data (plaintext or ciphertext)
// ----------
DES_INTERNAL_Load_Into_R15_R8:
	ld	r15, Z+
	ld	r14, Z+
	ld	r13, Z+
	ld	r12, Z+
	ld	r11, Z+
	ld	r10, Z+
	ld	r9,  Z+
	ld	r8,  Z+
	ret


// ----------
// This routine is called by several other routines, and contains common code
// to XOR two 64 bits values.
//
// Input:
//     R15 - R8 - 64 bits value.
//     R7  - R0 - 64 bits value.
//
// Returns:
//     R7  - R0 - 64 bits xored value.
// ----------
DES_INTERNAL_XOR_Routine:
	eor	r7, r15
	eor	r6, r14
	eor	r5, r13
	eor	r4, r12
	eor	r3, r11
	eor	r2, r10
	eor	r1,  r9
	eor	r0,  r8
	ret		


// ----------
// This routine is called by several other routines, and contains common code
// for storing data located in register 7 to 0 to memory pointed to by Z.
//
// Input:
//     R23:R22 - pointer to ouput memory.
//
// Registers used during execution:
//     R31:R30 - Z pointer is used, and not preserved.
//
// Returns:
//     R23:R22 - updated output pointer.
// ----------
DES_INTERNAL_Store_Data:
	movw	r30, r22
	st	Z+,  r7
	st	Z+,  r6
	st	Z+,  r5
	st	Z+,  r4
	st	Z+,  r3
	st	Z+,  r2
	st	Z+,  r1
	st	Z+,  r0
	movw	r22, r30
	ret


// ----------
// This routine is called by several other routines, and contains common code
// doing the DES encryption/decryption.
//
// Input:
//     R15 - R8 - 64 bits key.
//     R7  - R0 - 64 bits plaintext/ciphertext.
//
// Returns:
//     R7 -  R0 - 64 bits ciphertext/plaintext.
//     R8 - R15 - 64 bits key.
// ----------
DES_INTERNAL_DES_Routine:
	des	0
	des	1
	des	2
	des	3
	des	4
	des	5
	des	6
	des	7
	des	8
	des	9
	des	10
	des	11
	des	12
	des	13
	des	14
	des	15
	ret


// ----------
// This routine is called by several other routines, and contains common code
// for preserving register defined in GCC.
//
// Note: The function call pushes the Program Counter on the stack, and this
//       must be popped out and placed after the preserved data on the stack.
//
// Note: If the Program Counter is 22-bits, 3 bytes has to be popped and pushed.
// ----------
DES_INTERNAL_Prolog:
#ifdef __22_BIT_PC__
	pop	r27
#endif
	pop	r30
	pop	r31

	push	r0
	push	r1
	push	r2
	push	r3
	push	r4
	push	r5
	push	r6
	push	r7
	push	r8
	push	r9
	push	r10
	push	r11
	push	r12
	push	r13
	push	r14
	push	r15
	push	r16
	push	r17
	push	r28
	push	r29

	push	r31
	push	r30
#ifdef __22_BIT_PC__
	push	r27
#endif
	ret


// ----------
// This routine is referenced by several other routines, and contains common code
// for restoring register defined in GCC.
//
// Note: This is the last routine to perform in the other routines and should not
//       be called and a jump to this routine should be performed instead.
//       If a function call is done, this will push the Program Counter on the stack,
//       and this must be popped out and placed after the preserved data on the stack.
//
// Note: If the Program Counter is 22-bits, 3 bytes has to be popped and pushed.
// ----------
DES_INTERNAL_Epilog:
	pop	r29
	pop	r28
	pop	r17
	pop	r16
	pop	r15
	pop	r14
	pop	r13
	pop	r12
	pop	r11
	pop	r10
	pop	r9
	pop	r8
	pop	r7
	pop	r6
	pop	r5
	pop	r4
	pop	r3
	pop	r2
	pop	r1
	pop	r0
	ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -