Calculating $s$ in ECDSA over $GF(2^m)$
Since you're calculating a scalar multiplication value, and the base point has order $q$, you should calculate $s$ in the field $\mathbb{Z}/q\mathbb{Z}$, not in $GF(2^m)$. In particular, this means that you can't use xor or polynomial division to implement addition and modular reduction, but should use regular addition and division instead.

For example, this should give you the value for $k^{-1}$ as:

$$k^{-1} \equiv 2315871241563531210130617073628712209517930583176 \pmod q$$

which is 1 95A7 4210 396D 0D19 E522 8C83 6815 E728 EFD7 9488 in hexadecimal notation. 

Since $q$ is prime, the order of $\mathbb{Z}/q\mathbb{Z}$ is $q-1$, so you can easily calculate the inverse of $k$, and then calculate $s$. This gives the correct output:

&gt;&gt;&gt; q = int('4000000000000000000020108A2E0CC0D99F8A5EF', 16)
&gt;&gt;&gt; x = int('09A4D6792295A7F730FC3F2B49CBC0F62E862272F', 16)
&gt;&gt;&gt; k = int('23AF4074C90A02B3FE61D286D5C87F425E6BDD81B', 16)
&gt;&gt;&gt; m = int('5795edf0d54db760f156f0eb4a7a0fe38d418e813', 16)
&gt;&gt;&gt; r = int('113A63990598A3828C407C0F4D2438D990DF99A7F', 16)
&gt;&gt;&gt; k_inverse = pow(k, q-2, q)
&gt;&gt;&gt; s = (k_inverse * (m + r * x)) % q
&gt;&gt;&gt; '%X' % s
'1313A2E03F5412DDB296A22E2C455335545672D9F'