-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from norrisjeremy/20210913
More legacy algorithm support and bugfixes
- Loading branch information
Showing
23 changed files
with
939 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,10 @@ public class JSch{ | |
config.put("keypairgen.ecdsa", "com.jcraft.jsch.jce.KeyPairGenECDSA"); | ||
config.put("random", "com.jcraft.jsch.jce.Random"); | ||
|
||
config.put("hmac-ripemd160", "com.jcraft.jsch.bc.HMACRIPEMD160"); | ||
config.put("[email protected]", "com.jcraft.jsch.bc.HMACRIPEMD160OpenSSH"); | ||
config.put("[email protected]", "com.jcraft.jsch.bc.HMACRIPEMD160ETM"); | ||
|
||
config.put("none", "com.jcraft.jsch.CipherNone"); | ||
|
||
config.put("[email protected]", "com.jcraft.jsch.jce.AES128GCM"); | ||
|
@@ -162,6 +166,18 @@ public class JSch{ | |
config.put("aes128-cbc", "com.jcraft.jsch.jce.AES128CBC"); | ||
config.put("aes192-cbc", "com.jcraft.jsch.jce.AES192CBC"); | ||
config.put("aes256-cbc", "com.jcraft.jsch.jce.AES256CBC"); | ||
config.put("[email protected]", "com.jcraft.jsch.jce.AES256CBC"); | ||
|
||
config.put("cast128-cbc", "com.jcraft.jsch.bc.CAST128CBC"); | ||
config.put("cast128-ctr", "com.jcraft.jsch.bc.CAST128CTR"); | ||
config.put("twofish128-cbc", "com.jcraft.jsch.bc.Twofish128CBC"); | ||
config.put("twofish192-cbc", "com.jcraft.jsch.bc.Twofish192CBC"); | ||
config.put("twofish256-cbc", "com.jcraft.jsch.bc.Twofish256CBC"); | ||
config.put("twofish-cbc", "com.jcraft.jsch.bc.Twofish256CBC"); | ||
config.put("twofish128-ctr", "com.jcraft.jsch.bc.Twofish128CTR"); | ||
config.put("twofish192-ctr", "com.jcraft.jsch.bc.Twofish192CTR"); | ||
config.put("twofish256-ctr", "com.jcraft.jsch.bc.Twofish256CTR"); | ||
config.put("[email protected]", "com.jcraft.jsch.bc.SEEDCBC"); | ||
|
||
config.put("aes128-ctr", "com.jcraft.jsch.jce.AES128CTR"); | ||
config.put("aes192-ctr", "com.jcraft.jsch.jce.AES192CTR"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | ||
/* | ||
Copyright (c) 2005-2018 ymnk, JCraft,Inc. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the distribution. | ||
3. The names of the authors may not be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, | ||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.jcraft.jsch.bc; | ||
|
||
import com.jcraft.jsch.Cipher; | ||
import org.bouncycastle.crypto.BufferedBlockCipher; | ||
import org.bouncycastle.crypto.engines.CAST5Engine; | ||
import org.bouncycastle.crypto.modes.CBCBlockCipher; | ||
import org.bouncycastle.crypto.params.*; | ||
|
||
public class CAST128CBC implements Cipher{ | ||
private static final int ivsize=8; | ||
private static final int bsize=16; | ||
private BufferedBlockCipher cipher; | ||
@Override | ||
public int getIVSize(){return ivsize;} | ||
@Override | ||
public int getBlockSize(){return bsize;} | ||
@Override | ||
public int getTagSize(){return 0;} | ||
@Override | ||
public void init(int mode, byte[] key, byte[] iv) throws Exception{ | ||
byte[] tmp; | ||
if(iv.length>ivsize){ | ||
tmp=new byte[ivsize]; | ||
System.arraycopy(iv, 0, tmp, 0, tmp.length); | ||
iv=tmp; | ||
} | ||
if(key.length>bsize){ | ||
tmp=new byte[bsize]; | ||
System.arraycopy(key, 0, tmp, 0, tmp.length); | ||
key=tmp; | ||
} | ||
|
||
try{ | ||
ParametersWithIV keyspec=new ParametersWithIV(new KeyParameter(key, 0, key.length), iv, 0, iv.length); | ||
cipher=new BufferedBlockCipher(new CBCBlockCipher(new CAST5Engine())); | ||
cipher.init(mode==ENCRYPT_MODE, keyspec); | ||
} | ||
catch(Exception e){ | ||
cipher=null; | ||
throw e; | ||
} | ||
} | ||
@Override | ||
public void update(int foo) throws Exception{ | ||
} | ||
@Override | ||
public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ | ||
cipher.processBytes(foo, s1, len, bar, s2); | ||
} | ||
@Override | ||
public void updateAAD(byte[] foo, int s1, int len) throws Exception{ | ||
} | ||
@Override | ||
public void doFinal(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ | ||
} | ||
@Override | ||
public boolean isCBC(){return true; } | ||
@Override | ||
public boolean isAEAD(){return false; } | ||
@Override | ||
public boolean isChaCha20(){return false; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | ||
/* | ||
Copyright (c) 2005-2018 ymnk, JCraft,Inc. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the distribution. | ||
3. The names of the authors may not be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, | ||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.jcraft.jsch.bc; | ||
|
||
import com.jcraft.jsch.Cipher; | ||
import org.bouncycastle.crypto.engines.CAST5Engine; | ||
import org.bouncycastle.crypto.modes.SICBlockCipher; | ||
import org.bouncycastle.crypto.params.*; | ||
|
||
public class CAST128CTR implements Cipher{ | ||
private static final int ivsize=8; | ||
private static final int bsize=16; | ||
private SICBlockCipher cipher; | ||
@Override | ||
public int getIVSize(){return ivsize;} | ||
@Override | ||
public int getBlockSize(){return bsize;} | ||
@Override | ||
public int getTagSize(){return 0;} | ||
@Override | ||
public void init(int mode, byte[] key, byte[] iv) throws Exception{ | ||
byte[] tmp; | ||
if(iv.length>ivsize){ | ||
tmp=new byte[ivsize]; | ||
System.arraycopy(iv, 0, tmp, 0, tmp.length); | ||
iv=tmp; | ||
} | ||
if(key.length>bsize){ | ||
tmp=new byte[bsize]; | ||
System.arraycopy(key, 0, tmp, 0, tmp.length); | ||
key=tmp; | ||
} | ||
|
||
try{ | ||
ParametersWithIV keyspec=new ParametersWithIV(new KeyParameter(key, 0, key.length), iv, 0, iv.length); | ||
cipher=new SICBlockCipher(new CAST5Engine()); | ||
cipher.init(mode==ENCRYPT_MODE, keyspec); | ||
} | ||
catch(Exception e){ | ||
cipher=null; | ||
throw e; | ||
} | ||
} | ||
@Override | ||
public void update(int foo) throws Exception{ | ||
} | ||
@Override | ||
public void update(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ | ||
cipher.processBytes(foo, s1, len, bar, s2); | ||
} | ||
@Override | ||
public void updateAAD(byte[] foo, int s1, int len) throws Exception{ | ||
} | ||
@Override | ||
public void doFinal(byte[] foo, int s1, int len, byte[] bar, int s2) throws Exception{ | ||
} | ||
@Override | ||
public boolean isCBC(){return false; } | ||
@Override | ||
public boolean isAEAD(){return false; } | ||
@Override | ||
public boolean isChaCha20(){return false; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | ||
/* | ||
Copyright (c) 2012-2018 ymnk, JCraft,Inc. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the distribution. | ||
3. The names of the authors may not be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, | ||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.jcraft.jsch.bc; | ||
|
||
import com.jcraft.jsch.MAC; | ||
import org.bouncycastle.crypto.Digest; | ||
import org.bouncycastle.crypto.macs.HMac; | ||
import org.bouncycastle.crypto.params.KeyParameter; | ||
|
||
abstract class HMAC implements MAC { | ||
protected String name; | ||
protected int bsize; | ||
protected Digest digest; | ||
protected boolean etm; | ||
private HMac mac; | ||
|
||
@Override | ||
public int getBlockSize() { | ||
return bsize; | ||
}; | ||
|
||
@Override | ||
public void init(byte[] key) throws Exception { | ||
if(key.length>bsize){ | ||
byte[] tmp = new byte[bsize]; | ||
System.arraycopy(key, 0, tmp, 0, bsize); | ||
key = tmp; | ||
} | ||
KeyParameter skey = new KeyParameter(key, 0, key.length); | ||
mac = new HMac(digest); | ||
mac.init(skey); | ||
} | ||
|
||
private final byte[] tmp = new byte[4]; | ||
@Override | ||
public void update(int i){ | ||
tmp[0] = (byte)(i>>>24); | ||
tmp[1] = (byte)(i>>>16); | ||
tmp[2] = (byte)(i>>>8); | ||
tmp[3] = (byte)i; | ||
update(tmp, 0, 4); | ||
} | ||
|
||
@Override | ||
public void update(byte foo[], int s, int l){ | ||
mac.update(foo, s, l); | ||
} | ||
|
||
@Override | ||
public void doFinal(byte[] buf, int offset){ | ||
mac.doFinal(buf, offset); | ||
} | ||
|
||
@Override | ||
public String getName(){ | ||
return name; | ||
} | ||
|
||
@Override | ||
public boolean isEtM(){ | ||
return etm; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ | ||
/* | ||
Copyright (c) 2002-2018 ymnk, JCraft,Inc. All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the distribution. | ||
3. The names of the authors may not be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, | ||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | ||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.jcraft.jsch.bc; | ||
|
||
import org.bouncycastle.crypto.digests.RIPEMD160Digest; | ||
|
||
public class HMACRIPEMD160 extends HMAC { | ||
public HMACRIPEMD160(){ | ||
name = "hmac-ripemd160"; | ||
bsize = 20; | ||
digest = new RIPEMD160Digest(); | ||
} | ||
} |
Oops, something went wrong.