[HN Gopher] Show HN: MemSafeCrypto, Java cryptography primitives...
       ___________________________________________________________________
        
       Show HN: MemSafeCrypto, Java cryptography primitives using
       DirectByteBuffer
        
       Author : java-man
       Score  : 25 points
       Date   : 2022-02-11 18:43 UTC (4 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | java-man wrote:
       | A subset of Bouncycastle primitives (Argon2, Blake2b,
       | DigestRandomGenerator, HKDFBytesGenerator, Poly1305,
       | Salsa20Engine, Scrypt, SHA256Digest, XSalsa20Engine) refactored
       | to use DirectByteBuffer instead of primitive arrays, for the
       | purpose of minimizing leaking information through garbage
       | collector.
        
         | The_rationalist wrote:
         | I wonder if region pinning is relevant here https://openjdk.jav
         | a.net/jeps/423#:~:text=G1%20permanently%2.... Looks like a
         | great project Javaman :)
        
           | java-man wrote:
           | Thank you.
           | 
           | I would rather see maybe an annotation instructing the
           | compiler and the runtime not to move allocated objects:
           | @UnmovableMemory       byte[] bytes = new byte[...];
        
             | The_rationalist wrote:
             | Yeah like https://doc.rust-lang.org/std/pin/ Maybe you
             | could propose the idea to the jdk tracker or mailing
             | lists?https://mail.openjdk.java.net/pipermail/jdk-
             | dev/2022-Februar...
        
               | java-man wrote:
               | All my life, large corporations did nothing but ignore
               | me. I basically gave up at this point.
               | 
               | You are right - something like Pin in rust. It will be a
               | new language feature, there are backward compatibility
               | aspects, and the fact that it will need to be _correctly_
               | done by all implementations (or it would fail its stated
               | purpose). DirectByteBuffer provides a certain guarantee
               | as it is.
               | 
               | On the other hand, the secrets might still be leaked via
               | paging, so even this solution is a partial one.
        
         | skanga wrote:
         | Are there any docs besides the unit tests?
        
           | java-man wrote:
           | It's a replacement for Bouncycastle classes, using
           | DirectByteBuffer wrappers to replace primitive arrays.
           | 
           | One difference is explicit zero() method via ICryptoZeroable
           | interface which clears the buffers.
        
       ___________________________________________________________________
       (page generated 2022-02-11 23:01 UTC)