diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index 955eb48220..569814c3fc 100644 --- a/src/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/src/regress/lib/libcrypto/wycheproof/wycheproof.go | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: wycheproof.go,v 1.105 2019/11/28 21:42:42 tb Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.106 2019/11/28 21:52:55 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018, 2019 Theo Buehler <tb@openbsd.org> |
@@ -1787,73 +1787,6 @@ func runECDSAWebCryptoTestGroup(algorithm string, wtg *wycheproofTestGroupECDSAW | |||
1787 | return success | 1787 | return success |
1788 | } | 1788 | } |
1789 | 1789 | ||
1790 | func runKWTestWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { | ||
1791 | var aesKey C.AES_KEY | ||
1792 | |||
1793 | ret := C.AES_set_encrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) | ||
1794 | if ret != 0 { | ||
1795 | fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", | ||
1796 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
1797 | return false | ||
1798 | } | ||
1799 | |||
1800 | outLen := msgLen | ||
1801 | out := make([]byte, outLen) | ||
1802 | copy(out, msg) | ||
1803 | out = append(out, make([]byte, 8)...) | ||
1804 | ret = C.AES_wrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(msgLen)) | ||
1805 | success := false | ||
1806 | if ret == C.int(len(out)) && bytes.Equal(out, ct) { | ||
1807 | if acceptableAudit && wt.Result == "acceptable" { | ||
1808 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
1809 | } | ||
1810 | if wt.Result != "invalid" { | ||
1811 | success = true | ||
1812 | } | ||
1813 | } else if wt.Result != "valid" { | ||
1814 | success = true | ||
1815 | } | ||
1816 | if !success { | ||
1817 | fmt.Printf("FAIL: Test case %d (%q) %v - msgLen = %d, AES_wrap_key() = %d, want %v\n", | ||
1818 | wt.TCID, wt.Comment, wt.Flags, msgLen, int(ret), wt.Result) | ||
1819 | } | ||
1820 | return success | ||
1821 | } | ||
1822 | |||
1823 | func runKWTestUnWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { | ||
1824 | var aesKey C.AES_KEY | ||
1825 | |||
1826 | ret := C.AES_set_decrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) | ||
1827 | if ret != 0 { | ||
1828 | fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", | ||
1829 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
1830 | return false | ||
1831 | } | ||
1832 | |||
1833 | out := make([]byte, ctLen) | ||
1834 | copy(out, ct) | ||
1835 | if ctLen == 0 { | ||
1836 | out = append(out, 0) | ||
1837 | } | ||
1838 | ret = C.AES_unwrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(ctLen)) | ||
1839 | success := false | ||
1840 | if ret == C.int(ctLen-8) && bytes.Equal(out[0:ret], msg[0:ret]) { | ||
1841 | if acceptableAudit && wt.Result == "acceptable" { | ||
1842 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
1843 | } | ||
1844 | if wt.Result != "invalid" { | ||
1845 | success = true | ||
1846 | } | ||
1847 | } else if wt.Result != "valid" { | ||
1848 | success = true | ||
1849 | } | ||
1850 | if !success { | ||
1851 | fmt.Printf("FAIL: Test case %d (%q) %v - keyLen = %d, AES_unwrap_key() = %d, want %v\n", | ||
1852 | wt.TCID, wt.Comment, wt.Flags, keyLen, int(ret), wt.Result) | ||
1853 | } | ||
1854 | return success | ||
1855 | } | ||
1856 | |||
1857 | func runHkdfTest(md *C.EVP_MD, wt *wycheproofTestHkdf) bool { | 1790 | func runHkdfTest(md *C.EVP_MD, wt *wycheproofTestHkdf) bool { |
1858 | ikm, err := hex.DecodeString(wt.Ikm) | 1791 | ikm, err := hex.DecodeString(wt.Ikm) |
1859 | if err != nil { | 1792 | if err != nil { |
@@ -1922,6 +1855,73 @@ func runHkdfTestGroup(algorithm string, wtg *wycheproofTestGroupHkdf) bool { | |||
1922 | return success | 1855 | return success |
1923 | } | 1856 | } |
1924 | 1857 | ||
1858 | func runKWTestWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { | ||
1859 | var aesKey C.AES_KEY | ||
1860 | |||
1861 | ret := C.AES_set_encrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) | ||
1862 | if ret != 0 { | ||
1863 | fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", | ||
1864 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
1865 | return false | ||
1866 | } | ||
1867 | |||
1868 | outLen := msgLen | ||
1869 | out := make([]byte, outLen) | ||
1870 | copy(out, msg) | ||
1871 | out = append(out, make([]byte, 8)...) | ||
1872 | ret = C.AES_wrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(msgLen)) | ||
1873 | success := false | ||
1874 | if ret == C.int(len(out)) && bytes.Equal(out, ct) { | ||
1875 | if acceptableAudit && wt.Result == "acceptable" { | ||
1876 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
1877 | } | ||
1878 | if wt.Result != "invalid" { | ||
1879 | success = true | ||
1880 | } | ||
1881 | } else if wt.Result != "valid" { | ||
1882 | success = true | ||
1883 | } | ||
1884 | if !success { | ||
1885 | fmt.Printf("FAIL: Test case %d (%q) %v - msgLen = %d, AES_wrap_key() = %d, want %v\n", | ||
1886 | wt.TCID, wt.Comment, wt.Flags, msgLen, int(ret), wt.Result) | ||
1887 | } | ||
1888 | return success | ||
1889 | } | ||
1890 | |||
1891 | func runKWTestUnWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { | ||
1892 | var aesKey C.AES_KEY | ||
1893 | |||
1894 | ret := C.AES_set_decrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) | ||
1895 | if ret != 0 { | ||
1896 | fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", | ||
1897 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
1898 | return false | ||
1899 | } | ||
1900 | |||
1901 | out := make([]byte, ctLen) | ||
1902 | copy(out, ct) | ||
1903 | if ctLen == 0 { | ||
1904 | out = append(out, 0) | ||
1905 | } | ||
1906 | ret = C.AES_unwrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(ctLen)) | ||
1907 | success := false | ||
1908 | if ret == C.int(ctLen-8) && bytes.Equal(out[0:ret], msg[0:ret]) { | ||
1909 | if acceptableAudit && wt.Result == "acceptable" { | ||
1910 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
1911 | } | ||
1912 | if wt.Result != "invalid" { | ||
1913 | success = true | ||
1914 | } | ||
1915 | } else if wt.Result != "valid" { | ||
1916 | success = true | ||
1917 | } | ||
1918 | if !success { | ||
1919 | fmt.Printf("FAIL: Test case %d (%q) %v - keyLen = %d, AES_unwrap_key() = %d, want %v\n", | ||
1920 | wt.TCID, wt.Comment, wt.Flags, keyLen, int(ret), wt.Result) | ||
1921 | } | ||
1922 | return success | ||
1923 | } | ||
1924 | |||
1925 | func runKWTest(keySize int, wt *wycheproofTestKW) bool { | 1925 | func runKWTest(keySize int, wt *wycheproofTestKW) bool { |
1926 | key, err := hex.DecodeString(wt.Key) | 1926 | key, err := hex.DecodeString(wt.Key) |
1927 | if err != nil { | 1927 | if err != nil { |