# S boxes in Blowfish

I know how the s-boxes in blowfish are initialized, but how is the output sorted, I mean which bit from the input goes where in the box ? and what do mean they have 256 entries if they are 32-bit S-Boxes ?

• Blowfish s-boxes have 256 entries, because they have 8-bit input and 32-bit output. I do not understand other part of the question. Commented Nov 29, 2015 at 17:32
• Oh hi, I mean for every 8 bit input a 32 bit output is generated right? how is this mapping done ? for example in DES S-Boxes we use the outer and Inner bits method
– user29481
Commented Nov 29, 2015 at 17:40
• It splits half block in 4 8-bit pieces, which are then used as an input to s-box (each piece goes through different s-box). 32-bit output of s-boxes is than combined. See this picture: upload.wikimedia.org/wikipedia/commons/2/22/… Commented Nov 29, 2015 at 19:09
• yeah, thanks man but you still didn't get my question :<. I get this part, what I meant is how does the algorithm decide what 8 bits get mapped to which 32 bits ? If the incoming bits are 11110000 how does the S-Box get the output 32 ?
– user29481
Commented Nov 29, 2015 at 19:39
• Table lookup. Value from 11110000 (240)th position. Commented Nov 29, 2015 at 20:29

A 32-bit value output is chosen from a table depending on an 8-bit input value.

The s-box within block ciphers is typically implement with a table, with a fixed input and output size. Some ciphers have the same input and output size; for example, for AES, it uses an sbox with 8 bit inputs and outputs, while Serpent uses an sbox with 4 bit inputs and outputs. When the sbox is implemented as a table, the output size defines size of entries and the input size defines number of entries. In the case of Blowfish, the input is 8-bit (and hence there are 256 entries), and the output is 32-bit (and hence each entry is 32 bits long). These sbox contents are generated during key setup.

In C Blowfish s-boxes are defined as:

uint32_t S[256];

• How will it convery the 8 bit input to 32 bit output?? Commented Jan 30, 2019 at 4:17
• @Sathwikareddy using table lookup. Commented Jan 31, 2019 at 18:28

In blowfish Algorithm, there are 4 S-Box .Each S-Box contains S-table with 8 rows and 32 columns, total of 256 entries.

S-Box take 8-bit input, where 1st, 7th and 8th bit of input is used to determines row. These 3-bit determines row from 8 rows of S-table. (3-bit gives 0 to 7)

Remaining 5-bits of input (i.e. 2nd, 3rd, 4th, 5th and 6th bits) determines column from 32 columns of S-table.(5-bit gives 0 to 31)

Each of 256 entries contains 32-bit(4-byte) of predefined value which provided as output from S-box depending on input.