Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto_secretstream_xchacha20poly1305_push #140

Open
pharrowandroid opened this issue Aug 3, 2020 · 0 comments
Open

crypto_secretstream_xchacha20poly1305_push #140

pharrowandroid opened this issue Aug 3, 2020 · 0 comments

Comments

@pharrowandroid
Copy link

pharrowandroid commented Aug 3, 2020

Trying to do the file encryption not the stream.

JNI DETECTED ERROR IN APPLICATION: jarray was NULL
java_vm_ext.cc:570] in call to GetByteArrayElements
java_vm_ext.cc:570] from int org.libsodium.jni.SodiumJNI.crypto_secretstream_xchacha20poly1305_push(byte[], byte[], int[], byte[], int, byte[], int, short)

I have noticed a few things I don't know if it's me or the library.
1st the Tag is listed as a short but it is a int. I have tried casting it.

The second is the clen_p is an int[]. So I'm not sure what to do with that? how does one get that?
I think it should be null? When run as null there is no error, but nothing is produced. It just hangs. When not null it's given an error. When not null it looks like it defaults to 80?

Here is what I have done. Because I have this working with data, and the xchacha20poly1305 with PHP. But for some reason android is a mess. I'm crashing on the 1st crypto_secretstream_xchacha20poly1305_push with not null and null produces nothing.
an example would have been helpful.

int chunk = 4096;
    int buf_out = chunk + crypto_secretstream_xchacha20poly1305_abytes();
    Ekey = new byte[crypto_secretstream_xchacha20poly1305_keybytes()];
    crypto_secretstream_xchacha20poly1305_keygen(Ekey);
    state = new byte[crypto_secretstream_xchacha20poly1305_statebytes()]; 
    header = new byte[crypto_secretstream_xchacha20poly1305_headerbytes()];
   crypto_secretstream_xchacha20poly1305_init_push(state, header, Ekey);
 
    byte[] bytes = new byte[chunk];
    byte[] outbyte = new byte[chunk + crypto_secretstream_xchacha20poly1305_abytes()];

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {
        fOut = new FileOutputStream(file);
         is = new FileInputStream(fileAP);
         bufin = new BufferedInputStream(is);
         bufout = new BufferedOutputStream(fOut);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    int tag = crypto_secretstream_xchacha20poly1305_tag_message();
    try {

        Completable.fromAction(() -> {

            int readNum = bufin.read(bytes);

            while (readNum != -1) {
                int[] outbytelength = new int[1];
                crypto_secretstream_xchacha20poly1305_push(state, outbyte, null, ,bytes, bytes.length ,null, 0 , (short)tag);
                bufout.write(outbyte);
                readNum = bufin.read(bytes);
            }if(readNum == -1){
                int[] outbytelength = new int[outbyte.length];
                int tagf = crypto_secretstream_xchacha20poly1305_tag_final();
                Sodium.crypto_secretstream_xchacha20poly1305_push(state, outbyte, null ,bytes, bytes.length ,null, 0 , (short) tagf);
                bufout.write(outbyte);
            }
        })
                .subscribeOn(Schedulers.io())
                .onErrorComplete()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe();
    } catch (Exception ea) {
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant