Tuesday | 21 MAY 2024
[ previous ]
[ next ]

MD5 in UniVerse

Title:
Date: 2023-05-05

MD5 hashing in UniVerse is quite the leaky abstraction. The functions to do md5 hashing and to then convert that to a base64 encoded string are very plainly C functions that have been wrapped. It would have been nice to have a tighter abstraction but we can wrap around them relatively easily.

The MD5 function is:

        STATUS = DIGEST('MD5',TEXT,1,MD5)

and the BASE64 function is:

        STATUS = ENCODE('BASE64A',1,MD5,1,HASH,1)

This will give us the md5 hash of a text that we can then store and display. I'm pretty sure these are light wrappers around openssl as openssl has these functions.

We can easily write a wrapper that will simply give back a Base64 string when the md5 program is called.


    SUBROUTINE MD5(TEXT,HASH)
*
    HASH = ''
    STATUS = DIGEST('MD5',TEXT,1,MD5)
    STATUS = ENCODE('BASE64A',1,MD5,1,HASH,1)
*
    RETURN
*
    END
*

This is also how we can write a SHA256 and SHA512 function. This is one of those things where having extra functions with set defaults even if they are all basically the same is nice. This way you can reach for a MD5, SHA256 or SHA512 without having to read the manual and figure out something that is probably always going to be the same.

I wrote SHA256 and SHA512 and added them to my library of TCL utilities. This is definitely starting to grow.