1*3d322d52SAndroid Build Coastguard Worker# Project Wycheproof 2*3d322d52SAndroid Build Coastguard Workerhttps://github.com/google/wycheproof 3*3d322d52SAndroid Build Coastguard Worker 4*3d322d52SAndroid Build Coastguard Worker*Project Wycheproof is named after 5*3d322d52SAndroid Build Coastguard Worker[Mount Wycheproof](https://en.wikipedia.org/wiki/Mount_Wycheproof), the smallest 6*3d322d52SAndroid Build Coastguard Workermountain in the world. The main motivation for the project is to have a goal 7*3d322d52SAndroid Build Coastguard Workerthat is achievable. The smaller the mountain the more likely it is to be able to 8*3d322d52SAndroid Build Coastguard Workerclimb it.* 9*3d322d52SAndroid Build Coastguard Worker 10*3d322d52SAndroid Build Coastguard Worker[TOC] 11*3d322d52SAndroid Build Coastguard Worker 12*3d322d52SAndroid Build Coastguard Worker## Introduction 13*3d322d52SAndroid Build Coastguard Worker 14*3d322d52SAndroid Build Coastguard WorkerProject Wycheproof tests crypto libraries against known attacks. It is developed 15*3d322d52SAndroid Build Coastguard Workerand maintained by members of Google Security Team, but it is not an official 16*3d322d52SAndroid Build Coastguard WorkerGoogle product. 17*3d322d52SAndroid Build Coastguard Worker 18*3d322d52SAndroid Build Coastguard WorkerAt Google, we rely on many third party cryptographic software libraries. 19*3d322d52SAndroid Build Coastguard WorkerUnfortunately, in cryptography, subtle mistakes can have catastrophic 20*3d322d52SAndroid Build Coastguard Workerconsequences, and we found that libraries fall into such implementation 21*3d322d52SAndroid Build Coastguard Workerpitfalls much too often and for much too long. Good implementation guidelines, 22*3d322d52SAndroid Build Coastguard Workerhowever, are hard to come by: understanding how to implement cryptography 23*3d322d52SAndroid Build Coastguard Workersecurely requires digesting decades' worth of academic literature. We recognize 24*3d322d52SAndroid Build Coastguard Workerthat software engineers fix and prevent bugs with unit testing, and we found 25*3d322d52SAndroid Build Coastguard Workerthat cryptographic loopholes can be resolved by the same means. 26*3d322d52SAndroid Build Coastguard Worker 27*3d322d52SAndroid Build Coastguard WorkerThese observations have prompted us to develop Project Wycheproof, a collection 28*3d322d52SAndroid Build Coastguard Workerof unit tests that detect known weaknesses or check for expected behaviors of 29*3d322d52SAndroid Build Coastguard Workersome cryptographic algorithm. Project Wycheproof provides tests for most 30*3d322d52SAndroid Build Coastguard Workercryptographic algorithms, including RSA, elliptic curve crypto and 31*3d322d52SAndroid Build Coastguard Workerauthenticated encryption. Our cryptographers have systematically surveyed the 32*3d322d52SAndroid Build Coastguard Workerliterature and implemented most known attacks. We have over 80 test cases which 33*3d322d52SAndroid Build Coastguard Workerhave uncovered more than [40 bugs](doc/bugs.md). For 34*3d322d52SAndroid Build Coastguard Workerexample, we found that we could recover the private key of widely-used DSA and 35*3d322d52SAndroid Build Coastguard WorkerECDHC implementations. 36*3d322d52SAndroid Build Coastguard Worker 37*3d322d52SAndroid Build Coastguard WorkerWhile we are committed to develop as many attacks as possible, Project 38*3d322d52SAndroid Build Coastguard WorkerWycheproof is by no means complete. Passing the tests does not imply that the 39*3d322d52SAndroid Build Coastguard Workerlibrary is secure, it just means that it is not vulnerable to the attacks that 40*3d322d52SAndroid Build Coastguard WorkerProject Wycheproof tests for. Cryptographers are also constantly discovering 41*3d322d52SAndroid Build Coastguard Workernew attacks. Nevertheless, with Project Wycheproof developers and users now can 42*3d322d52SAndroid Build Coastguard Workercheck their libraries against a large number of known attacks, without having 43*3d322d52SAndroid Build Coastguard Workerto spend years reading academic papers or become cryptographers themselves. 44*3d322d52SAndroid Build Coastguard Worker 45*3d322d52SAndroid Build Coastguard WorkerFor more information on the goals and strategies of Project Wycheproof, please 46*3d322d52SAndroid Build Coastguard Workercheck out our [doc](doc/). 47*3d322d52SAndroid Build Coastguard Worker 48*3d322d52SAndroid Build Coastguard Worker### Coverage 49*3d322d52SAndroid Build Coastguard Worker 50*3d322d52SAndroid Build Coastguard WorkerProject Wycheproof has tests for the most popular crypto algorithms, including 51*3d322d52SAndroid Build Coastguard Worker 52*3d322d52SAndroid Build Coastguard Worker- AES-EAX 53*3d322d52SAndroid Build Coastguard Worker- AES-GCM 54*3d322d52SAndroid Build Coastguard Worker- [DH](doc/dh.md) 55*3d322d52SAndroid Build Coastguard Worker- DHIES 56*3d322d52SAndroid Build Coastguard Worker- [DSA](doc/dsa.md) 57*3d322d52SAndroid Build Coastguard Worker- [ECDH](doc/ecdh.md) 58*3d322d52SAndroid Build Coastguard Worker- ECDSA 59*3d322d52SAndroid Build Coastguard Worker- ECIES 60*3d322d52SAndroid Build Coastguard Worker- [RSA](doc/rsa.md) 61*3d322d52SAndroid Build Coastguard Worker 62*3d322d52SAndroid Build Coastguard WorkerThe tests detect whether a library is vulnerable to many attacks, including 63*3d322d52SAndroid Build Coastguard Worker 64*3d322d52SAndroid Build Coastguard Worker- Invalid curve attacks 65*3d322d52SAndroid Build Coastguard Worker- Biased nonces in digital signature schemes 66*3d322d52SAndroid Build Coastguard Worker- Of course, all Bleichenbacher’s attacks 67*3d322d52SAndroid Build Coastguard Worker- And many more -- we have over 80 test cases 68*3d322d52SAndroid Build Coastguard Worker 69*3d322d52SAndroid Build Coastguard WorkerOur first set of tests are written in Java, because Java has a common 70*3d322d52SAndroid Build Coastguard Workercryptographic interface. This allowed us to test multiple providers with a 71*3d322d52SAndroid Build Coastguard Workersingle test suite. While this interface is somewhat low level, and should not 72*3d322d52SAndroid Build Coastguard Workerbe used directly, we still apply a "defense in depth" argument and expect that 73*3d322d52SAndroid Build Coastguard Workerthe implementations are as robust as possible. For example, we consider weak 74*3d322d52SAndroid Build Coastguard Workerdefault values to be a significant security flaw. We are converting as many 75*3d322d52SAndroid Build Coastguard Workertests into sets of test vectors to simplify porting the tests to other 76*3d322d52SAndroid Build Coastguard Workerlanguages. We provide ready-to-use test runners for Java Cryptography 77*3d322d52SAndroid Build Coastguard WorkerArchitecture providers such as [Bouncy Castle](http://bouncycastle.org), 78*3d322d52SAndroid Build Coastguard Worker[Spongy Castle](https://rtyley.github.io/spongycastle/), and the default 79*3d322d52SAndroid Build Coastguard Workerproviders in [OpenJDK](http://openjdk.java.net/). 80*3d322d52SAndroid Build Coastguard Worker 81*3d322d52SAndroid Build Coastguard Worker### Usage 82*3d322d52SAndroid Build Coastguard Worker 83*3d322d52SAndroid Build Coastguard Worker- Install [Bazel](https://bazel.build/). 84*3d322d52SAndroid Build Coastguard Worker 85*3d322d52SAndroid Build Coastguard Worker- Install [Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction 86*3d322d52SAndroid Build Coastguard Worker Policy 87*3d322d52SAndroid Build Coastguard Worker Files](http://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters): 88*3d322d52SAndroid Build Coastguard Worker this enables tests with large key sizes. Otherwise you'll see a lot of 89*3d322d52SAndroid Build Coastguard Worker "illegal key size" exceptions. 90*3d322d52SAndroid Build Coastguard Worker 91*3d322d52SAndroid Build Coastguard Worker- Check out the tests 92*3d322d52SAndroid Build Coastguard Worker 93*3d322d52SAndroid Build Coastguard Worker``` 94*3d322d52SAndroid Build Coastguard Workergit clone https://github.com/google/wycheproof.git 95*3d322d52SAndroid Build Coastguard Worker``` 96*3d322d52SAndroid Build Coastguard Worker 97*3d322d52SAndroid Build Coastguard Worker- To test latest stable version of Bouncy Castle: 98*3d322d52SAndroid Build Coastguard Worker 99*3d322d52SAndroid Build Coastguard Worker``` 100*3d322d52SAndroid Build Coastguard Workerbazel test BouncyCastleAllTests 101*3d322d52SAndroid Build Coastguard Worker``` 102*3d322d52SAndroid Build Coastguard Worker 103*3d322d52SAndroid Build Coastguard Worker- To test other versions, e.g., v1.52: 104*3d322d52SAndroid Build Coastguard Worker 105*3d322d52SAndroid Build Coastguard Worker``` 106*3d322d52SAndroid Build Coastguard Workerbazel test BouncyCastleAllTests_1_52 107*3d322d52SAndroid Build Coastguard Worker``` 108*3d322d52SAndroid Build Coastguard Worker 109*3d322d52SAndroid Build Coastguard Worker- To test all known versions (warning, will take a long time): 110*3d322d52SAndroid Build Coastguard Worker 111*3d322d52SAndroid Build Coastguard Worker``` 112*3d322d52SAndroid Build Coastguard Workerbazel test BouncyCastleAllTests_* 113*3d322d52SAndroid Build Coastguard Worker``` 114*3d322d52SAndroid Build Coastguard Worker 115*3d322d52SAndroid Build Coastguard Worker- To test a local jar, set the `WYCHEPROOF_BOUNCYCASTLE_JAR` environment 116*3d322d52SAndroid Build Coastguard Worker variable: 117*3d322d52SAndroid Build Coastguard Worker 118*3d322d52SAndroid Build Coastguard Worker```shell 119*3d322d52SAndroid Build Coastguard Worker$ WYCHEPROOF_BOUNCYCASTLE_JAR=/path/to/bouncycastle 120*3d322d52SAndroid Build Coastguard Worker$ bazel test BouncyCastleTestLocal 121*3d322d52SAndroid Build Coastguard Worker$ bazel test BouncyCastleAllTestsLocal 122*3d322d52SAndroid Build Coastguard Worker``` 123*3d322d52SAndroid Build Coastguard Worker 124*3d322d52SAndroid Build Coastguard WorkerNote: bazel does not currently invalidate the build on environment changes. If 125*3d322d52SAndroid Build Coastguard Workeryou change the `WYCHEPROOF_BOUNCYCASTLE_JAR` environment variable, run `bazel 126*3d322d52SAndroid Build Coastguard Workerclean` to force a rebuild: 127*3d322d52SAndroid Build Coastguard Worker 128*3d322d52SAndroid Build Coastguard Worker```shell 129*3d322d52SAndroid Build Coastguard Worker$ WYCHEPROOF_BOUNCYCASTLE_JAR=/path/to/bouncycastle 130*3d322d52SAndroid Build Coastguard Worker$ bazel test BouncyCastleTestLocal 131*3d322d52SAndroid Build Coastguard Worker$ WYCHEPROOF_BOUNCYCASTLE_JAR=/path/to/other/jar 132*3d322d52SAndroid Build Coastguard Worker$ bazel clean 133*3d322d52SAndroid Build Coastguard Worker$ bazel test BouncyCastleTestLocal 134*3d322d52SAndroid Build Coastguard Worker``` 135*3d322d52SAndroid Build Coastguard Worker 136*3d322d52SAndroid Build Coastguard Worker- To test [Spongy Castle](https://rtyley.github.io/spongycastle/), replace 137*3d322d52SAndroid Build Coastguard WorkerBouncyCastle with SpongyCastle in your commands, for example 138*3d322d52SAndroid Build Coastguard Worker 139*3d322d52SAndroid Build Coastguard Worker``` 140*3d322d52SAndroid Build Coastguard Workerbazel test SpongyCastleAllTests 141*3d322d52SAndroid Build Coastguard Worker``` 142*3d322d52SAndroid Build Coastguard Worker 143*3d322d52SAndroid Build Coastguard Worker- To test your current installation of 144*3d322d52SAndroid Build Coastguard Worker[OpenJDK](http://openjdk.java.net/): 145*3d322d52SAndroid Build Coastguard Worker 146*3d322d52SAndroid Build Coastguard Worker``` 147*3d322d52SAndroid Build Coastguard Workerbazel test OpenJDKAllTests 148*3d322d52SAndroid Build Coastguard Worker``` 149*3d322d52SAndroid Build Coastguard Worker 150*3d322d52SAndroid Build Coastguard WorkerNote that OpenJDKAllTests expects that OpenJDK is your default JDK, so it might 151*3d322d52SAndroid Build Coastguard Workerrefuse to run or its results might be incorrect if you are using some other JDK. 152*3d322d52SAndroid Build Coastguard WorkerIf you downloaded your JDK from Oracle or https://java.com, you're probably 153*3d322d52SAndroid Build Coastguard Workerusing Oracle JDK, which should be compatible with OpenJDK, thus the tests should 154*3d322d52SAndroid Build Coastguard Workerrun correctly. 155*3d322d52SAndroid Build Coastguard Worker 156*3d322d52SAndroid Build Coastguard WorkerSome tests take a very long time to finish. If you want to exclude them, use 157*3d322d52SAndroid Build Coastguard WorkerBouncyCastleTest, SpongyCastleTest or OpenJDKTest -- these targets exclude all 158*3d322d52SAndroid Build Coastguard Workerslow tests (which are annotated with @SlowTest). 159*3d322d52SAndroid Build Coastguard Worker 160*3d322d52SAndroid Build Coastguard WorkerMost test targets are failing, and each failure might be a security issue. To 161*3d322d52SAndroid Build Coastguard Workerlearn more about what a failed test means, you might want to check out [our 162*3d322d52SAndroid Build Coastguard Workerdocumentation](doc/bugs.md) or the comments on top of the corresponding test 163*3d322d52SAndroid Build Coastguard Workerfunction and test class. 164*3d322d52SAndroid Build Coastguard Worker 165*3d322d52SAndroid Build Coastguard Worker### Hall of Bugs 166*3d322d52SAndroid Build Coastguard Worker 167*3d322d52SAndroid Build Coastguard WorkerHere are some of the notable vulnerabilities that are uncovered by 168*3d322d52SAndroid Build Coastguard WorkerProject Wycheproof: 169*3d322d52SAndroid Build Coastguard Worker 170*3d322d52SAndroid Build Coastguard Worker- OpenJDK's SHA1withDSA leaks private keys > 1024 bits 171*3d322d52SAndroid Build Coastguard Worker - Test: testBiasSha1WithDSA in 172*3d322d52SAndroid Build Coastguard Worker[DsaTest](https://github.com/google/wycheproof/blob/master/java/com/google/security/wycheproof/testcases/DsaTest.java). 173*3d322d52SAndroid Build Coastguard Worker - This bug is the same as 174*3d322d52SAndroid Build Coastguard Worker[CVE-2003-0971 - GnuPG generated ElGamal signatures that leaked the private key] 175*3d322d52SAndroid Build Coastguard Worker(https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2003-0971). 176*3d322d52SAndroid Build Coastguard Worker 177*3d322d52SAndroid Build Coastguard Worker- Bouncy Castle's ECDHC leaks private keys 178*3d322d52SAndroid Build Coastguard Worker - Test: testModifiedPublic and testWrongOrderEcdhc in 179*3d322d52SAndroid Build Coastguard Worker[EcdhTest](https://github.com/google/wycheproof/blob/master/java/com/google/security/wycheproof/testcases/EcdhTest.java). 180*3d322d52SAndroid Build Coastguard Worker 181*3d322d52SAndroid Build Coastguard Worker### Maintainers 182*3d322d52SAndroid Build Coastguard Worker 183*3d322d52SAndroid Build Coastguard WorkerProject Wycheproof is maintained by: 184*3d322d52SAndroid Build Coastguard Worker 185*3d322d52SAndroid Build Coastguard Worker- Daniel Bleichenbacher 186*3d322d52SAndroid Build Coastguard Worker- Thai Duong 187*3d322d52SAndroid Build Coastguard Worker- Emilia Kasper 188*3d322d52SAndroid Build Coastguard Worker- Quan Nguyen 189*3d322d52SAndroid Build Coastguard Worker 190*3d322d52SAndroid Build Coastguard Worker### Contact and mailing list 191*3d322d52SAndroid Build Coastguard Worker 192*3d322d52SAndroid Build Coastguard WorkerIf you want to contribute, please read [CONTRIBUTING](CONTRIBUTING.md) and send 193*3d322d52SAndroid Build Coastguard Workerus pull requests. You can also report bugs or request new tests. 194*3d322d52SAndroid Build Coastguard Worker 195*3d322d52SAndroid Build Coastguard WorkerIf you'd like to talk to our developers or get notified about major new 196*3d322d52SAndroid Build Coastguard Workertests, you may want to subscribe to our 197*3d322d52SAndroid Build Coastguard Worker[mailing list](https://groups.google.com/forum/#!forum/wycheproof-users). To 198*3d322d52SAndroid Build Coastguard Workerjoin, simply send an empty mail to [email protected]. 199