Friday, February 3, 2023

Which one to use - SHA256sum vs md5sum

  • Both algorithms SHA256sum and md5sum generate a hash. 
  • md5sum generates 128bit hash vs 256 bit hash for sha256sum. In theory, that can reduce hash collisions i.e. two different files/entities being hashed generating the same hash value.
  • Which algorithm to use depends on the use case i.e. the entity/ file being hashed. We want to pick something that does not result in a hash collision.
  • For most cases, 132bit hash sum is more than good enough for supporting a large number of unique items with very low probability of collision [2]. e.g. with a 160bit hash with 2* 10^20 unique entities, the odds of collision are 1 in 100million which is great for most purposes.
  • Considering the limited number of unique objects of a particular type being compared, for most cases a 32bit hash sum suffices.
label: programming, utilities, linux, artifact comparison, SHA256sum vs md5sum, CRC32

Reference
[1] md5sum vs sha256sum - Good discussion, but I do not agree with the hash collision discussion here.
[2] Hash collision probabilities  - Nice algorithm for computing probability of hash collision.

Thursday, February 2, 2023

Comparison between unix sockets and TCP/IP sockets

Netlink sockets are the way entities communicate to each other.
  • Address: Unix domain sockets do not need a IP address + port number, TCP/IP sockets do. 
  • Reach: Unix sockets are local to that machine, while TCP/IP sockets need not be.
  • Speed: Unix sockets are faster since they do not go through the TCP/IP stack which ends up being faster.
  • Types: TCP/IP sockets are of the type streaming, datagram, or Raw. There are no further types of Unix sockets.
  • Application: Unix sockets are used for inter process communication on the same system. They behave like system pipes. TCP/IP sockets have a wide range of applications e.g. Telnet.
  • Scope control: Unix domain sockets can be chmod protected while TCP/IP sockets have global scope. [2]
label: TLDR, Sockets, application, comparison, Unix, Networking, pipes, differences

References

Wednesday, February 1, 2023

SWD vs JTAG and the use of semihosting

  • JTAG (Joint test access group interface) [4] and SWD (Serial wire debug) [5] are interfaces used to connect to a remote embedded processor for debugging and tracking execution. 
    • SWD is a 2 wire interface which is ARM specific, while JTAG is used more widely in the industry. 
    • JTAG supports boundary scan [5] a mechanism used to inspect IC pin states and measure voltages.
  • Semihosting [1] is a way by which a target device connected via a JTAG or SWD interface can use a remote hosts (e.g. a laptops) keyboard and console. This is enabled via a C library compiled with the target's code that allows the injection of breakpoints when these inputs or outputs are required and allows communication with the remote host via a debugger interface (JTAG/SWD) [2].
  • Debugging or printing is usually slow with the JTAG interface because the clock speed is slow on those lines [3].
labels: embedded development, semihosting, SWD, JTAG interface, debugging, TLDR, Summary

References
[1] Semihosting - The ARM guide
[2] Semihosting ARM interface

Tuesday, January 31, 2023

How does Linux load rootfs

  • To load rootfs, you need a basic set of tools. How does the kernel bring them in? Initramfs
  • Initramfs is a RAM based FS that brings support for the basic things.  Command line to setup the kernel at start: vmlinuz initrd=initramfs.img root=/dev/sdaX
  • Moving from initramfs to rootfs: Initramfs does a pivot and switch to rootfs. (1) Move initramfs mountpoints to new rootfs mountpoints, (2) This initramfs contains the essential tools required to create and launch the rootfs. Final switch is done by: switch_root /newroot /bin/bash. Finally once the switch_root is done, run the init from the new rootfs.
Labels: switch_root, Linux, Kernel, rootfs, initramfs, build, systems, TLDR, summary

Code Snippet:
# First, find and mount the new filesystem.      mkdir /newroot    mount /dev/whatever /newroot      # Unmount everything else you've attached to rootfs.  (Moving the filesystems    # into newroot is something useful to do with them.)      mount --move /sys /newroot/sys    mount --move /proc /newroot/proc    mount --move /dev /newroot/dev      # Now switch to the new filesystem, and run /sbin/init out of it.  Don't    # forget the "exec" here, because you want the new init program to inherit    # PID 1.      exec switch_root /newroot /sbin/init

Thursday, January 26, 2023

TLDR: WPA3-SAE - How does it work

  • WPA3 - SAE - stands for simultaneous authentication of equals. This is a more secure mechanism than the previous WPA2-PSK [1].
  • This relies on 3 fundamental components:
    • DH - Diffie-hellman key exchange - Helps to generate a common shared key between the two WiFi entities e.g. station and client.
    • ECC (elliptic curve cryptography) - Elliptic-curve cryptography (ECC) is an approach to public-key cryptography based on the algebraic structure of elliptic curves over finite fields. ECC allows smaller keys compared to non-EC cryptography (based on plain Galois fields) to provide equivalent security [2]. ECC is used once a common pairwise key is generated using the DH key exchange.
    • Dragonfly key exchange is a mechanism for key exchange using discrete logarithm cryptography [3]. This is used with the two components above to setup SAE. See the reference for details on how it is setup [3]. Also covered in RFC7664.
labels: WiFi, TLDR, summary article, WPA3, SAE, security, 

Reference: