ATECC608A : SHA command (I²C)

Viewed 62

I am working with the ATECC608a chip and trying to execute the SHA command sending I²C signals. I have modified the atecc608.go file (https://github.com/f-secure-foundry/armoryctl). You can find the full datasheet here : https://atecc608a.github.io/.

First I have to send a sha_start command, then 1 or several sha_update commands and finally a sha_end command.

My problem is that when I send the update command, a parse error occurs but I don't know why. I think that the bytes sent are correct but it seems that the chip doesn't see it that way. Here is my code that I add to the file :

func sha_start() (err error) {

   _, err = ExecuteCmd(Cmd["SHA"],[1]byte{0x00},[2]byte{0x00,0x00},nil,true)

   if err != nil{
       return
   }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

   return nil
}

func sha_update(data []byte) (err error){
    _, err = ExecuteCmd(Cmd["SHA"],[1]byte{0x01},[2]byte{0x00,0x00}, data,true)                                                                                                                                                                                                                                                                                                                                                                                                               

    if err != nil{                                                                                                                                                                                                                                                                                                                                                                                                                                                         
        return
    }

    return nil 
}

func sha_end() (res []byte, err error){

    res, err = ExecuteCmd(Cmd["SHA"],[1]byte{0xC2},[2]byte{0x00,0x00},nil,true)

    if err != nil{
        return
    }

    return res, nil
}

func sha_steps(data []byte) (res []byte, err error){ 

    err = sha_start()
 
    if err != nil{
        return
    }

    err = sha_update(data)

    if err != nil{
        return
    }

    res, err = sha_end()

    if err != nil{
        return
    }

    return res, nil
}

func SHA() (res string, err error){

    rn, err := ExecuteCmd(Cmd["Rand"], [1]byte{0x00}, [2]byte{0x00, 0x00}, nil, true) 

    if err != nil{
       return
    }

    sha_digest, err := sha_steps(rn)

    if err != nil{
        return
    }

    return fmt.Sprintf("\nData : 0x\nSHA Digest : 0x%x\n\n", sha_digest), nil
}

When I watch to the byte that the first command (sha_start) return (via the function ExecuteCmd()) I have that : 0x00%!(EXTRA string=), I should normally have 0x00 but I think this is from the function fmt.SprintF().

The parameters of the I²C messages are the following : sha_start : Param1 = 0x00, Param2 = 0x00, 0x00 (byte 0, byte 1), data = nothing.

sha_update : Param1 = 0x01, Param2 = 0x00, 0x00 (byte 0, byte 1), data = 32 randomly generated bytes.

sha_end : Param1 = 0xC2, Param2 = 0x00, 0x00 (byte 0, byte 1), data = nothing.

The Rand command returns 32 bytes randomly generated by the chip and the sha_update command accept 1 to 64 bytes of data. Other commands work fine.

1 Answers

Actually, the armoryctl tool sent the chip to SLEEP, and the sha context was deleted in the chip when it goes to sleep. The armoryctl tool was modified to send the chip to the IDLE state where the sha context is not deleted.

""" the problem was that we were sleeping after each command, rather than idling, and that caused the internal temporary registers to be cleared """, Collaborator abarisani on the github (https://github.com/f-secure-foundry/armoryctl/).

Related