Skip to content

How does paddedBuffLen in Sodium.sodium_pad() work? #65

@erikvanzijst

Description

@erikvanzijst

The Sodium.sodium_pad native method declares the paddedBuffLen argument as a pass-by-value int.

    public native int sodium_pad(int paddedBuffLen, char[] buf, int unpaddedBufLen, int blockSize, int maxBufLen);

The documentation in Padding.Native states that paddedBuffLen is the new length of the buffer:

        /**
         * Adds extra padding to a buffer {@code buf} whose
         * original size is {@code unpaddedBufLen} in order
         * to extend its total length to a multiple of {@code blocksize}.
         * @param paddedBuffLen New length of buffer.
         * @param buf The buffer byte array.
         * @param unpaddedBufLen The length of {@code buf} with no padding.
         * @param blockSize Block size.
         * @param maxBufLen The absolute maximum you want this buffer length
         *                  to be.
         * @return False if the padded buffer length would exceed {@code maxBufLen}.
         */
        boolean sodiumPad(int paddedBuffLen, char[] buf, int unpaddedBufLen, int blockSize, int maxBufLen);

However, it seems that the C function takes a size_t pointer which it only writes a new value to.

int
sodium_pad(size_t *padded_buflen_p, unsigned char *buf,
           size_t unpadded_buflen, size_t blocksize, size_t max_buflen)

I might be overlooking something, but isn't the pointer used to communicate the padded length back to the caller? Something that doesn't work with Java's call-by-value primitives?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestquestionIf you simply want to ask a question, then use this

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions