5 Replies Latest reply on Nov 2, 2012 3:35 PM by danospv

    Executing a hashing algorithm

    danospv

      Hey all,

       

      I'm writing a Lightroom plugin that needs to execute a SHA-256 hash algorithm on the photos prior to performing other actions on them.

       

      Lightroom namespace provides LrMD5, but doesn't provide SHA256. I found the following implementation of the algorithm in Lua, but if I try to require the script, I get a "Could no load toolkit script" error.

       

      Any suggestions?

        • 1. Re: Executing a hashing algorithm
          areohbee Level 5

          It seems Lr is not supporting bit32, which is native in Lua 5.2 (but not 5.1).

           

          Gonna be hard to port this code, since most implementations you're likely to find will depend on 'C' code which Lr does not support.

           

          You may have to write your own emulation of bit32 to get this code working (or use Jeffrey's).

           

          Note: I played with it enough to know these routines need the capability to work with 64-bit temporary results, despite the 32 in the name. Beware: LrMath's equivalent functions are undefined with inputs greater than 2**32-1, so you'd have to write your own functions to replace them too.

           

          Cheers,

          Rob

          • 2. Re: Executing a hashing algorithm
            DawMatt Level 3

            Hi,

             

            There is a ready made Lightroom compatible implementation of SHA-1 here. Not 100% sure if it will do exactly what you want, but it shows how to work around the Lightroom SDK limitations when working with algorithms like this.

             

            Also be aware that Jeffrey had to jump through all sorts of hoops here because this code was written before LrMath existed. LrMath implemented binary operations that should make this easier. So it might be possible to simplify (and speed optimise) some of his code if you have to apply the ideas rather than reuse the code directly.

             

            Matt

            • 3. Re: Executing a hashing algorithm
              wepurol

              Hi

               

               

              You could try to use an export filter and calculate the hash in an external tool?

               

              Daniel

              • 4. Re: Executing a hashing algorithm
                areohbee Level 5

                wepurol wrote:

                 

                You could try to use an export filter and calculate the hash in an external tool?

                 

                Great idea to use external tool for the computation - not sure if it would be faster or slower than a lua implementation would be - external tool would execute faster, but it would have to be reloaded from disk every time. If the hash is to be computed on the source files, it can be done in export service, otherwise I agree: this would be a good case for an export filter.

                • 5. Re: Executing a hashing algorithm
                  danospv Level 1

                  Thanks for the suggestion! Yes, it looks like a good way to proceed. What's the recommendation for getting the results back - write to a temporary file, or return as a metadata element?