yum-slop/TaSTT
Free self-hosted STT for VRChat.
git clone https://git.yummers.dev/yum-slop/TaSTT
ee8213d
v0.21.0
1#!/usr/bin/env python3 2 3# This module is used to implement obfuscation of TaSTT network 4# speech data. At a high level, TaSTT is simply streaming N bits of 5# arbitrary data to a shader via VRChat's parameter sync mechanism. 6# 7# It would be trivial to mine this data for speech information, since 8# we're sending unicode (or ASCII) characters to peers. 9# 10# To raise the cost for the casual data collector, we can obfuscate 11# this data using a one-time pad in cipher-block chaining mode. 12# 13# Making things interesting, encrypted data will arrive at the Unity 14# animator, which processes them in 8 bit chunks. They are written 15# into contiguous blocks of the animator. Thus the shader can decrypt 16# the board by decrypting each block. This is thus stronger than 17# applying a one-time pad to each byte of the plaintext, since the 18# statistical distribution of individual letters is destroyed. 19# Obviously due to the lack of an initialization vector, the 20# distribution of phrases (blocks) is preserved. 21 22import math 23import os 24 25def genKey ( n_bits = 128 ) -> bytearray : 26return os . urandom ( int ( n_bits / 8 )) 27 28def saveKey ( filename : str , key : str ) : 29with open ( filename , "wb" ) as f : 30f . write ( key ) 31 32def loadKey ( filename : str ) -> bytearray : 33with open ( filename , "rb" ) as f : 34return f . read () 35 36# Apply a symmetric cypher to `data` using cypher-block chaining. 37def obfuscate ( data : bytearray , key : bytearray ) -> str : 38n_blocks = int ( math . ceil ( len ( data ) / len ( key ))) 39# This is a misnomer. A true IV would be randomized, but we can't 40# do that since the shader doesn't have access to it. We just use 41# this to implement the "chaining" aspect of CBC. 42iv = bytearray ( b' \x00 ' ) * len ( key ) 43result = bytearray () 44for i in range ( 0 , n_blocks ) : 45block_begin = i * len ( key ) 46block_end = ( i + 1 ) * len ( key ) 47block_plain = data [ block_begin : block_end ] 48block_cypher = block_plain . copy () 49for i in range ( 0 , len ( block_cypher )) : 50block_cypher [ i ] ^= iv [ i ] 51block_cypher [ i ] ^= key [ i ] 52result += block_cypher 53iv = block_cypher 54return result 55 56def deobfuscate ( data : bytearray , key : bytearray ) -> str : 57n_blocks = int ( math . ceil ( len ( data ) / len ( key ))) 58# This is a misnomer. A true IV would be randomized, but we can't 59# do that since the shader doesn't have access to it. We just use 60# this to implement the "chaining" aspect of CBC. 61iv = bytearray ( b' \x00 ' ) * len ( key ) 62result = bytearray () 63for i in range ( 0 , n_blocks ) : 64block_begin = i * len ( key ) 65block_end = ( i + 1 ) * len ( key ) 66block_cypher = data [ block_begin : block_end ] 67block_plain = block_cypher . copy () 68for i in range ( 0 , len ( block_plain )) : 69block_plain [ i ] ^= key [ i ] 70block_plain [ i ] ^= iv [ i ] 71result += block_plain 72iv = block_cypher 73return result 74 75def test () : 76key = genKey () 77saveKey ( "test.key" , key ) 78new_key = loadKey ( "test.key" ) 79os . remove ( "test.key" ) 80assert ( key == new_key ) 81 82plaintext_original = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." 83plaintext_bytes = bytearray ( plaintext_original , "utf-8" ) 84cyphertext = obfuscate ( plaintext_bytes , key ) 85assert ( len ( plaintext_bytes ) == len ( cyphertext )) 86plaintext_recovered = deobfuscate ( cyphertext , key ) . decode ( "utf-8" ) 87assert ( plaintext_original == plaintext_recovered ) 88assert ( plaintext_bytes != cyphertext ) 89 90if __name__ == "__main__" : 91test () 92