Can I update sha-256 digest chunk-wise instead of the whole array at once? I'm not sure whether this questions is about SHA-256 algorithm itself or the particular implementation I'm using.

Usually, a hash algorithm implementation has functions, let us call them update and finalize. update feeds another chunk of data, finalize possibly feeds the last chunk and calculates the digest.

Should passing the whole array at once produce the same hash as passing it's chunks one by one? In other words, update(whole_array) vs update(1st_half); update(2nd_half)
TL;DR: As long as the concatenation of all the binary input to the update / final operations, in order is identical then the secure hash function should return the same output hash.



The hash function implementations generally have a buffer the size of the block size. This internal block size is generally hidden to the user. For SHA-256 the block size is 512 bits, 64 bytes or - as SHA-256 is build using 32-bit operations - sixteen 32-bit words.

So what happens is that during update the buffer is filled until it is full, which is then processed by the internal compression function, altering the internal state. Then the buffer is filled again and again until all the blocks have been processed. The last part of the update will leave the buffer empty or partially filled. When a new update is processed the whole situation is repeated, starting with the values in the buffer from the last update (if any).

When the final is called then the input data for the final operation is processed as if it was an update. Then the internal bit padding (a one bit followed by X zero bits) takes place and the encoding of the total length is added. This forms the last one or two blocks which are then processed in order. 



So with the description above, it is clear that passing the whole array at once produce the same hash as passing it's chunks one by one. This is because the the same buffers will be processed and the internal state will therefore be updated in exactly the same way. The required padding and total length is the same as well. That's all the input to the block operations within SHA-2 so the final output must be identical too.



If you get a different result then you may have run into encoding issues. SHA-2 processes binary data: bits or - for most implementations - bytes. If you perform a different encoding on a string (e.g. UTF-8 vs UTF-8 with Byte Order Mark) then the input will differ and the hash result will differ as well. In principle, the implementation could be faulty as well, but usually this is not the case; there aren't all that many input variants / edge cases to test and test vectors exist.



Notes:


It depends on the implementation if the final operation can contain input data or not. If it does it is identical to having an additional update with the given data and then performing the final operation with the padding and length encoding.
SHA-224 uses the same block size / 32-bit operations as SHA-256; SHA-512 uses 1024 bit blocks and 64-bit operations internally, and so does SHA-384 and the less common SHA-512/224 and SHA-512/256 hash functions.
SHA-3 uses a different internal scheme (a construction using a sponge instead of a Merkle-Damgard construction) but the description of the buffering and block size is still valid.