📄 security.psm
字号:
;become lower than intended.
;
CONSTANT delay_1us_constant, 0B
;
;
;
;
;ASCII table
;
CONSTANT character_a, 61
CONSTANT character_b, 62
CONSTANT character_c, 63
CONSTANT character_d, 64
CONSTANT character_e, 65
CONSTANT character_f, 66
CONSTANT character_g, 67
CONSTANT character_h, 68
CONSTANT character_i, 69
CONSTANT character_j, 6A
CONSTANT character_k, 6B
CONSTANT character_l, 6C
CONSTANT character_m, 6D
CONSTANT character_n, 6E
CONSTANT character_o, 6F
CONSTANT character_p, 70
CONSTANT character_q, 71
CONSTANT character_r, 72
CONSTANT character_s, 73
CONSTANT character_t, 74
CONSTANT character_u, 75
CONSTANT character_v, 76
CONSTANT character_w, 77
CONSTANT character_x, 78
CONSTANT character_y, 79
CONSTANT character_z, 7A
CONSTANT character_A, 41
CONSTANT character_B, 42
CONSTANT character_C, 43
CONSTANT character_D, 44
CONSTANT character_E, 45
CONSTANT character_F, 46
CONSTANT character_G, 47
CONSTANT character_H, 48
CONSTANT character_I, 49
CONSTANT character_J, 4A
CONSTANT character_K, 4B
CONSTANT character_L, 4C
CONSTANT character_M, 4D
CONSTANT character_N, 4E
CONSTANT character_O, 4F
CONSTANT character_P, 50
CONSTANT character_Q, 51
CONSTANT character_R, 52
CONSTANT character_S, 53
CONSTANT character_T, 54
CONSTANT character_U, 55
CONSTANT character_V, 56
CONSTANT character_W, 57
CONSTANT character_X, 58
CONSTANT character_Y, 59
CONSTANT character_Z, 5A
CONSTANT character_0, 30
CONSTANT character_1, 31
CONSTANT character_2, 32
CONSTANT character_3, 33
CONSTANT character_4, 34
CONSTANT character_5, 35
CONSTANT character_6, 36
CONSTANT character_7, 37
CONSTANT character_8, 38
CONSTANT character_9, 39
CONSTANT character_colon, 3A
CONSTANT character_fullstop, 2E
CONSTANT character_semi_colon, 3B
CONSTANT character_minus, 2D
CONSTANT character_divide, 2F ;'/'
CONSTANT character_plus, 2B
CONSTANT character_comma, 2C
CONSTANT character_less_than, 3C
CONSTANT character_greater_than, 3E
CONSTANT character_equals, 3D
CONSTANT character_space, 20
CONSTANT character_CR, 0D ;carriage return
CONSTANT character_question, 3F ;'?'
CONSTANT character_dollar, 24
CONSTANT character_exclaim, 21 ;'!'
CONSTANT character_BS, 08 ;Back Space command character
;
;
;
;
;
;**************************************************************************************
;Initialise the system
;**************************************************************************************
;
cold_start: CALL SF_init ;initialise StrataFLASH controls
LOAD s0, 00 ;Start with application enabled in hardware
OUTPUT s0, authentication_control_port
LOAD s0, character_P ;start with design enabled by software (see ISR)
STORE s0, authentication_status
CALL delay_1s ;delay to allow system to settle
CALL LCD_reset ;Initialise the LCD
;
ENABLE INTERRUPT ;interrupts to provide software enable to application
;
;**************************************************************************************
; Main program
;**************************************************************************************
;
; The main program follows a logical sequence of events describing the power on and
; authentication process of a design. This process will is either successfully authorises
; the 'real' application to operate or fail to authenticate and disable the 'real'
; application in a similar way to a production design. The only difference that it keeps
; you informed about what it is doing on both the LCD display and PC terminal via the UART.
; A real production design should keep all details hidden.
;
; Following the authentication check and control over the 'real' application a simple menu
; is provided on the PC terminal to allow you to read, write and erase the authentication
; area of the StrataFLASH memory and therefore evaluate the design authentication security
; of this reference design.
;
;
;
; Write welcome message to LCD display
;
warm_start: LOAD s5, 12 ;Line 1 position 2
CALL LCD_cursor
CALL disp_PicoBlaze ;Display 'PicoBlaze'
LOAD s5, 25 ;Line 2 position 5
CALL LCD_cursor
CALL disp_Security ;Display 'Security'
;
; Write welcome message to PC via UART
;
CALL send_welcome
;
;
; Display 'Copyright Ken Chapman 2006' via the UART.
;
; This message is significant because it demonstrates that the design now has a 'watermark'.
; The ASCII codes for this string are part of the PicoBlaze program stored in a Block
; Memory and therefore are also part of the configuration bit stream. If someone tries to
; change or delete this copyright message the hardware design will detect the change to the
; Block memory contents and also inhibit the design.
;
CALL send_Copyright
;
;
;
; Delay of 10 seconds before performing any security checks.
;
; This allows the design to work for a short time which could be important for
; production testing.
;
; Having a significant time delay (days or weeks) before security checks means that someone
; attempting to clone the product may not be aware that there is any form of design security
; at all until products are in the field are failing. A time delay also impedes the ability to
; attempt to break the security and confirm if an attempt is or is not successful.
;
LOAD s5, 0A ;delay of 10 seconds.
CALL delay_Ns
;
;
;
; Read serial number of the StrataFLASH memory.
; The whole principle of low cost design security is based on this unique number. Clearly this
; number is not a secret, but what we then go on to do with it should normally be kept secret.
;
CALL read_SF_serial_number ;read serial number from FLASH memory
CALL send_serial_number ;send value to UART for display on PC
CALL disp_serial_number ;display serial number on LCD display.
CALL send_CR
;
;
;
LOAD s5, 0A ;delay of 10 seconds to read messages.
CALL delay_Ns
;
;
;
; Compute the 16-bit CRC for the serial number as an authentication value for the design.
; The CRC value is formed in register pair [sE,sD]. To complicate the authentication value
; the initial contents of the registers are seeded with a 'secret' number.
; Hint 1 - The CRC computation could be implemented in hardware where it is less visible.
; Hint 2 - There are more secure algorithms such as SHA-1 which could be used to generate
; authentication values that are extremely difficult to decode.
;
;
LOAD sE, 15 ;seed CRC register with an initial value provided by my daughter when asked :-)
LOAD sD, 8E
CALL compute_seeded_CRC ;compute CRC for serial number and configuration memory
;
; Store CRC value in scratch pad memory and display computed CRC value on the PC via UART.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -