Skip to content
Snippets Groups Projects
Commit bc1592ac authored by da1l6's avatar da1l6
Browse files

ATMegaCard: Move keystore to portal application dir. Its only used there.

parent 0e4b64a9
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,7 @@ OPT = s ...@@ -54,7 +54,7 @@ OPT = s
# If there is more than one source file, append them above, or modify and # If there is more than one source file, append them above, or modify and
# uncomment the following: # uncomment the following:
SRC = main.c software_serial.c ISO7816-card.c keystore.c rng.c ../common/sha1/sha1.c applications/portal/portal.c SRC = main.c software_serial.c ISO7816-card.c rng.c ../common/sha1/sha1.c applications/portal/keystore.c applications/portal/portal.c
# List Assembler source files here. # List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s # Make them always end in a capital .S. Files ending in a lowercase .s
......
File moved
File moved
#!/usr/bin/ruby
KEYSTORE_OFFSET=127
KEY_LENGTH=64
class IntelHexWriter
RECORD_LENGTH=0x20
RECORD_TYPE_DATA = 0x00
def initialize(filename)
@file = File.open(filename, "w")
@offset = 0
@record = ""
end
public; def write_data(data)
while(data && data.length > 0)
bytesleft = RECORD_LENGTH - @record.length
@record += data[0, bytesleft]
data = data[bytesleft..-1]
write_record() if (data && data.length > 0)
end
end
private; def write_record()
r = (":%02X%04X%02X" % [@record.length, @offset, RECORD_TYPE_DATA])
checksum = @record.length + (@offset & 0xFF) + (@offset >> 8) + RECORD_TYPE_DATA
r += @record.bytes.map{|b| checksum=(checksum+b) & 0xFF; "%02X" % b}.join()
r += "%02X" % ((((checksum & 0xFF) ^ 0xFF) + 1) & 0xFF)
r += "\r\n"
@file.write(r)
@record = ""
@offset += RECORD_LENGTH
end
public; def close()
write_record() if (@record.length > 0)
@file.write(":00000001FF\n")
@file.close
end
end
def hex2bin(hex)
c = hex.length / 2
bin = ('.'.encode('ASCII-8BIT'))*c
(0...c).each{|i|
bin.setbyte(i,hex[i << 1, 2].hex)
}
return bin
end
eeprom_file = ARGV[0]
keystring = ARGV[1]
if ((!eeprom_file.kind_of?(String)) || (!keystring.kind_of?(String)) || keystring.length != (2*KEY_LENGTH))
puts "Usage: #{$0} hexfilename keystring"
exit 1
end
print("Writing EEPROM key to #{eeprom_file}...")
f = IntelHexWriter.new(eeprom_file)
f.write_data("\xFF"*KEYSTORE_OFFSET)
f.write_data("\x00")
f.write_data(hex2bin(keystring))
f.write_data("\xFF"*KEY_LENGTH)
f.close
puts("OK")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment