Category Archives: cryptography

What does endianness have to do with Bitcoins

The order of the byte appears is called the endianness in computer technology. This term stem from processor architecture design, for example, x86 and the classic 6502 is little endian, while S/360 and SPARC are big endian. ARM processors like the one powering the Beagleboard SBC I am happy with from Yubikey to the R statistics package can be configured to run either.

At the end of the day, programs are compiled and linked to instruction sets for the hardware processor to execute. But that is not the end of the story for software developers. Apart from the hardware instruction sets there are also endianness in file. Any developers having involved in any form of low level file processing, in classic or modern programming languages alike, should be very familiar with this.

Take the bitcoin file as en example, the hex dump below is the genesis bitcoin with the timestamp field highlighted in yellow.

bitcoinraw02

On file it reads 29AB5F49, but for the sake of endianness, this value should be interpreted as 495FAB29 in hexadecimal, and the corresponding decimal value is 1231006505. Converting this decimal value timestamp into human readable date:
bitcoinraw03

It is quite trivial to convert from one to another through programming languages and a classic C example as simple as the below macro will do the job.

bitcoinraw04

In Python:

bitcoinraw07

Advertisements

Using TI Nspire to explore mathematics behind blockchain technology

The TI Nspire is a great tool for exploring mathematics through its calculation and graphing capability. One of the emerging technologies that is based on mathematics is blockchain. It gained popularity through bitcoin that caused much debate and controversy in the field of banking, economics and finance. Until recently more and more established research and technology firms started to look at it seriously and its underlying core technology, blockchain, is gaining momentum for being adopted by traditional financial institutions.

In a previous installment, the property of the Elliptic Curve is explored using TI Nspire. As shown in the dynamic graph below, the curve exhibit several properties that form the two basic operations of asymmetric encryption – point addition and point doubling – for public and private key pair generation.

ecanim

Using a=0, and b=7 as in Bitcoin, the two properties are basically illustrated in the following graphs.

Point Addition
blockchainecc1c

Point Doubling
blockchainecc2c2

However, in reality, the Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm to generate public and private key relied also on another mathematical concept known as the finite field. This is basically a limit imposed on the numbers that are available for use in the calculation, and in this case, positive integers from a modulo calculation. The prime modulo for Bitcoin (as in secp256k1) is set to  2256 – 232 – 29 – 28 – 27 – 26 – 24 – 1. Having this in place, the graph will not look like the above but some scattered points on a fixed region, and overflows will wrap around. However, the symmetry will still be preserved and recognized visually on graph.

With this mathematical backed technology as the foundation, blockchain can provides open ledger for secure transaction service.

SHA-256 initial hash derivation explained in TI Nspire

The SHA-256 is a cryptographic hash function with many usages. From bitcoin and block chain calculation to digital signature, SHA-256 played a pivotal role.

From the official definition, there are 8 initial hash values in the algorithm. They are hexadecimal form of the fractional part of the square roots of the first 8 prime numbers 2, 3, 5, 7, 11, 13, 17, and 19. The values are:

nspire-sha256-1

In practice these initial values are constants, but for demonstrating how fractions are represented in hexadecimal, the calculation can be shown in TI Nspire although no built-in support is provided for hexadecimal fractions. The calculation is very simple, take the fractional part from the value times 16, and then convert the integer part to hexadecimal. Repeat with the resulting value to concatenate the answer. In the below example, the second SHA-256 initial hash value calculation is shown (first three most significant value).

nspire-sha256-2