SHA-1 or SHA1 is a one-way hash function;
it computes a 160-bit message digest.
SHA-1 often appears in security protocols; for example,
many HTTPS websites use RSA with SHA-1 to secure their connections.
BitTorrent uses SHA-1 to verify downloads.
Git and Mercurial use SHA-1 digests to identify commits.

A US government standard, FIPS 180-1, defines SHA-1.

Find the SHA-1 message digest for a string of octets. You may either call a SHA-1 library, or implement SHA-1 in your language. Both approaches interest Rosetta Code.



 Warning: SHA-1 has known weaknesses. Theoretical attacks may find a collision after 252 operations, or perhaps fewer.
This is much faster than a brute force attack of 280 operations. USgovernment deprecated SHA-1.
For production-grade cryptography, users may consider a stronger alternative, such as SHA-256 (from the SHA-2 family) or the upcoming SHA-3.


 
 
/* ARM assembly Raspberry PI  */
/*  program sha1-1.s   */
/* use with library openssl */
/* link with gcc option  -lcrypto -lssl  */
 
/* REMARK 1 : this program use routines in a include file 
   see task Include a file language arm assembly 
   for the routine affichageMess conversion10 
   see at end of this program the instruction include */
 
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes                       */
/************************************/
.include "../constantes.inc"
 
.equ SHA_DIGEST_LENGTH, 20
 
/*******************************************/
/* Fichier des macros                       */
/********************************************/
.include "../../ficmacros.s"
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
szMessRosetta:        .asciz "Rosetta Code"
                      .equ LGMESSROSETTA, . - szMessRosetta - 1
szCarriageReturn:     .asciz "\n"
szMessSup64:          .ascii "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                      .ascii "abcdefghijklmnopqrstuvwxyz"
                      .asciz "1234567890AZERTYUIOP"
                      .equ LGMESSSUP64, . - szMessSup64 - 1
szMessTest2:          .asciz "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
                      .equ LGMESSTEST2,  . - szMessTest2 - 1
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss
.align 4
szMessResult:              .skip 24
sZoneConv:                 .skip 24
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                                      @ entry of program 
 
    ldr r0,iAdrszMessRosetta
    mov r1,#LGMESSROSETTA
    ldr r2,iAdrszMessResult
    bl SHA1                                @ appel fonction openssl 
    ldr r0,iAdrszMessResult
    bl displaySHA1
 
100:                                       @ standard end of the program 
    mov r0, #0                             @ return code
    mov r7, #EXIT                          @ request to exit program
    svc #0                                 @ perform the system call
 
iAdrszMessRosetta:        .int szMessRosetta
iAdrszCarriageReturn:     .int szCarriageReturn
iAdrszMessResult:         .int szMessResult
iAdrsZoneConv:            .int sZoneConv
iAdrszMessSup64:          .int szMessSup64
iAdrszMessTest2:          .int szMessTest2
/******************************************************************/
/*     display hash  SHA1                         */ 
/******************************************************************/
/* r0 contains the address of hash  */
displaySHA1:
    push {r1-r3,lr}                  @ save  registres
    mov r3,r0
    mov r2,#0
1:
    ldr r0,[r3,r2,lsl #2]            @ load 4 bytes
    rev r0,r0                        @ reverse bytes
    ldr r1,iAdrsZoneConv
    bl conversion16                  @ conversion hexa
    ldr r0,iAdrsZoneConv
    bl affichageMess
    add r2,r2,#1
    cmp r2,#SHA_DIGEST_LENGTH / 4
    blt 1b                           @ and loop
    ldr r0,iAdrszCarriageReturn
    bl affichageMess                 @ display message
100:
    pop {r1-r3,lr}                   @ restaur registers
    bx lr                            @ return  
/***************************************************/
/*      ROUTINES INCLUDE                 */
/***************************************************/
.include "../affichage.inc"
 