** Implementation of the sha3(X,SIZE) function. ** ** Return a BLOB which is the SIZE-bit SHA3 hash of X. The default ** size is 256. If X is a BLOB, it is hashed as is. ** For all other non-NULL types of input, X is converted into a UTF-8 string ** and the string is hashed without the trailing 0x00 terminator. The hash ** of a NULL value is NULL. */
| 1892 | ** of a NULL value is NULL. |
| 1893 | */ |
| 1894 | static void sha3Func( |
| 1895 | sqlite3_context *context, |
| 1896 | int argc, |
| 1897 | sqlite3_value **argv |
| 1898 | ){ |
| 1899 | SHA3Context cx; |
| 1900 | int eType = sqlite3_value_type(argv[0]); |
| 1901 | int nByte = sqlite3_value_bytes(argv[0]); |
| 1902 | int iSize; |
| 1903 | if( argc==1 ){ |
| 1904 | iSize = 256; |
| 1905 | }else{ |
| 1906 | iSize = sqlite3_value_int(argv[1]); |
| 1907 | if( iSize!=224 && iSize!=256 && iSize!=384 && iSize!=512 ){ |
| 1908 | sqlite3_result_error(context, "SHA3 size should be one of: 224 256 " |
| 1909 | "384 512", -1); |
| 1910 | return; |
| 1911 | } |
| 1912 | } |
| 1913 | if( eType==SQLITE_NULL ) return; |
| 1914 | SHA3Init(&cx, iSize); |
| 1915 | if( eType==SQLITE_BLOB ){ |
| 1916 | SHA3Update(&cx, sqlite3_value_blob(argv[0]), nByte); |
| 1917 | }else{ |
| 1918 | SHA3Update(&cx, sqlite3_value_text(argv[0]), nByte); |
| 1919 | } |
| 1920 | sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT); |
| 1921 | } |
| 1922 | |
| 1923 | /* Compute a string using sqlite3_vsnprintf() with a maximum length |
| 1924 | ** of 50 bytes and add it to the hash. |
nothing calls this directly
no test coverage detected